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

public static Node stringToNode(final String confXmlString) {
    try {/*from w  ww .ja v a 2s . com*/
        return DocumentBuilderFactory.newInstance().newDocumentBuilder()
                .parse(new ByteArrayInputStream(confXmlString.getBytes())).getFirstChild();
    } catch (final Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:Main.java

public static Document parse(String xml) throws Exception {
    return DocumentBuilderFactory.newInstance().newDocumentBuilder()
            .parse(new InputSource(new StringReader(xml)));
}

From source file:Main.java

/** Create a empty XML docmuent */
public static Document createDocument() throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder = factory.newDocumentBuilder();
    Document doc = docBuilder.newDocument();
    return doc;//from  ww w. j  a  v a2s.c  o m
}

From source file:Main.java

public static Document load(String path) throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setIgnoringComments(false);/*ww w.  j  av  a2s  .co m*/
    factory.setIgnoringElementContentWhitespace(false);
    factory.setValidating(false);
    factory.setCoalescing(true);
    DocumentBuilder builder = factory.newDocumentBuilder();
    return builder.parse(path);
}

From source file:Main.java

public static Document createDocument() {
    Document document;/*ww  w .  ja va 2 s  .c  om*/

    try {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        document = builder.newDocument();
    } catch (Exception ex) {
        ex.printStackTrace();
        return null;
    }

    return document;
}

From source file:Main.java

private static DocumentBuilder xmlBuilder() throws ParserConfigurationException {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    return factory.newDocumentBuilder();
}

From source file:Main.java

public static Element parseElement(String xml) {
    try {/*from w ww.  j  av  a2  s.  co  m*/
        DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = dbfac.newDocumentBuilder();
        Document doc = docBuilder.parse(new ByteArrayInputStream(xml.getBytes()));
        return doc.getDocumentElement();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:Main.java

public static Document novoDocument() {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);/*ww w .  j  a  v  a2s. c  om*/
    DocumentBuilder builder = null;
    try {
        builder = dbf.newDocumentBuilder();
    } catch (ParserConfigurationException e) {
        throw new RuntimeException(e);
    }

    return builder.newDocument();
}

From source file:Main.java

public static Document parseToDom(String content) throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(false);//from   w  w  w  .  java  2s . c  om
    DocumentBuilder builder = factory.newDocumentBuilder();
    return builder.parse(new ByteArrayInputStream(content.getBytes()));
}

From source file:Main.java

public static Document stringToXML(String xmlString) throws Exception {

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);//from  www . ja v a 2  s. co  m
    Document document = null;
    try {
        document = factory.newDocumentBuilder().parse(new InputSource(new StringReader(xmlString)));
    } catch (Exception e) {
        e.printStackTrace();
    }

    return document;
}