我按照此处显示的代码: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)的标题?
提前谢谢!
答案 0 :(得分:1)
你可以像Attributes
那样得到它:
foreach(System.Xml.XmlNode listItem in nodeListItems){
Console.WriteLine(listItem.Attributes["ows_Title"].Value);
}
答案 1 :(得分:0)
你应该试试这个:
listItem.Attributes["ows_Title"].Value;
确保存在ows_Title属性!
答案 2 :(得分:0)
尝试以下代码获取特定属性
foreach(System.Xml.XmlNode listItem in nodeListItems){
Console.WriteLine(listItem.Attributes["ows_Title"].Value);
}
答案 3 :(得分:0)
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
答案 4 :(得分:0)
我能够使用以下代码(来自: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;
}
}
}
}