Java XML Document from File loadXml(String fn)

Here you can find the source of loadXml(String fn)

Description

load Xml

License

Creative Commons License

Declaration

private static Document loadXml(String fn) throws Exception 

Method Source Code


//package com.java2s;
//License from project: Creative Commons License 

import java.io.FileInputStream;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;

public class Main {
    private static Document loadXml(String fn) throws Exception {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
        factory.setFeature("http://xml.org/sax/features/external-general-entities", false);
        factory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
        factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
        factory.setXIncludeAware(false);
        factory.setExpandEntityReferences(false);

        factory.setNamespaceAware(true);
        DocumentBuilder builder = factory.newDocumentBuilder();
        return builder.parse(new FileInputStream(fn));
    }/*from   w  w w  .j a  va  2s. com*/
}

Related

  1. loadDocument(String filePath)
  2. loadRootElement(DocumentBuilder documentBuilder, File file)
  3. loadXML(String filename)
  4. loadXml(String fileName)
  5. loadXml(String filePath)
  6. loadXMLDocument(String path)
  7. loadXmlDocumentFromFile(@Nonnull File file)
  8. loadXmlFromFile(String xmlFileName)
  9. read(InputStream input)