muc
作者muc·2010-09-27 16:32
其它·北京华为朗新科技有限公司

java中dom4j解析xml文件怎么获取节点属性

字数 553阅读 1098评论 0赞 0
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);
    //对子节点进行其它操作...
}

如果觉得我的文章对您有用,请点赞。您的支持将鼓励我继续创作!

0

添加新评论0 条评论

Ctrl+Enter 发表

作者其他文章

相关文章

相关问题

相关资料

X社区推广