Java XML Document Create createDocument(String mainType, String customType)

Here you can find the source of createDocument(String mainType, String customType)

Description

create Document

License

Apache License

Declaration

public static Document createDocument(String mainType, String customType) throws ParserConfigurationException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

public class Main {
    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);
        Element sync = document.createElement("Sync");
        document.appendChild(sync);/*from   w  w  w . j  a v  a 2 s .c o  m*/
        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;
    }
}

Related

  1. CreateDocument(Path xml, Path xsd)
  2. createDocument(String content, String charset)
  3. createDocument(String docElt)
  4. createDocument(String docElt)
  5. createDocument(String iName)
  6. createDocument(String namespaceURI, String qualifiedName)
  7. createDocument(String pageID)
  8. createDocument(String root, NodeList content)
  9. createDocument(String rootElement)