我正试图预测一个XPathNodeIterator对象
XPathNodeIterator xpCategories = GetCategories();现在,xpCategories持有这样一个xml
<root>
<category numberofproducts="0">
<id>format</id>
<name>Kopi/Print</name>
</category>
<category numberofproducts="1">
<id>frankering</id>
<name>Kopi/Print</name>
</category>
<category numberofproducts="0">
<id>gardbøjler</id>
<name>Møbler</name>
</category>
<category numberofproducts="0">
<id>gardknager</id>
<name>Møbler</name>
</category>
<category numberofproducts="0">
<id>gardspejle</id>
<name>Møbler</name>
</category>
</root>我需要在loop.tried中获取每个类别节点"id“,如下所示
foreach (char str in xpCategories.Current.Value)
{
xpCategories.MoveNext();
}但是没有一个use..Can能指引我走正确的道路吗?
发布于 2013-08-02 08:12:33
试试这个:
//Replace with your method to return the XML
XPathDocument document = new XPathDocument("DemoXML.xml");
//*****
XPathNavigator navigator = document.CreateNavigator();
XPathNodeIterator nodes = navigator.Select("/root/category/id");
while (nodes.MoveNext())
Console.WriteLine(nodes.Current.Value);编辑:
XPathNodeIterator xpCategories = GetCategories();
XPathNodeIterator xpCategoriesID = xpCategories.Current.Select("root/category/id");
while (xpCategoriesID.MoveNext())
Console.WriteLine(xpCategoriesID.Current.Value);发布于 2013-08-02 08:54:22
XPathNodeIterator xpCategories = GetCategories().Current.Select("/root/category/id");
while (xpCategories.MoveNext())
Console.WriteLine(xpCategories.Current.Value);https://stackoverflow.com/questions/18010984
复制相似问题