public class XmlUtils extends Object
Modifier and Type | Method and Description |
---|---|
static Document |
createDocument()
Creates a new XML document.
|
static Element |
getFirstChildElement(Element parent)
Gets the first child element of an element.
|
static Element |
getRootElement(Document parent)
Gets the root element of a document.
|
static Document |
toDocument(InputStream in)
Parses an XML document from an input stream.
|
static Document |
toDocument(Reader reader)
Parses an XML document from a reader.
|
static Document |
toDocument(String xml)
Parses an XML string into a DOM.
|
static List<Element> |
toElementList(NodeList nodeList)
Gets all the elements out of a
NodeList . |
static String |
toString(Node node)
Converts an XML node to a string.
|
static String |
toString(Node node,
Map<String,String> outputProperties)
Converts an XML node to a string.
|
static void |
toWriter(Node node,
Writer writer)
Writes an XML node to a writer.
|
static void |
toWriter(Node node,
Writer writer,
Map<String,String> outputProperties)
Writes an XML node to a writer.
|
public static Document createDocument()
public static Document toDocument(String xml) throws SAXException
xml
- the XML stringSAXException
- if the string is not valid XMLpublic static Document toDocument(InputStream in) throws SAXException, IOException
in
- the input streamSAXException
- if the XML is not validIOException
- if there is a problem reading from the input streampublic static Document toDocument(Reader reader) throws SAXException, 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 readerSAXException
- if the XML is not validIOException
- if there is a problem reading from the readerpublic static String toString(Node node)
node
- the XML nodepublic static String toString(Node node, Map<String,String> outputProperties)
node
- the XML nodeoutputProperties
- the output propertiespublic static void toWriter(Node node, Writer writer) throws TransformerException
node
- the XML nodewriter
- the writerTransformerException
- if there's a problem writing to the writerpublic static void toWriter(Node node, Writer writer, Map<String,String> outputProperties) throws TransformerException
node
- the XML nodewriter
- the writeroutputProperties
- the output propertiesTransformerException
- if there's a problem writing to the writerpublic static List<Element> toElementList(NodeList nodeList)
NodeList
.nodeList
- the node listpublic static Element getRootElement(Document parent)
parent
- the documentThis software is published under the BSD license. Copyright © 2003-${build.year}, CRIXP AG, Switzerland, All rights reserved. Use is subject to license terms.