Count Total Number of XmlNodes in C#

前端 未结 6 979
走了就别回头了
走了就别回头了 2021-01-13 04:59

I\'m trying to find a way to get the total number of child nodes from an XmlNode recursively.

That it is to say I want to count all the children, grand children etc.

6条回答
  •  春和景丽
    2021-01-13 05:28

    The XPath you are after is:

    descendant::node() (1)

    or

    descendant::* (2)

    The first XPath expresion (1) above selects any node (text-node, processing-instruction, comment, element) in the subtree rooted by the current node.

    (2) selects any element node in the subtree rooted by the current node.

提交回复
热议问题