count of element in XPath

前端 未结 3 1782
一整个雨季
一整个雨季 2021-02-02 07:52
...

     ... 
     ... 
    

        
3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-02 08:45

    If you are using XPath from an environment such as Java or C#, you should first bind a prefix to the namespace, which depends on the API you are using, but will be something like

    xpath.declareNamespace("f", "mynamespace")
    

    and then evaluate the XPath expression

    count(element/f:Element1)
    

    I deliberately chose a different prefix from the one in your source document just to show that you can use any prefix you like, but of course your code is more readable if you are consistent in your choice of prefixes.

提交回复
热议问题