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 newDocument(String rootName) throws ParserConfigurationException {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document doc = builder.newDocument();

    doc.appendChild(doc.createElement(rootName));

    return (doc);
}

From source file:Main.java

public static Document createDocument() throws Exception {
    DocumentBuilderFactory localDocumentBuilderFactory = getDocumentBuilderFactoryInstance();
    DocumentBuilder localDocumentBuilder = localDocumentBuilderFactory.newDocumentBuilder();
    return localDocumentBuilder.newDocument();
}

From source file:Main.java

/**
 * Creates a new DOM document.//from ww  w  .  ja  v  a2  s.com
 * 
 * @return a new empty DOM document
 */
public static Document createDocument() {
    try {
        DocumentBuilderFactory factory = (DocumentBuilderFactory) DocumentBuilderFactory.newInstance();
        DocumentBuilder b = (DocumentBuilder) factory.newDocumentBuilder();
        return b.newDocument();
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

From source file:Main.java

public static Document createNewDocument() throws ParserConfigurationException {
    DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    org.w3c.dom.Document doc = builder.newDocument();
    return doc;// w w w  .  j  a v  a  2 s  .  co m
}

From source file:Main.java

public static synchronized Document newDocument() {
    Document doc = null;/*w ww .  j  a va2s  . c  o  m*/
    try {
        DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        doc = db.newDocument();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return doc;
}

From source file:Main.java

/**
 * Creates and returns a newly created {@link Document}-object. This is
 * quite usual start {@link PersistenceHandler #save(ExerciseData) save()}
 * -method of an {@link PersistenceHandler}-implementor.
 * /*from w  w w. j  a va2s .  co  m*/
 * @return newly created empty {@link Document}-object
 * @throws ParserConfigurationException
 */
public static Document createEmptyDocument() throws ParserConfigurationException {
    DocumentBuilder dBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    Document doc = dBuilder.newDocument();

    return doc;
}

From source file:Main.java

/**
 *
 * @return//ww w  .  j  a v  a  2s. c  o  m
 */
public static Document getNewDocument() {
    Document document = null;
    try {
        DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
        document = documentBuilder.newDocument();
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    }

    return document;
}

From source file:Main.java

/**
 * Builds an XML document.//from  w  w  w . j  a v a  2  s .  co m
 * @return The XML document.
 * @throws ParserConfigurationException 
 */
private static Document getDocument() throws ParserConfigurationException {
    DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    return docBuilder.newDocument();
}

From source file:Main.java

public static void buildSkeleton() {
    try {//w ww  . j ava  2  s .co  m
        DocumentBuilderFactory dFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder dBldr = dFactory.newDocumentBuilder();

        Document doc = dBldr.newDocument();
        Element rootElement = doc.createElement("hooks");
        doc.appendChild(rootElement);

        write(doc);
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

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

    Document doc = docBuilder.newDocument();
    Element rootElement = doc.createElement(MESSAGES);
    doc.appendChild(rootElement);//from   www.java2 s.  c om

    Transformer transformer = getTransformer();

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