Java 怎么获取XML DOM文档生成器(DocumentBuilder)

2019年7月29日19:42:20Java 怎么获取XML DOM文档生成器(DocumentBuilder)已关闭评论 445 961字阅读3分12秒

1.简介

Java 怎么获取XML DOM文档生成器(DocumentBuilder)?——请看下文。

2.示例代码

/**
 * 版权所有 编程十万个怎么办(www.tah1986.com)
 */

 
import java.io.OutputStream;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathFactory;
import org.w3c.dom.Document;
import org.w3c.dom.bootstrap.DOMImplementationRegistry;
import org.w3c.dom.ls.DOMImplementationLS;
import org.w3c.dom.ls.LSOutput;
import org.w3c.dom.ls.LSSerializer;

public class Main{
    public static void main(String[] argv) throws Exception{
        System.out.println(getDocumentBuilder());
    }
    public static DocumentBuilder getDocumentBuilder() {
        DocumentBuilderFactory newInstance = DocumentBuilderFactory
                .newInstance();
        newInstance.setNamespaceAware(true);
        newInstance.setIgnoringElementContentWhitespace(true);
        try {
            return newInstance.newDocumentBuilder();
        } catch (ParserConfigurationException e) {
            throw new XmlException("document builder was not created", e);
        }
    }
}

 
继续阅读
编程十万个怎么办