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).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.