Java Utililty Methods XML Document Create

List of utility methods to do XML Document Create

Description

The list of methods to do XML Document Create are organized into topic(s).

Method

DocumentcreateDocument(String mainType, String customType)
create Document
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.newDocument();
document.setXmlStandalone(false);
Element sync = document.createElement("Sync");
document.appendChild(sync);
Element entity = document.createElement("Entity");
entity.setAttribute("mainType", mainType);
...
DocumentcreateDocument(String namespaceURI, String qualifiedName)
Creates a new document with the given namespace and document element.
DOMImplementation impl = getDOMImplementation();
return impl.createDocument(namespaceURI, qualifiedName, null);
DocumentcreateDocument(String pageID)
create Document
final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();
DOMImplementation implementation = builder.getDOMImplementation();
return implementation.createDocument(null, pageID, null);
DocumentcreateDocument(String root, NodeList content)
Creates a XML document with the given root element and the given NodeList as content.
DocumentBuilder docBuilder = createDocumentBuilder();
Document document = docBuilder.newDocument();
Element rootElement = document.createElement(root);
document.appendChild(rootElement);
for (int i = 0; i < content.getLength(); i++) {
    Node item = content.item(i);
    item = document.adoptNode(item.cloneNode(true));
    rootElement.appendChild(item);
...
DocumentcreateDocument(String rootElement)
create Document
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
Document document = dbFactory.newDocumentBuilder().newDocument();
document.appendChild(document.createElement(rootElement));
return document;
NodecreateDocument(String rootElementName)
create Document
try {
    DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder;
    docBuilder = docFactory.newDocumentBuilder();
    Document doc = docBuilder.newDocument();
    Element rootElement = doc.createElement(rootElementName);
    doc.appendChild(rootElement);
    return rootElement;
...
DocumentcreateDocument(String rootName)
Creates a new document with the param rootName
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document foo = builder.newDocument();
foo.createElement(rootName);
return foo;
DocumentcreateDocument(String rootNodeName)
This method creates a new Document Object.
DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
dfactory.setNamespaceAware(true);
dfactory.setValidating(false);
DocumentBuilder bldr = dfactory.newDocumentBuilder();
Document doc = bldr.newDocument();
Element rootEle = doc.createElement(rootNodeName);
doc.appendChild(rootEle);
return doc;
...
DocumentcreateDocument(String rootQName, String namespaceURI, String doctypePublicID, String doctypeSystemID)
Creates empty DOM Document using JAXP factoring.
DOMImplementation impl = getDOMImplementation();
if ((doctypePublicID != null) && (doctypeSystemID == null)) {
    throw new IllegalArgumentException("System ID cannot be null if public ID specified. "); 
DocumentType dtd = null;
if (doctypeSystemID != null) {
    dtd = impl.createDocumentType(rootQName, doctypePublicID, doctypeSystemID);
return impl.createDocument(namespaceURI, rootQName, dtd);
DocumentcreateDocument(String str)
create Document
try {
    StringReader reader = new StringReader(str);
    InputSource src = new InputSource();
    src.setCharacterStream(reader);
    Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(src);
    return doc;
} catch (Exception x) {
    throw new RuntimeException("Can't create document", x);
...