List of utility methods to do XML Document Create
Document | createDocument(String xml) convenience method to create an xml Document. DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(new ByteArrayInputStream(xml.getBytes())); doc.getDocumentElement().normalize(); return doc; |
DocumentBuilder | createDocumentBuilder() Builds new DocumentBuilder DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setValidating(false); dbf.setIgnoringComments(true); dbf.setNamespaceAware(false); try { return dbf.newDocumentBuilder(); } catch (ParserConfigurationException e) { throw new RuntimeException("Failed to create a document builder factory", e); ... |
DocumentBuilder | createDocumentBuilder(boolean namespaces, boolean validating) create Document Builder DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(namespaces);
factory.setValidating(validating);
DocumentBuilder builder = factory.newDocumentBuilder();
return builder;
|
DocumentBuilderFactory | createDocumentBuilderFactory() Creates a new DocumentBuilderFactory instance. return DocumentBuilderFactory.newInstance();
|
DocumentBuilderFactory | createDocumentBuilderFactory(ClassLoader classLoader) create Document Builder Factory if (classLoader == null) classLoader = Thread.currentThread().getContextClassLoader(); return DocumentBuilderFactory.newInstance(DOCUMENT_BUILDER_FACTORY_IMPL, classLoader); |
Document | createDocumentFromElement(final Element element) create Document From Element Document ret = null; if (null == element) { throw new NullPointerException("input DOM element is null"); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); ret = factory.newDocumentBuilder().newDocument(); Node domNode = ret.importNode(element, true); ... |
Document | createDocumentFromFile(File file) create Document From File DocumentBuilderFactory factory = getDocumentBuilderFactory(); DocumentBuilder builder; try { builder = factory.newDocumentBuilder(); } catch (ParserConfigurationException e) { throw new Exception(e); return builder.parse(file); ... |
Document | createDocumentFromResult(final StreamResult result) returns Document from StreamResult Document document = null; final String fileString = result.getWriter().toString(); try { final DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder(); final StringReader reader = new StringReader(fileString); final InputSource inputSource = new InputSource(reader); document = parser.parse(inputSource); } catch (final SAXException e) { ... |
Document | createDocumentFromString(String str) create Document From String DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setValidating(false); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document document = documentBuilder.parse(new InputSource(new StringReader(str))); return document; |
Document | createDocumentFromString(String xmlString) create Document From String DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder(); ByteArrayInputStream byteIs = new ByteArrayInputStream(xmlString.getBytes()); Document doc = parser.parse(byteIs); return doc; |