XmlUtils.java 文件源码

java
阅读 30 收藏 0 点赞 0 评论 0

项目:javaide 作者:
/**
 * Parses the given UTF file as a DOM document, using the JDK parser. The parser does not
 * validate, and is optionally namespace aware.
 *
 * @param file           the UTF encoded file to parse
 * @param namespaceAware whether the parser is namespace aware
 * @return the DOM document
 */
@NonNull
public static Document parseUtfXmlFile(@NonNull File file, boolean namespaceAware)
        throws ParserConfigurationException, IOException, SAXException {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    Reader reader = getUtfReader(file);
    try {
        InputSource is = new InputSource(reader);
        factory.setNamespaceAware(namespaceAware);
        factory.setValidating(false);
        DocumentBuilder builder = factory.newDocumentBuilder();
        return builder.parse(is);
    } finally {
        reader.close();
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号