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

/**
 *
 * @param obj//from  w w  w  .  jav  a 2  s. c o  m
 * @return
 * @throws JAXBException
 * @throws ParserConfigurationException
 */
public static Document jaxbToDocument(Object obj) throws JAXBException, ParserConfigurationException {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = factory.newDocumentBuilder();
    Document doc = db.newDocument();
    // Marshal the Object to a Document
    final Marshaller m = JAXBContext.newInstance(obj.getClass()).createMarshaller();
    m.marshal(obj, doc);
    return doc;
}

From source file:Main.java

/**
 * Creates ElementNode for given tag with particular text as content.
 *//*w w w.  ja va2 s.c om*/
public static Element createTextNode(String tag, String content) throws ParserConfigurationException {
    DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
    Document doc = docBuilder.newDocument();
    Element node = doc.createElement(tag);
    Text t = doc.createTextNode(content);
    node.appendChild(t);

    return node;
}

From source file:Main.java

public static Document createDocument() {
    Document document = null;//from  w  ww.  j a v a  2 s  .c o  m

    try {
        DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder documentBuilder = builderFactory.newDocumentBuilder();
        document = documentBuilder.newDocument();
    } catch (ParserConfigurationException ex) {
        // Ignore parser configuration errors
    }

    return document;
}

From source file:Main.java

public static Document createDocument() {
    try {//from  w  w  w .  java  2s  .co  m
        DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        return builder.newDocument();
    } catch (ParserConfigurationException ignored) {
    }
    return null;
}

From source file:Main.java

public static Document createDocument() throws ParserConfigurationException {
    DocumentBuilder documentBuilder = s_documentBuilderFactory.newDocumentBuilder();
    Document document = documentBuilder.newDocument();
    return document;
}

From source file:Main.java

public static Document createNewXMLDocument() throws ParserConfigurationException {
    DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
    Document document = documentBuilder.newDocument();

    return document;
}

From source file:Main.java

/**
 * Creates a new empty DOM {@link Document}.
 *
 * @return the created {@code Document}.
 *///from www  .  j a  va 2 s . c  om
public static Document createEmptyDomDocument() {
    try {
        DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
        return documentBuilder.newDocument();
    } catch (ParserConfigurationException e) {
        throw new RuntimeException("Internal error: ParserConfigurationException: " + e.getMessage());
    }
}

From source file:Main.java

/**
 * Create a new DOM document/*from  w w w .  j ava2s  . c  o  m*/
 */
public static Document newDocument() throws IOException {
    try {
        DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        return builder.newDocument();
    } catch (ParserConfigurationException e) {
        throw new IOException(e.getMessage());
    }
}

From source file:Main.java

public static Document createDoc() {
    Document document = null;// ww  w.  j  av a 2s.  c  o  m
    DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
    try {
        DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
        document = docBuilder.newDocument();
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    }

    return document;
}

From source file:Main.java

public static Document newDocument() throws ParserConfigurationException {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);//  w  w w .  jav a2  s.  c  o  m
    DocumentBuilder documentBuilder = factory.newDocumentBuilder();
    return documentBuilder.newDocument();
}