XPath Get first element of subset

后端 未结 2 2081
礼貌的吻别
礼貌的吻别 2020-12-16 11:16

I have XML like this:


    
        
        
    &         


        
相关标签:
2条回答
  • 2020-12-16 11:37

    This one should work for you:

    (//*/CCC)[1]
    
    0 讨论(0)
  • 2020-12-16 11:52

    I want to get first element. But with XPath expression //*/CCC[1] I have got two elements. Each of them is the first elemet in <BBB></BBB> context. How to get first element in subset?

    This is a FAQ:

    The [] operator has a higher precedence (binds stronger) than the // abbreviation.

    Use:

    (//CCC)[1]
    

    This selects the first (in document order) CCC element in the XML document.

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