Use of count in Xpath expressions

后端 未结 2 942
一生所求
一生所求 2020-12-20 03:58

if I have an XML like this: (just to do an example)


    
            
相关标签:
2条回答
  • 2020-12-20 04:27
    restaurant/tables/count(table)
    

    This expression is only legal in XPath 2.0. It produces a sequence of numbers and this sequence may have length greater than one if the XML document has more than one restorant or restorant/tables elements.

    count(restaurant/tables/table)
    

    This expression is valid both in XPath 1.0 and XPath 2.0. It produces a single number.

    So, in general, the two expressions are different, only the second is legal in XPath 1.0 and in XPath 2.0 these expressions may produce different results, depending on the XML document against which they are evaluated.

    However on the specified XML document, these two expressions (when evaluated in XPath 2.0) produce the same result:

    3
    
    0 讨论(0)
  • 2020-12-20 04:32

    Check out this Microsoft XPath count() tutorial.

    count(/restaurant/tables/table)
    

    will count the table elements in the above path.

    0 讨论(0)
提交回复
热议问题