public class XmlUtils
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static org.w3c.dom.Document |
createDocument()
Creates a new XML document.
|
static org.w3c.dom.Element |
getFirstChildElement(org.w3c.dom.Element parent)
Gets the first child element of an element.
|
static org.w3c.dom.Element |
getRootElement(org.w3c.dom.Document parent)
Gets the root element of a document.
|
static org.w3c.dom.Document |
toDocument(java.io.InputStream in)
Parses an XML document from an input stream.
|
static org.w3c.dom.Document |
toDocument(java.io.Reader reader)
Parses an XML document from a reader.
|
static org.w3c.dom.Document |
toDocument(java.lang.String xml)
Parses an XML string into a DOM.
|
static java.util.List<org.w3c.dom.Element> |
toElementList(org.w3c.dom.NodeList nodeList)
Gets all the elements out of a
NodeList . |
static java.lang.String |
toString(org.w3c.dom.Node node)
Converts an XML node to a string.
|
static java.lang.String |
toString(org.w3c.dom.Node node,
java.util.Map<java.lang.String,java.lang.String> outputProperties)
Converts an XML node to a string.
|
static void |
toWriter(org.w3c.dom.Node node,
java.io.Writer writer)
Writes an XML node to a writer.
|
static void |
toWriter(org.w3c.dom.Node node,
java.io.Writer writer,
java.util.Map<java.lang.String,java.lang.String> outputProperties)
Writes an XML node to a writer.
|
public static org.w3c.dom.Document createDocument()
public static org.w3c.dom.Document toDocument(java.lang.String xml) throws org.xml.sax.SAXException
xml
- the XML stringorg.xml.sax.SAXException
- if the string is not valid XMLpublic static org.w3c.dom.Document toDocument(java.io.InputStream in) throws org.xml.sax.SAXException, java.io.IOException
in
- the input streamorg.xml.sax.SAXException
- if the XML is not validjava.io.IOException
- if there is a problem reading from the input streampublic static org.w3c.dom.Document toDocument(java.io.Reader reader) throws org.xml.sax.SAXException, java.io.IOException
Parses an XML document from a reader.
Note that use of this method is discouraged. It ignores the character
encoding that is defined within the XML document itself, and should only
be used if the encoding is undefined or if the encoding needs to be
ignored for whatever reason. The toDocument(InputStream)
method
should be used instead, since it takes the XML document's character
encoding into account when parsing.
reader
- the readerorg.xml.sax.SAXException
- if the XML is not validjava.io.IOException
- if there is a problem reading from the readerpublic static java.lang.String toString(org.w3c.dom.Node node)
node
- the XML nodepublic static java.lang.String toString(org.w3c.dom.Node node, java.util.Map<java.lang.String,java.lang.String> outputProperties)
node
- the XML nodeoutputProperties
- the output propertiespublic static void toWriter(org.w3c.dom.Node node, java.io.Writer writer) throws javax.xml.transform.TransformerException
node
- the XML nodewriter
- the writerjavax.xml.transform.TransformerException
- if there's a problem writing to the writerpublic static void toWriter(org.w3c.dom.Node node, java.io.Writer writer, java.util.Map<java.lang.String,java.lang.String> outputProperties) throws javax.xml.transform.TransformerException
node
- the XML nodewriter
- the writeroutputProperties
- the output propertiesjavax.xml.transform.TransformerException
- if there's a problem writing to the writerpublic static java.util.List<org.w3c.dom.Element> toElementList(org.w3c.dom.NodeList nodeList)
NodeList
.nodeList
- the node listpublic static org.w3c.dom.Element getRootElement(org.w3c.dom.Document parent)
parent
- the documentpublic static org.w3c.dom.Element getFirstChildElement(org.w3c.dom.Element parent)
parent
- the parent elementThis software is published under the BSD license. Copyright © 2003-${build.year}, CRIXP AG, Switzerland, All rights reserved. Use is subject to license terms.