I want to add an XPath attribute to all <definition> tags in my XML document. The XPath’s value will come from a nested tag <term>Test123</term> inside each <definition> tag. I’m using the import org.w3c.dom.Document; object. When I run this line with my really long XML file then it tells me that there are 539 instances of the <definition> tag:
System.out.println(inputDOM.getDocumentElement().getElementsByTagName("definition"));
So the end result is that there must be a Document object that has set all the definition tags from the term tags, for example
<definition XPath="Test123"> <term>Test123</term> </definition>
Try something like this
First we get all
<definition>tags. After that we iterate each<definition>tag and set a new attributs “XPath” whose value is the text content of the<term>child tag