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(final File file)
create Document
return createBuilder().parse(file);
DocumentcreateDocument(final String rootName)
Creates a new DOM.
if (docBuilder == null) {
    try {
        docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    } catch (final ParserConfigurationException exc) {
        exc.printStackTrace();
        return null;
final Document doc = docBuilder.newDocument();
if (rootName != null)
    doc.appendChild(doc.createElement(rootName));
return doc;
DocumentcreateDocument(InputSource is)
create Document
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
factory.setIgnoringElementContentWhitespace(true);
factory.setCoalescing(true);
DocumentBuilder builder = factory.newDocumentBuilder();
return builder.parse(is);
DocumentcreateDocument(Node node)
create Document
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
Document doc = dbf.newDocumentBuilder().newDocument();
if (node != null) {
    Transformer t = TransformerFactory.newInstance().newTransformer();
    t.transform(new DOMSource(node), new DOMResult(doc));
return doc;
...
DocumentcreateDocument(Node sourceNode)
create Document
Document doc = createDocumentBuilder().newDocument();
Node source;
if (sourceNode.getNodeType() == Node.DOCUMENT_NODE) {
    source = ((Document) sourceNode).getDocumentElement();
} else {
    source = sourceNode;
Node node = doc.importNode(source, true);
...
DocumentCreateDocument(Path xml, Path xsd)
Create Document
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(true);
factory.setNamespaceAware(true);
factory.setIgnoringComments(true);
factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage",
        "http://www.w3.org/2001/XMLSchema");
if (xsd != null)
    factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaSource", xsd.toString());
...
DocumentcreateDocument(String content, String charset)
create Document
try {
    InputStream is = new ByteArrayInputStream(content.getBytes(charset));
    return getBuilder().parse(is);
} catch (Exception e) {
    throw new RuntimeException(e);
DocumentcreateDocument(String docElt)
Creates a new DOM document.
getImplementation();
return impl.createDocument("", docElt, null);
DocumentcreateDocument(String docElt)
Creates a new DOM document.
getImplementation();
return impl.createDocument("", docElt, null);
DocumentcreateDocument(String iName)
create Document
DocumentBuilderFactory lFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder lBuilder = lFactory.newDocumentBuilder();
DOMImplementation lBuilderImpl = lBuilder.getDOMImplementation();
return lBuilderImpl.createDocument(null, iName, null);