<?xml version="1.0" encoding="utf-8"?>
<parent>
<child ID="1" Name="CHILD" Order="1">
<child ID="1" Name="SUB_CHILD" Order="1">
<child ID="1" Name="SUB_CHILD_1" Order="01"/>
<child ID="2" Name="SUB_CHILD_2" Order="02"/>
</child >
</child>
<child ID="2" Name="CHILD_2" Order="1">
<child ID="1" Name="SUB_CHILD" Order="1">
<child ID="1" Name="SUB_CHILD_1" Order="01"/>
<child ID="2" Name="SUB_CHILD_2" Order="02"/>
</child >
</child>
</parent>
这是我获取<child ID="1" Name="CHILD" Order="1">
名称的代码:
NodeList nodeList = doc.getElementsByTagName("child");
Element element = (Element) nodeList.item(0);
name = element.getAttribute("Name");
Toast.makeText(this, ""+ name, Toast.LENGTH_SHORT).show();
我如何获得名称:
<child ID="1" Name="SUB_CHILD" Order="1">
<child ID="1" Name="SUB_CHILD_1" Order="01"/>
我已经尝试过getChildNode,但它只返回任何内容。