Example usage for javax.xml.parsers DocumentBuilder newDocument

List of usage examples for javax.xml.parsers DocumentBuilder newDocument

Introduction

In this page you can find the example usage for javax.xml.parsers DocumentBuilder newDocument.

Prototype


public abstract Document newDocument();

Source Link

Document

Obtain a new instance of a DOM Document object to build a DOM tree with.

Usage

From source file:Main.java

public static Document createDocument() throws ParserConfigurationException {
    DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
    docFactory.setNamespaceAware(true);/* ww w  .  j  ava  2  s.c o m*/
    return docBuilder.newDocument();

}

From source file:Main.java

public static synchronized void createIdStorage() throws ParserConfigurationException, TransformerException {
    DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder = docFactory.newDocumentBuilder();

    Document doc = docBuilder.newDocument();
    Element rootElement = doc.createElement(IDS);
    doc.appendChild(rootElement);/*www .j  av a  2 s .c  om*/

    Transformer transformer = getTransformer();

    DOMSource source = new DOMSource(doc);
    StreamResult result = new StreamResult(new File(ID_STORAGE_LOCATION));
    transformer.transform(source, result);
}

From source file:Main.java

public static Document open(IFile file, IProgressMonitor monitor) throws ParserConfigurationException {
    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
    if (!file.exists()) {
        return dBuilder.newDocument();
    }/*from w  w  w .j a  va 2s .  c om*/
    try {
        return dBuilder.parse(file.getContents());
    } catch (Exception e) {
        return dBuilder.newDocument();
    }
}

From source file:Main.java

/**
 * Creates a new empty XML DOM document.
 * @return the XML DOM document./* w w w.  j av  a2 s  .co  m*/
 */
public static Document getDocument() throws Exception {
    DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    return db.newDocument();
}

From source file:Main.java

public static Document getNewDocument() {
    Document doc = null;/*from   www . ja v a 2  s.c  o m*/
    //initializing the DOM object to load the XML object into
    try {
        javax.xml.parsers.DocumentBuilderFactory factory = javax.xml.parsers.DocumentBuilderFactory
                .newInstance();
        javax.xml.parsers.DocumentBuilder docbuilder = factory.newDocumentBuilder();
        doc = docbuilder.newDocument();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return doc;
}

From source file:Main.java

public static Document newXmlDocument() {
    try {//  w ww . ja v  a 2 s  . c o m
        DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
        return docBuilder.newDocument();
    } catch (ParserConfigurationException ex) {
        System.err.println("Error: Canot create new XML document");
        System.err.println("Cause: " + ex.getMessage());
        System.exit(1);
        return null;
    }
}

From source file:Main.java

static public Document getNewDocument() throws Exception {

    //Create instance of DocumentBuilderFactory
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    //Get the DocumentBuilder
    DocumentBuilder docBuilder = factory.newDocumentBuilder();
    //Create blank DOM Document
    Document doc = docBuilder.newDocument();
    return doc;/*www .j  av a2 s .  co  m*/
}

From source file:Main.java

public static Document buildDocumentWithRootElement() {

    try {/*from   w  w  w  . j a  v a  2 s.  c om*/
        DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder;
        docBuilder = docFactory.newDocumentBuilder();
        doc = docBuilder.newDocument();
        Element rootElement = doc.createElement(rootElementName);
        doc.appendChild(rootElement);
    } catch (ParserConfigurationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return doc;
}

From source file:Main.java

public synchronized static Document createDocument() throws ParserConfigurationException {
    DocumentBuilder builder = createDocumentBuilder();
    if (builder == null)
        return null;
    return builder.newDocument();
}

From source file:Main.java

public static Document createDocument() {
    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
    dbFactory.setNamespaceAware(true);/*from  www .  ja v  a  2s .c om*/
    DocumentBuilder dBuilder;
    try {
        dBuilder = dbFactory.newDocumentBuilder();
        return dBuilder.newDocument();
    } catch (ParserConfigurationException e) {
        throw new RuntimeException("Could not create XML document", e);
    }
}