I would like to understand how to create or modify a node in a simple XML file.
the following is the XML file:
<?xml version = "1.0"?>
<myRootNode>
<myNode a="P" b="Q" c="R">
<subNode id= "1">
<x>more text</x>
<y>some more</y>
</subNode>
<subNode id="2">
<x>blah</x>
<y><blah blah</y>
</subNode>
</myNode>
<myNode a="S" b="T" c="U">
<subNode id= "1">
<x>some more text</x>
<y>even more</y>
</subNode>
<subNode id="2">
<x>abcdefg</x>
<y>hijklmno</y>
</subNode>
</myNode>
</myRootNode>
I would like to know how to edit a node's inner text. for eg: Edit the inner text of the node achieved by evaluating the expression:
/myRootNode/myNode[@a='P' and @b='Q' and @c='R']/subNode[@id='1']/x
I would also like to know how can I use pure xPath to insert a node:
<subNode id="3">
<x>pqrst</x>
<y>uvxyz</y>
</subNode>
after the node achieved by evaluating the expression:
/myRootNode/myNode[@a='P' and @b='Q' and @c='R']/subNode[@id="2"]
If possible, please provide Java code. Thank you.