Get the non-empty element using XPATH

后端 未结 4 2007
情歌与酒
情歌与酒 2020-12-31 00:34

I have the following XML



  
    
  
  

        
相关标签:
4条回答
  • 2020-12-31 01:02

    It actually can be simplified as below:

    //group/p1[string-length() > 0]    => element text is non-empty
    //group/p1[string-length() = 6]    => element text has length 6
    
    0 讨论(0)
  • 2020-12-31 01:11

    This xpath should work as well:

    //group/p1[string-length(text()) > 0] 
    
    0 讨论(0)
  • 2020-12-31 01:14

    You may also use [not(node())] Selector. Example: //group/p1[not(node())]

    0 讨论(0)
  • 2020-12-31 01:17

    How about something like /root/group/p1[text() and not(../following-sibling::group/p1/text())]

    In other words: get the p1 elements that have text and whose group parents are not followed by group nodes that have non-empty p1 elements.

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