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() {
    // creo la factory
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    // setX (che tipo di document builder ci deve produrre)

    dbf.setNamespaceAware(false);//  w  w w .ja v  a  2 s.  c o  m
    // se metti a true la valiazione il parser fa la validazione (prende la dtd associata e valida l'xml)
    dbf.setValidating(false);
    try {
        // dalla factory creo il DocumentBuilder
        DocumentBuilder db = dbf.newDocumentBuilder();
        return db.newDocument();
    } catch (ParserConfigurationException ex) {
        System.err.println("Impossibile creare il parser XML!");
    }

    return null;
}

From source file:Main.java

public static Document createDocument() throws ParserConfigurationException {
    DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
    return docBuilder.newDocument();
}

From source file:Main.java

/**
 * Creates a document/*from  ww  w  .ja  v  a2s  .  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 createDocument() {
    Document document;// w  w w  . ja va 2  s  .  c o m

    try {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        document = builder.newDocument();
    } catch (Exception ex) {
        ex.printStackTrace();
        return null;
    }

    return document;
}

From source file:Main.java

/**
 * Cria um documento XML vazio//  www  . java2  s.co  m
 * @return Document -> novo documento XML 
 * @throws Exception
 */
public static Document criarDocumentoXMl() throws Exception {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);
    DocumentBuilder db;
    db = dbf.newDocumentBuilder();
    Document doc = db.newDocument();
    return doc;
}

From source file:Utils.java

/**
 * Return a new document, ready to populate.
 * //from  w w  w . j av  a 2 s . com
 * @return
 * @throws ParserConfigurationException
 */
public static Document newDocument() throws ParserConfigurationException {
    DocumentBuilder builder = getBuilder();
    Document doc = builder.newDocument();
    releaseBuilder(builder);
    return doc;
}

From source file:Main.java

public static Document deserialize(Object object) throws Exception {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);//from ww w . jav a  2 s.  c  o  m
    DocumentBuilder db = dbf.newDocumentBuilder();
    Document doc = db.newDocument();

    JAXBContext context = JAXBContext.newInstance(object.getClass());
    Marshaller m = context.createMarshaller();
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    m.marshal(object, doc);
    return doc;
}

From source file:Main.java

private static Document createEmptyDocument() {
    DocumentBuilder documentBuilder = createDocumentBuilder();
    return documentBuilder.newDocument();
}

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

public static Document newDocument() {
    try {/*from w  w w  .  java2s . co m*/
        DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
        docBuilderFactory.setNamespaceAware(true);
        DocumentBuilder builder = docBuilderFactory.newDocumentBuilder();
        return builder.newDocument();
    } catch (ParserConfigurationException e) {
        throw new RuntimeException(e);
    }
}