I am working on a project in which I have to operate XML files using java.
Earlier I was getting nodes by using node name, ie. getElementsByTagName(). Now a problem arises when I have an xml file with parent node and child node with same name.
How can I distinguish between them.
This a short sample of my xml file.
<deviceparameters>
<parameter> // parent
<name>ABC</name>
<parameter>Yes</parameter> // child with same name
<value>20</value>
</parameter>
</deviceparameters>
Thanks in advance.
Start with finding deviceparameters by name, and then find a named child parameter which is your first one, then then parameter child of that. The Javadoc will tell you the methods to use to find a named child (you may have to loop through the child elements).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With