Sachin Mhetre
Sachin Mhetre

Reputation: 4543

How to find a node if parent node and child node has same name?

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.

Upvotes: 3

Views: 1757

Answers (1)

Francis Upton IV
Francis Upton IV

Reputation: 19443

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).

Upvotes: 2

Related Questions