首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > XML SOAP >

dom4j透过ElementIterator对xml节点进行遍历

2013-11-15 
dom4j通过ElementIterator对xml节点进行遍历xml文件:studentsstudentnamea/nameage19/agecou

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


热点排行