Я пытаюсь определить количество дочерних элементов, которые есть у узла, но единственное, что я могу получить - есть ли у них дочерние элементы, а не сколько.Например: я использую Xpath в C # (XPathNodeIterator
, XPathDocument
и XPathNavigator
)
РЕДАКТИРОВАТЬ:
iterator.Count
не то, что я хочудостичь, потому что он возвращает количество всех узлов, возвращаемых выражением.Я хотел бы знать, сколько дочерних узлов находится «под» iterator.Current
Это Xml-файл, с которым я работаю (как в примере)
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->
<breakfast_menu>
<food>
<name>Belgian Waffles</name>
<price>$5.95</price>
<description>two of our famous Belgian Waffles with plenty of real maple syrup</description>
<calories>650</calories>
</food>
<food>
<name>Strawberry Belgian Waffles</name>
<price>$7.95</price>
<description>light Belgian waffles covered with strawberries and whipped cream</description>
<calories>900</calories>
</food>
</breakfast_menu>
`
Мой код:
XPathDocument document = new XPathDocument(@"C:\\xmls\\chair1.xml");
XPathNavigator navigator = document.CreateNavigator();
XPathNodeIterator iterator = navigator.Select("//*");
while (iterator.MoveNext())
{
stringList.Add(iterator.Current.Name);
if(iterator.Current.HasChildren) stringList.Add(iterator.Current.Value);
stringList.Add(" ------- ");
}
И что он производит
![enter image description here](https://i.stack.imgur.com/kxRaB.png)