<book >
<author>11</author>
<title>aa</title>
</book>
<book>
<author>22</author>
<title>bb</title>
</book>
<book>
<author>33</author>
<title>cc</title>
</book>
如上所示 某一个xml文件中存在如上类似的节点内容,这个节点内容上面有不确定多少个父节点,
SelectNodes("book"); 是无法定位到此节点下的子节点集合的,
有什么方法或者能精确定位到所有book节点内所有子节点内容?
XmlNodeList nodes = parent.SelectNodes("book");
foreach (XmlNode node in nodes)
{
string author = node.SelectSingleNode("auther").InnerText;
string title = node.SelectSingleNode("title").InnerText;
}
追加回复:
string shortname = null;
XmlNodeList nodelist = doc.GetElementsByTagName("SW-BASE-TYPE");
int n = nodelist.Count;//12
XmlNode node11 = null;
XmlNode node22 = null;
for (int i = 0; i < n; i++)
{
node11 = nodelist.Item(i);
shortname = node11["SHORT-NAME"].InnerText;
Console.WriteLine("{0}", shortname);
}
string author;
string title;
foreach (XmlNode node in xmldoc.GetElementsByTagName("book"))
{
author = node.SelectSingleNode("auther").InnerText;
title = node.SelectSingleNode("title").InnerText;
}