System.out.println(getLevel(level)+"节点名字"+node2.getNodeName());
}
level++;
//获取子节点集合
NodeList list = node2.getChildNodes();
System.out.println(list.getLength());
//遍历集合
for (int i = 0; i < list.getLength(); i++) {
Node node = list.item(i);
//递归
getNode(node,level);
}
}
//定义层次显示方法
public static String getLevel(int level){
StringBuffer sBuffer = new StringBuffer();
for (int i = 1; i <= level; i++) {
sBuffer.append("---");
}
return sBuffer.toString();
}
}