我在android中使用dom xml解析器。在我的源代码中,xml包含父和子的相同名称。
如何在分析xml数据时区分父标记和子标记?
这是我的样本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>
答案 0 :(得分:2)
您可以创建文档文档。
NodeList nodes = doc.getElementsByTagName("parentnode");
Element e = (Element) nodes.item(i);
flag =XMLfunctions.getValue(e,"childnode");