Spring 解析xml代码提取

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)