How to differentiate parent and child tag while dom parsing?

淺唱寂寞╮ 提交于 2019-12-13 01:09:24

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!