日期:2014-05-20 浏览次数:21262 次
Node root = doc.getFirstChild(); NodeList nodes = root.getChildNodes(); for(int i=0;i<nodes.getLength();i++){ NodeList ns = nodes.item(i).getChildNodes(); for(int j=0;j<ns.getLength();j++){ String s=ns.item(j).getTextContent(); System.out.print(s+" "); } System.out.println(); }
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <students> <student> <name>lisi</name> <id>1001</id> <age>man</age> </student> <student> <name>zhangsan</name> <id>1002</id> <age>man</age> </student> <student> <name>wangwu</name> <id>1003</id> <age>man</age> </student> <student> <student> <name>haha</name> <student> <name>hehe</name> <id>1002</id> <age>woman</age> </student> </student> </student> </students>