java--xml解析

来源:互联网 发布:mac双系统开机默认 编辑:程序博客网 时间:2024/04/30 11:04
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);}}

原创粉丝点击