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

/**
 * Create a new XML document./* www  .j  a v a2s .c o  m*/
 * 
 * @return document
 * @throws ParserConfigurationException 
 */
public static Document newXml() throws ParserConfigurationException {
    DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
    return docBuilder.newDocument();
}

From source file:Main.java

public static Document createDocument() throws ParserConfigurationException {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    Document doc;//from  w w  w  . j av a  2 s. co m
    DocumentBuilder db;

    db = dbf.newDocumentBuilder();
    doc = db.newDocument();
    return doc;
}

From source file:Main.java

/**
 *
 *
 * @return .../*from ww w.ja  v a 2s  .  c  o m*/
 */
public static Document newDocument() {
    DocumentBuilder d = getDocumentBuilder();

    return d.newDocument();
}

From source file:Main.java

public static Document getdoc(String uri) throws Exception {
    uri = uri.replace(" ", "%20");
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = null;
    db = dbf.newDocumentBuilder();//from   w w  w.  j a  va2  s  . com
    Document doc = db.newDocument();
    doc = db.parse(new URL(uri).openStream());
    if (doc == null || doc.getTextContent() == "") {
        throw new Exception();
    } else
        return doc;
}

From source file:Main.java

/**
 * Creates a W3C DOM./*from  w  w  w .  j a v a2s .com*/
 *
 * @return The document object.
 * @throws ParserConfigurationException
 */
public static Document createDocument() throws ParserConfigurationException {
    DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = builderFactory.newDocumentBuilder();
    return builder.newDocument();
}

From source file:Main.java

@Nonnull
public static Document newDomDocument() throws IOException {
    try {// ww  w .j a v a  2s  . c o  m
        DocumentBuilderFactory factory = newDocumentBuilderFactory();
        DocumentBuilder builder = factory.newDocumentBuilder();
        return builder.newDocument();
    } catch (ParserConfigurationException e) {
        throw new IOException("Can't create new DOM-document.", e);
    }
}

From source file:Main.java

public static Document newDocument(boolean namespaceaware) throws Exception {
    DocumentBuilder builder = getSyncDocumentBuilder(namespaceaware);
    Document doc = builder.newDocument();
    builder.reset();/*from   w  ww . j ava  2  s  .c o m*/
    return doc;
}

From source file:Main.java

public static Document createDocument(String mainType, String customType) throws ParserConfigurationException {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document document = builder.newDocument();
    document.setXmlStandalone(false);//w ww  .jav a 2s  .c o  m
    Element sync = document.createElement("Sync");
    document.appendChild(sync);
    Element entity = document.createElement("Entity");
    entity.setAttribute("mainType", mainType);
    if (customType.length() > 0)
        entity.setAttribute("customType", customType);
    document.getElementsByTagName("Sync").item(0).appendChild(entity);
    return document;
}

From source file:Main.java

public static Document createXML() {
    try {//from www.  j  av  a  2 s. co  m
        DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
        return docBuilder.newDocument();
    } catch (ParserConfigurationException ex) {
        return null;
    }
}

From source file:Main.java

public static Document CreateCustomerFile(JFrame mainFrame) {
    Document CustomerDoc = null;/*  ww  w .j a v a 2  s . c  o  m*/
    try {
        DocumentBuilderFactory Factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder Build = Factory.newDocumentBuilder();
        CustomerDoc = Build.newDocument();
        Element rootElem = CustomerDoc.createElement("Customers");
        CustomerDoc.appendChild(rootElem);
    } catch (ParserConfigurationException ex) {
        System.out.println(ex.getMessage());
        JOptionPane.showMessageDialog(mainFrame,
                "There Was an Error Saving The File. Please Restart the Application.");
        System.exit(1);
    }
    return CustomerDoc;
}