Java怎么解析xml子节点中的属性,如下
<results><statuscode>200</statuscode><contactsversion="2560343512541298689"><buddylis...
<results>
<statuscode>200</statuscode>
<contacts version="2560343512541298689">
<buddylists>
<buddylist id="0" name="11"></buddylist>
</buddylists>
</contacts>
</results>
怎么解析出来id的值 展开
<statuscode>200</statuscode>
<contacts version="2560343512541298689">
<buddylists>
<buddylist id="0" name="11"></buddylist>
</buddylists>
</contacts>
</results>
怎么解析出来id的值 展开
1个回答
展开全部
dom4j中,使用Element.attributes方法可以获取到节点的属性,而使用elements则可以获取相应的子节点
比如:
Element root = doc.getRootElement();
List attrList = root.attributes();
for (int i = 0; i < attrList.size(); i++) {
//属性的取得
Attribute item = (Attribute)attrList.get(i);
System.out.println(item.getName() + "=" + item.getValue());
}
List childList = root.elements();
for (int i = 0; i < childList.size(); i++) {
//子节点的操作
Element it = (Element) childList.get(i);
//对子节点进行其它操作...
}
比如:
Element root = doc.getRootElement();
List attrList = root.attributes();
for (int i = 0; i < attrList.size(); i++) {
//属性的取得
Attribute item = (Attribute)attrList.get(i);
System.out.println(item.getName() + "=" + item.getValue());
}
List childList = root.elements();
for (int i = 0; i < childList.size(); i++) {
//子节点的操作
Element it = (Element) childList.get(i);
//对子节点进行其它操作...
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询