Example usage for javax.xml.parsers DocumentBuilderFactory newDocumentBuilder

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

Introduction

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

Prototype


public abstract DocumentBuilder newDocumentBuilder() throws ParserConfigurationException;

Source Link

Document

Creates a new instance of a javax.xml.parsers.DocumentBuilder using the currently configured parameters.

Usage

From source file:Main.java

public static Document getDocument(InputSource source)
        throws ParserConfigurationException, SAXException, IOException {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document doc = builder.parse(source);
    return doc;/*from  w w  w.ja  v a 2 s. c om*/
}

From source file:Main.java

public static Document createDocument() throws Exception {
    DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = builderFactory.newDocumentBuilder();
    return builder.newDocument();
}

From source file:Main.java

public static Document createDoc() throws ParserConfigurationException {
    DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
    Document doc = docBuilder.newDocument();
    return doc;//w ww . j  a v a2s  .c o  m
}

From source file:Main.java

public static Document buildAndParseDocument(String in) {
    try {/*from  w w  w .  jav a2  s  .  co  m*/
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db = dbf.newDocumentBuilder();
        InputSource is = new InputSource(new StringReader(in));
        return db.parse(is);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:Main.java

public static Document convertStringToDocument(String xmlStr)
        throws ParserConfigurationException, SAXException, IOException {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();

    return builder.parse(new InputSource(new StringReader(xmlStr)));
}

From source file:Main.java

public static Document toDocument(String content)
        throws ParserConfigurationException, SAXException, IOException {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = dbf.newDocumentBuilder();
    return content == null ? null : db.parse(new InputSource(new StringReader(content)));
}

From source file:Main.java

public static Document toDocument(InputStream input)
        throws ParserConfigurationException, SAXException, IOException {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = dbf.newDocumentBuilder();
    return input == null ? null : db.parse(input);
}

From source file:Main.java

private static Document initializeXML(File xmlFile) throws Exception {
    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
    Document doc = dBuilder.parse(xmlFile);
    doc.getDocumentElement().normalize();
    return doc;//from   w  ww .ja va  2s  . c om
}

From source file:Main.java

/**
 * Creates a document/*from   w  ww. j  av a2  s  .co  m*/
 * @return Document
 * @throws ParserConfigurationException
 */
public static Document createDocument() throws ParserConfigurationException {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document document = builder.newDocument();
    return document;
}

From source file:Main.java

public static Document loadXMLFromString(String xml)
        throws ParserConfigurationException, SAXException, IOException {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    InputSource is = new InputSource(new StringReader(xml));
    return builder.parse(is);
}