Document
which can be used, for example for XSL transformations.
Document
:XMLDocumentBuilderFactory factory = XMLDocumentBuilderFactory.newInstance(); Document document = factory.parse(<the XML File>);
Document
in many situations, such as using an XSL transform. For example:// create the Document XMLDocumentBuilderFactory factory = XMLDocumentBuilderFactory.newInstance(); Document document = factory.parse(<the XML File>); // apply the XSL transform TransformerFactory factory = TransformerFactory.newInstance(); StreamSource streamSource = new StreamSource(<the XSL transform>); Transformer transformer = factory.newTransformer(streamSource); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no"); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); DOMSource xslDomSource = new DOMSource(document); File outputFile = ... // the XSL output file try ( FileOutputStream outputStream = new FileOutputStream(outputFile)) { try { transformer.transform(xslDomSource, new StreamResult(outputStream)); } catch (TransformerException e) { } }
XMLDocumentBuilderFactory factory = XMLDocumentBuilderFactory.newInstance(); factory.keepAttributesOrder(true); // specify that the order of attributes for each node will be preserved Document document = factory.parse(<the XML File>);
xml.space="&reserve&
XML declaration (by default spaces are not preserved)File file = ... XMLDocumentBuilderFactory factory = XMLDocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); Document document = factory.parse(file);
Document
:getSchemaTypeInfo
and getDomConfig()
methods are currently unsupportedcloneNode
method always return the same Node without cloningCopyright 2006-2024 Herve Girod. All Rights Reserved. Documentation and source under the LGPL v2 and Apache 2.0 licences