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() throws ParserConfigurationException, SAXException, IOException {
    DocumentBuilderFactory dBuilderFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder dBuilder = dBuilderFactory.newDocumentBuilder();
    return dBuilder.parse(docPath);
}

From source file:Main.java

public static synchronized Document createDocument() throws Exception {
    DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
    Document document = docBuilder.newDocument();
    return document;
}

From source file:Main.java

private static Document getDocument(String filePath) throws Exception {
    File inputFile = new File(filePath);
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = dbf.newDocumentBuilder();
    Document doc = db.parse(inputFile);
    doc.getDocumentElement().normalize();
    return doc;/*from  w w  w.  j a  va 2 s.  c o  m*/
}

From source file:Main.java

public static NodeList readXML(File xmlfile, String tag) throws Exception {
    NodeList list = null;/*w w  w  .  ja  v  a2  s. co m*/
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document doc = builder.parse(xmlfile);
    Element rootElement = doc.getDocumentElement();
    list = rootElement.getElementsByTagName(tag);

    return list;
}

From source file:Main.java

private static Document getDoc() throws ParserConfigurationException {
    DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder = docFactory.newDocumentBuilder();

    //root elements
    Document doc = docBuilder.newDocument();
    return doc;/* w ww .  j  av a2 s  . co m*/
}

From source file:Main.java

public static Document fileToXMLDoc(File file) throws ParserConfigurationException, SAXException, IOException {
    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
    Document doc = dBuilder.parse(file);

    doc.getDocumentElement().normalize();

    return doc;/*from w  ww .  j  a v a2  s .c o m*/
}

From source file:Main.java

public static Document stringToDoc(final String xml) throws Exception {
    final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    final DocumentBuilder builder = factory.newDocumentBuilder();
    final InputSource is = new InputSource(new StringReader(xml));
    return builder.parse(is);
}

From source file:Main.java

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

From source file:Main.java

public static Document getW3CDom(String xmlStr) throws ParserConfigurationException, SAXException, IOException {
    StringReader sr = new StringReader(xmlStr);
    InputSource is = new InputSource(sr);
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document doc = builder.parse(is);
    return doc;/*w w  w. java  2 s.  c  o  m*/
}

From source file:Main.java

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