问题
I am using dom xml parser in android. In my source xml contains same name for parent and child.
How to differentiate parent tag and child tag while parsing xml data?
This is my sample xml.
<alerts>
<alert>
<code>QWEOS</code>
<alert>this is alert1</alert>
<description>this is description</description>
</alert>
<alert>
<code>SDFHP</code>
<alert>this is alert2</alert>
<description>this is description</description>
</alert>
</alerts>
回答1:
You can create an document doc.
NodeList nodes = doc.getElementsByTagName("parentnode");
Element e = (Element) nodes.item(i);
flag =XMLfunctions.getValue(e,"childnode");
来源:https://stackoverflow.com/questions/13245874/how-to-differentiate-parent-and-child-tag-while-dom-parsing