XPath (SimpleXML) selection of child based on value of child's sibling

后端 未结 3 1999
旧时难觅i
旧时难觅i 2021-01-22 05:28

I\'m using SimpleXML (Java) and I\'m trying to get a List of objects based on the value of one of the siblings of the list.

So, here\'s my XML:



        
3条回答
  •  灰色年华
    2021-01-22 06:19

    1. Your xml example is not well-formed. The link element doesn't have its closing counterpart. The same applies for the description el. I assume these are just typos.
    2. Here is the working XPath expression:

    /metadata/resources/resource/links/link[parent::links/preceding-sibling::ittype/text()=='Service_Links']

    or much simpler version:

    /metadata/resources/resource[ittype = 'Service_Links']/links/link

提交回复
热议问题