List of utility methods to do XML Document Create
Document | createDocumentFromXml(String input) create Document From Xml DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); StringReader stringReader = new StringReader(input); InputSource inputSource = new InputSource(stringReader); return documentBuilder.parse(inputSource); |
Document | createDocumentFromXMLContent(String docContent) create Document From XML Content DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); Document doc = docBuilder.parse(new ByteArrayInputStream(docContent.getBytes())); TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory .newTransformer(new StreamSource("src/test/resources/strip-spaces.xls")); DOMSource source = new DOMSource(doc); OutputStream os = new ByteArrayOutputStream(); ... |
Document | createDocumentFromXmlFragment(final InputStream inputStreamXmlFragment, final URL urlSchema) create Document From Xml Fragment Document ret = null; if (null == inputStreamXmlFragment) { throw new NullPointerException("input stream XML fragment is null"); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); if (null != urlSchema) { SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); ... |
Document | createDocumentFromXmlString(String xmlStr) create Document From Xml String try { DocumentBuilderFactory docBuilderFactory; docBuilderFactory = DocumentBuilderFactory.newInstance(); docBuilderFactory.setIgnoringComments(true); docBuilderFactory.setIgnoringElementContentWhitespace(true); docBuilderFactory.setNamespaceAware(false); DocumentBuilder builder = docBuilderFactory.newDocumentBuilder(); ByteArrayInputStream bais = new ByteArrayInputStream(xmlStr.getBytes()); ... |
Document | createEmptyDocument() Create empty document DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = dbf.newDocumentBuilder();
return builder.newDocument();
|
Document | createEmptyDocument() create Empty Document DocumentBuilder documentBuilder = createDocumentBuilder();
return documentBuilder.newDocument();
|
Document | createEmptyDocument() Creates an empty XML document. DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder; try { builder = factory.newDocumentBuilder(); } catch (ParserConfigurationException e) { throw new IllegalStateException("No document builder found, probably Java is misconfigured!", e); return builder.newDocument(); ... |
Document | createEmptyDocument() Purpose: Creates an Empty XML Document object DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
DOMImplementation impl = builder.getDOMImplementation();
Document doc = impl.createDocument(null, null, null);
return doc;
|
Document | createEmptyDocument(final DocumentBuilder builder) create Empty Document return builder.newDocument();
|
Element | createEmptyElement(Document doc, QName qname) create Empty Element String prefix = qname.getPrefix(); String name = qname.getLocalPart(); if (prefix != null && prefix.length() > 0) name = prefix + ':' + name; String uri = qname.getNamespaceURI(); return doc.createElementNS(uri, name); |