xml结点的遍历

前端之家收集整理的这篇文章主要介绍了xml结点的遍历前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
dom4j通过ElementIterator对xml节点进行遍历
xml文件
<students>
<student>

<name>a</name>
<age>19</age>
<course>math</cource>
<course>english</cource>

</student>
</students>

这里先获取student节点。

Element stu;

然后获取这个节点的子节点course的iterator对象
Iterator it=stu.elementIterator("course");
while(itr.hasNext()){
			Element node=(Element) itr.next();
                        System.out.println(node.getName());
			System.out.println(node.getText());
			
		}
 

这里便会输出:
course
math
course
english 原文链接:https://www.f2er.com/xml/298469.html

猜你在找的XML相关文章