Java How to extract a complete XML block with xpath -


i have xml files this:

<a>   <b>     <c>       <id>0</id>     </c>   </b>   <b>     <c>       <id>1</id>     </c>   </b> </a> 

and b block when c has specific id. example, if want block id=1, want reponse:

      <b>         <c>           <id>1</id>         </c>       </b> 

but not know how can part want. tried:

node result = (node)xpath.evaluate("a/b/c[id = '1']", doc, xpathconstants.node); 

but returns c block, when want b block.

and:

node result = (node)xpath.evaluate("b[a/b/c[id = '1']]", doc, xpathconstants.node); 

returns null.

also have read official documentation did not find anything:

https://msdn.microsoft.com/en-us/library/ms256471(v=vs.110).aspx

https://msdn.microsoft.com/en-us/library/ms256086(v=vs.110).aspx

thanks.

predicates mean "only keep element if respects condition put in predicate"

so simply,

a/b[c/id = 1] 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -