我有一个XPathNodeIterator
名为_xpCategories的数据,其中包含这样的数据
<root>
<category numberofproducts="0">
<id>hoved</id>
<url>/products/hovednavigation</url>
<name>HOVEDNAVIGATION</name>
<category numberofproducts="0">
<id>embalfors</id>
<url>/products/emballage-og-forsendelse</url>
<name>Emballage og forsendelse</name>
<category numberofproducts="0">
<id>gaveindpak</id>
<url>/products/gaveindpakning</url>
<name>Gaveindpakning</name>
<category numberofproducts="3">
<id>cellofan</id>
<url>/products/cellofan</url>
<name>Cellofan</name>
</category>
<category numberofproducts="30">
<id>gavebånd</id>
<url>/products/gavebaand</url>
<name>Gavebånd</name>
</category>
</category>
<category numberofproducts="0">
<id>kuvkonv</id>
<url>/products/kuverter-og-konvolutter</url>
<name>Kuverter og konvolutter</name>
</category>
</category>
</category>
</root>
我想遍历这个xml中的每个类别并打印每个类别的id。我做了一些这样的代码。
while (_xpCategories.MoveNext())
{
Console.WriteLine(_xpCategories.Current.SelectSingleNode("id"));
}
但是这个循环只能工作一个,只有第一个类别 id 得到,然后它存在循环。有人能指出我做错了什么吗?