private static void forEach(String filepath) throws Exception {
//获取解析器工厂
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
//获取解析器
DocumentBuilder builder = factory.newDocumentBuilder();
//解析文档
Document doc = builder.parse(filepath);
//获取根节点
Element root = doc.getDocumentElement();
//遍历节点
forEachDetail(root);
}
private static void forEachDetail(Node node){
NodeList nodeList = node.getChildNodes();
for (int i = 0; i < nodeList.getLength(); i++) {
Node childNode = nodeList.item(i);
System.out.println(childNode.getNodeName());
forEachDetail(childNode);
}
}
java--xml解析
最新推荐文章于 2023-05-07 21:33:52 发布