如何从XmlNode检索数据到List
本文关键字:数据 List 检索 XmlNode | 更新日期: 2023-09-27 18:18:01
我遵循如下代码:http://msdn.microsoft.com/en-us/library/office/ms429658(v=office.14).aspx
控制台显示:
<z:row ows_MetaInfo="5;#" ows_Level="3" ows_Title="TITLEA" ows_ID="5" />
<z:row ows_MetaInfo="6;#" ows_Level="3" ows_Title="TITLEB" ows_ID="6" />
<z:row ows_MetaInfo="7;#" ows_Level="3" ows_Title="TITLEC" ows_ID="7" />
在我的c#代码中,我有:
System.Xml.XmlNode nodeListItems= getItems.GetListItems(listName,viewName,query, viewFields, rowLimit, queryOptions, null);
foreach(System.Xml.XmlNode listItem in nodeListItems){
Console.WriteLine(listItem.InnerXml);
}
问题:我如何能够从每个xmlnode (TitleA, TitleB, TitleC)只检索标题?
提前感谢!
你可以像这样从Attributes
获取:
foreach(System.Xml.XmlNode listItem in nodeListItems){
Console.WriteLine(listItem.Attributes["ows_Title"].Value);
}
你应该试试这个:
listItem.Attributes["ows_Title"].Value;
试试下面的代码获取特定属性
foreach(System.Xml.XmlNode listItem in nodeListItems){
Console.WriteLine(listItem.Attributes["ows_Title"].Value);
}
XmlTextReader reader = new XmlTextReader(saveurl);
List<string> values = new List<string>();
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Text:
values.Add(reader.Value);
break;
} //switch case ends
} // while loop ends
我能够使用以下代码(来自:http://social.msdn.microsoft.com/forums/sharepoint/en-US/2c042b7b-19a5-4062-94b5-8e2ea7e117b4/how-to-get-list-item-using-webservice)来获得我的答案:
foreach (XmlNode node in nodeListItems)
{
if (node.Name == "rs:data")
{
for (int i = 0; i < node.ChildNodes.Count; i++)
{
if (node.ChildNodes[i].Attributes != null)
{
string field = node.ChildNodes[i].Attributes["ows_Title"].InnerText;
}
}
}
}