Example usage for javax.xml.parsers DocumentBuilderFactory newInstance

List of usage examples for javax.xml.parsers DocumentBuilderFactory newInstance

Introduction

In this page you can find the example usage for javax.xml.parsers DocumentBuilderFactory newInstance.

Prototype

public static DocumentBuilderFactory newInstance() 

Source Link

Document

Obtain a new instance of a DocumentBuilderFactory .

Usage

From source file:Main.java

private static DocumentBuilder getDocumentBuilder() throws ParserConfigurationException {
    return DocumentBuilderFactory.newInstance().newDocumentBuilder();
}

From source file:Main.java

public static Object getBean() {
    try {//from  w  w  w. j  ava  2s.  c o  m
        DocumentBuilderFactory dFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = dFactory.newDocumentBuilder();
        Document doc = builder.parse(new File("src/config.xml"));

        NodeList nl = doc.getElementsByTagName("className");
        Node node = nl.item(0).getFirstChild();
        String cName = node.getNodeValue();

        Class clazz = Class.forName(cName);
        Object obj = clazz.newInstance();
        return obj;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

From source file:Main.java

public static org.w3c.dom.Document readXML(String xmlString) throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);//from  ww  w  .j a  v a 2  s . co m
    DocumentBuilder builder = factory.newDocumentBuilder();
    return builder.parse(new ByteArrayInputStream(xmlString.getBytes()));
}

From source file:Main.java

public static Document generateDocument() throws ParserConfigurationException {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);// ww w . j  av  a  2s.  c o  m
    return dbf.newDocumentBuilder().newDocument();
}

From source file:Main.java

public static Document load(File fileName) throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setIgnoringComments(false);/*from w  w  w.  j a  va 2 s.  co  m*/
    factory.setIgnoringElementContentWhitespace(true);
    factory.setValidating(false);
    factory.setCoalescing(false);
    DocumentBuilder builder = factory.newDocumentBuilder();
    return builder.parse(fileName);
}

From source file:Main.java

public static DocumentBuilder getDocumentBuilder() {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);/*from   ww w  .  java  2  s  .  c  o  m*/
    factory.setIgnoringComments(true);
    DocumentBuilder db;
    try {
        db = factory.newDocumentBuilder();
        return db;
    } catch (ParserConfigurationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

public static Node loadURL(java.net.URL url) {
    Document document = null;/* w  w w. ja v  a 2s  .  co m*/
    if (url != null) {
        try {
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            DocumentBuilder builder = factory.newDocumentBuilder();
            document = builder.parse(url.openStream());
        } catch (java.io.IOException ioe) {
            document = null;
            ioe.printStackTrace();
        } catch (ParserConfigurationException pce) {
            document = null;
            pce.printStackTrace();
        } catch (org.xml.sax.SAXException se) {
            document = null;
            se.printStackTrace();
        }

        return document;
    }
    return null;
}

From source file:Main.java

private final static DocumentBuilder createDocumentBuilder() {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = null;
    try {//from ww w .  ja v  a2 s .  c  o  m
        builder = factory.newDocumentBuilder();
    } catch (ParserConfigurationException e) {
        throw new RuntimeException(e);
    }
    return builder;
}

From source file:Main.java

public static Document createNewDocument() throws Exception {
    DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    Document document = builder.newDocument();

    return document;
}

From source file:Main.java

public static synchronized DocumentBuilderFactory getDOMFactory() {
    if (DOM_FACTORY == null) {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setNamespaceAware(true);
        factory.setExpandEntityReferences(false);
        DOM_FACTORY = factory;//from  ww w  .jav a  2s . co  m
    }
    return DOM_FACTORY;
}