我对.NET中的XML处理非常陌生。
我正在通过web服务引用使用asp .net站点中sharepoint列表的数据。
下面是我使用数据的代码。
TestSharePointSite.Lists lists = new global::Test.TestSharePointSite.Lists();
lists.Url = "http://intranetsharepoint/global/test/_vti_bin/Lists.asmx";
lists.Credentials = System.Net.CredentialCache.DefaultCredentials;
XmlNode n = lists.GetListItems("TestList", null, null, null, null, null, null);
for (int i = 0; i < n.ChildNodes[1].ChildNodes.Count; i++)
{
if (n.ChildNodes[1].ChildNodes[i].Attributes != null)
{
foreach (XmlAttribute a in n.ChildNodes[1].ChildNodes[i].Attributes)
{
Response.Write("<br> .. " + a.Name + " .. " + a.InnerText);
}
}
}下面是我从上述代码中得到的输出
.. ows_Content_x0020_Description .. string;#Fast Track
.. ows_Dev_x002e__x0020_Location .. 32;#Numatics Actuator Tennessee
.. ows_Strategic_x0020_Bucket0 .. 4;#Minor Revision
--------------------- Other Attributes ----------------
.. ows_Engineer .. 584;#Tilmos, Wayne [INDAUTO/ASCONUM/NOVI]
.. ows__ModerationStatus .. 0 现在我想搜索一个特定的XML元素\XML节点。我想要一个节点,其中的内容描述(这里有名称ows_Content_x0020_Description)包含Fast Track。
我已经完成了以下问题,但无法在代码中实现解决方案。我也尝试过在谷歌上搜索,但做不到。提前结束。
发布于 2013-09-05 15:10:26
XmlDocument dddd = new XmlDocument();
dddd.Load(@"D:\Development\xxxx\xxxxx.xml");
XmlNode xnode = dddd.DocumentElement;
for (int i = 0; i < xnode.ChildNodes.Count; i++)
{
if(xnode.ChildNodes[i].Attributes !=null)
foreach (XmlAttribute a in xnode.ChildNodes[i].Attributes)
{
if (a.Name == "ows_Content_x0020_Description")
{
string nameddd = a.InnerText;
}
}
}发布于 2013-09-05 14:31:52
您应该使用XPath表达式进行测试。我假设变量列表是一个XmlDocument。
XmlNode node =
list.SelectSingleNode("//root/ows_Content_x0020_Description[contains(.,'Fast Track')]");请参阅http://msdn.microsoft.com/en-us/library/system.xml.xmlnode.selectsinglenode.aspx
编辑:使用XPath测试XPathTester表达式
https://stackoverflow.com/questions/18635378
复制相似问题