List of utility methods to do XML Document Create
Document | createDocument(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); ... |
Document | createDocument(String namespaceURI, String qualifiedName) Creates a new document with the given namespace and document element. DOMImplementation impl = getDOMImplementation();
return impl.createDocument(namespaceURI, qualifiedName, null);
|
Document | createDocument(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); |
Document | createDocument(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); ... |
Document | createDocument(String rootElement) create Document DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
Document document = dbFactory.newDocumentBuilder().newDocument();
document.appendChild(document.createElement(rootElement));
return document;
|
Node | createDocument(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; ... |
Document | createDocument(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;
|
Document | createDocument(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;
...
|
Document | createDocument(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); |
Document | createDocument(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); ... |