public class Test { public static void main(String[] args) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder docBuilder = factory.newDocumentBuilder(); InputStream inputSource = new FileInputStream("D:\\spring-beans.xml"); Document document = docBuilder.parse(inputSource); Element root = document.getDocumentElement(); NodeList nl = root.getChildNodes(); for (int i = 0 ;i< nl.getLength();i++) { Node node = nl.item(i); if (node instanceof Element) { Element ele = (Element) node; System.out.println("node NamespaceURI = " + ele.getNamespaceURI()); } } System.out.println(nl.getLength()); } }
Spring 解析xml代码提取
最新推荐文章于 2024-06-28 14:52:57 发布