XPATH problem with dom4j

后端 未结 2 1443
花落未央
花落未央 2021-01-29 12:21

I am using dom4j to overwrite a value in the XML. The XML looks like this:


    
        

        
相关标签:
2条回答
  • 2021-01-29 12:47

    to select the three values, use:

    //name[@time='555555']/element1/value
    

    If that returns null as well, there may be a default namespace involved and that means you need to show your entire XML.

    XPath is flexible, if you want you can express the same like this:

    //value[ancestor::name[1]/@time='555555']
    
    0 讨论(0)
  • 2021-01-29 13:06

    The XPath that you are using is looking for a time attribute equal to 555555 on element1. However, your time attributes are on the name nodes.

    You could go either the way Tomalak suggested, or change it to:

    //element1[../@time='555555']
    

    This is looking for an element1 node with a parent who has a time attribute equal to 555555.

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