Package de.aristaflow.adept2.util.xml
Class XMLHelperTools
- java.lang.Object
-
- de.aristaflow.adept2.util.xml.XMLHelperTools
-
public class XMLHelperTools extends Object
Contains important function for both, XML import and export.
-
-
Field Summary
Fields Modifier and Type Field Description static String
DEFAULT_ENCODING
The encoding that should be used for writing XML files.static String
ENCODING
Deprecated.UseDEFAULT_ENCODING
instead.protected static Logger
logger
The logger instance of this class.
-
Constructor Summary
Constructors Constructor Description XMLHelperTools()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static Document
createDocument()
Initialises the document object which will be used for constructing elements.static byte[]
getByteArrayForDocument(Node node)
Returns a byte array containing the XML code for the given node.static byte[]
getByteArrayForDocument(Node node, boolean intend)
Returns a byte array containing the XML code for the given node.static Document
getDocumentFromFile(File file, Schema schema, ErrorHandler errorHandler)
Read a Document from a stream.static Document
getDocumentFromSource(InputSource source)
Reads a document from the designated source; namespaces will be used, no validation will take place.static Document
getDocumentFromSource(InputSource source, Schema schema, ErrorHandler errorHandler, boolean nsAware)
Reads a document from the designated source.static Document
getDocumentFromStream(InputStream inputStream)
Parse a Stream and converts it to a Documentstatic Document
getDocumentFromStream(InputStream inputStream, Schema schema, ErrorHandler errorHandler, boolean nsAware)
Reads a document from the designated stream.static Document
getDocumentFromString(String string, Schema schema)
Parse a string and converts it to a Document using theDEFAULT_ENCODING
.static Element
getElement(Node node)
Finds an DOM Element for a given Node.static AttributedInputStream
getInputStreamForDocument(Node node)
Deprecated, for removal: This API element is subject to removal in a future version.UsegetStreamForDocument(Node)
instead.static AttributedInputStream
getInputStreamForDocument(Node node, boolean intend)
Deprecated, for removal: This API element is subject to removal in a future version.UsegetStreamForDocument(Node, boolean)
instead.static ByteArrayOutputStream
getOutputStreamForDocument(Node node)
Deprecated, for removal: This API element is subject to removal in a future version.UsegetStreamForDocument(Node)
instead.static ByteArrayOutputStream
getOutputStreamForDocument(Node node, boolean intend)
Deprecated, for removal: This API element is subject to removal in a future version.UsegetStreamForDocument(Node, boolean)
instead.static ByteArrayOutputStream
getOutputStreamForDocument(Node node, Source xslt)
Deprecated, for removal: This API element is subject to removal in a future version.UsegetStreamForDocument(Node, Source)
instead.static ByteArrayOutputStream
getOutputStreamForDocument(Node node, Source xslt, boolean intend)
Deprecated, for removal: This API element is subject to removal in a future version.UsegetStreamForDocument(Node, Source, boolean)
instead.static int
getParsedID(String nodeValue)
Strips off the leading character and parses the integer value.static int
getParsedID(Node node)
Strips off the leading character and parses the integer value.static AttributedInputStream
getStreamForDocument(Node node)
Gets an input stream containing the XML code of the given node.static AttributedInputStream
getStreamForDocument(Node node, boolean intend)
Gets an input stream containing the XML code of the given node.static AttributedInputStream
getStreamForDocument(Node node, Source xslt)
Gets an input stream containing the XML code of the given node.static AttributedInputStream
getStreamForDocument(Node node, Source xslt, boolean intend)
Gets an input stream containing the XML code of the given node using theDEFAULT_ENCODING
.protected static String
getTagName(Element e)
This method returns the tag name of the given element.static String
getXMLStringForDocument(Node node)
Returns the XML code of a given node as string.static String
getXMLStringForDocument(Node node, boolean intend)
Returns the XML code of a given node as string.static String
getXMLStringForInputStream(InputStream is)
Deprecated, for removal: This API element is subject to removal in a future version.UseStreamTools.readUtf8String(InputStream)
instead.static boolean
hasTagName(Element e, String... names)
This method checks, whether the (local) tag name of the given element matches one of the designated names.static boolean
hasTagName(Node n, String... names)
This method checks, whether the (local) tag name of the given element matches one of the designated names.static boolean
isStreamValid(InputStream is, Schema schema)
Returns whether the givenNode
is valid against the givenSchema
.static boolean
isValid(Node node, Schema schema)
Returns whether the givennode
is valid against the givenSchema
.static Element
nextElement(Node node)
Find the next element that actually contains data.static Element
nextElement(Node node, String name)
Find the next element that actually contains data, with the given name.
NOTE: If the current node is an element that matches the name it will be returned!static String
replaceWithXMLEntities(String string)
Replaces all occurrences of special characters that may not appear directly in XML (<, >, &, ' and ") with their corresponding XML entities.static void
validateAndPrintDoc(Node node, Schema schema)
Checks, if a node uses a valid schema.static void
validateDocument(Node node, Schema schema)
Checks, if a node uses a valid schema.static void
validateStream(InputStream is, Schema schema)
Checks, if a node uses a valid schema.static void
writeDocumentToFile(Node node, File file, Schema schema)
Exports a DOM node to a file, validates the node before the export, if a schema type is provided.static void
writeDocumentToFile(Node node, File file, Schema schema, boolean intend)
Exports a DOM node to a file using theDEFAULT_ENCODING
, validates the node before the export, if a schema type is provided.static void
writeDocumentToFile(Node node, File file, Schema schema, boolean intend, String encoding)
Exports a DOM node to a file using the designated encoding.static void
writeDocumentToStream(Node node, OutputStream out)
Writes the node to the given output stream.static void
writeDocumentToStream(Node node, OutputStream out, boolean intend)
Writes the node to the given output stream using theDEFAULT_ENCODING
.static void
writeDocumentToStream(Node node, OutputStream out, boolean intend, String encoding)
Writes the node to the designated output stream with the designated encoding.static OutputStream
writeDocumentToStream(Node node, OutputStream os, Source xslt)
Transforms and writes the XML code of the designated node to the designated output stream using theDEFAULT_ENCODING
.static OutputStream
writeDocumentToStream(Node node, OutputStream os, Source xslt, boolean intend)
Transforms and writes the XML code of the designated node to the designated output stream using theDEFAULT_ENCODING
.static void
writeDocumentToWriter(Node node, Writer out)
Writes the node to the designated writer with no indentation and theDEFAULT_ENCODING
.static void
writeDocumentToWriter(Node node, Writer out, boolean intend)
Writes the node to the designated writer withDEFAULT_ENCODING
.static void
writeDocumentToWriter(Node node, Writer out, boolean intend, String encoding)
Writes the node to the designated writer with the designated encoding.
-
-
-
Field Detail
-
ENCODING
@Deprecated public static final String ENCODING
Deprecated.UseDEFAULT_ENCODING
instead.The encoding that should be used for writing xml files. Some preferable encodings are 'UTF-8', 'UTF-16BE', 'UTF-16LE' or 'ISO-8859-1'- See Also:
for more possible encodings
, Constant Field Values
-
DEFAULT_ENCODING
public static final String DEFAULT_ENCODING
The encoding that should be used for writing XML files. Some preferable encodings are 'UTF-8', 'UTF-16BE', 'UTF-16LE' or 'ISO-8859-1'.
Note that Microsoft DBMS do not supportUTF-8
but onlyUTF-16
.- See Also:
for more possible encodings
, Constant Field Values
-
logger
protected static final Logger logger
The logger instance of this class.
-
-
Method Detail
-
isValid
public static boolean isValid(Node node, Schema schema)
Returns whether the givennode
is valid against the givenSchema
.- Parameters:
node
- The node to be validated.schema
- The schema to validate the node against.- Returns:
- Whether the given
Node
is valid against the givenSchema
.
-
isStreamValid
public static boolean isStreamValid(InputStream is, Schema schema)
Returns whether the givenNode
is valid against the givenSchema
.- Parameters:
is
- The input stream containing the XML data to be validated.schema
- The schema to validate the node against.- Returns:
- Whether the given
Node
is valid against the givenSchema
.
-
validateAndPrintDoc
public static void validateAndPrintDoc(Node node, Schema schema) throws XMLFormatException, IOException
Checks, if a node uses a valid schema. If not the invalid XML will be written toSystem.out
.- Parameters:
node
- The node, that wants to be checked.schema
- The Schema, the node has to use, to be valid.- Throws:
XMLFormatException
- when the validation fails.IOException
- when conversion to string representation fails.
-
validateDocument
public static void validateDocument(Node node, Schema schema) throws XMLFormatException
Checks, if a node uses a valid schema.- Parameters:
node
- The node, that wants to be checked.schema
- The Schema, the node has to use, to be valid.- Throws:
XMLFormatException
- when the validation fails
-
validateStream
public static void validateStream(InputStream is, Schema schema) throws XMLFormatException
Checks, if a node uses a valid schema.- Parameters:
is
- The input stream containing the XML data.schema
- The Schema, the node has to use, to be valid.- Throws:
XMLFormatException
- when the validation fails
-
replaceWithXMLEntities
public static String replaceWithXMLEntities(String string)
Replaces all occurrences of special characters that may not appear directly in XML (<, >, &, ' and ") with their corresponding XML entities.- Parameters:
string
- the string to be converted- Returns:
- the converted string
-
getDocumentFromString
public static Document getDocumentFromString(String string, Schema schema) throws XMLFormatException, IOException
Parse a string and converts it to a Document using theDEFAULT_ENCODING
.- Parameters:
string
- The string, that shall be converted.schema
- The XML Schema to validate the document against ornull
to omit validation.- Returns:
- A DOM document for the XML in the given string.
- Throws:
XMLFormatException
- if the document is not well-formedIOException
- if error occurs while reading from the file
-
getDocumentFromFile
public static Document getDocumentFromFile(File file, Schema schema, ErrorHandler errorHandler) throws XMLFormatException, FileNotFoundException, IOException
Read a Document from a stream.- Parameters:
file
-schema
- The XML Schema to validate the document against ornull
to omit validationerrorHandler
- The optional error handler that will be used for the document builder- Returns:
- A DOM document
- Throws:
XMLFormatException
- if the document is not well-formed or doesn't conform to the given SchemaFileNotFoundException
- if the file does not exist or can't be openedIOException
- if error occurs while reading from the file
-
getDocumentFromStream
public static Document getDocumentFromStream(InputStream inputStream) throws XMLFormatException, IOException
Parse a Stream and converts it to a Document- Parameters:
inputStream
- The stream that shall be converted- Returns:
- A DOM document for the given input stream.
- Throws:
XMLFormatException
- if the document is not well-formedIOException
- if error occurs while reading from the stream
-
getDocumentFromSource
public static Document getDocumentFromSource(InputSource source) throws XMLFormatException, IOException
Reads a document from the designated source; namespaces will be used, no validation will take place.- Parameters:
source
- The source providing the XML.- Returns:
- A DOM document read from the designated source.
- Throws:
XMLFormatException
- If parsing the XML failed, anXMLFormatException
will be thrown.IOException
- If there are problems reading from the designated source, anIOException
will be thrown.
-
getDocumentFromStream
public static Document getDocumentFromStream(InputStream inputStream, Schema schema, ErrorHandler errorHandler, boolean nsAware) throws XMLFormatException, IOException
Reads a document from the designated stream. Optionally, the document will be validated against the designated schema and namespaces may be used.- Parameters:
inputStream
- The input stream providing the XML.schema
- The XML Schema to validate the document against ornull
to omit validation.nsAware
- Whether the input stream should be parsed namespace aware.errorHandler
- The optional error handler that will be used for the document builder.- Returns:
- A DOM document read from the designated source.
- Throws:
XMLFormatException
- If parsing or validating the XML failed, anXMLFormatException
will be thrown.IOException
- If there are problems reading from the designated source, anIOException
will be thrown.
-
getDocumentFromSource
public static Document getDocumentFromSource(InputSource source, Schema schema, ErrorHandler errorHandler, boolean nsAware) throws XMLFormatException, IOException
Reads a document from the designated source. Optionally, the document will be validated against the designated schema and namespaces may be used.- Parameters:
source
- The source providing the XML.schema
- The XML Schema to validate the document against ornull
to omit validation.nsAware
- Whether the input stream should be parsed namespace aware.errorHandler
- The optional error handler that will be used for the document builder.- Returns:
- A DOM document read from the designated source.
- Throws:
XMLFormatException
- If parsing or validating the XML failed, anXMLFormatException
will be thrown.IOException
- If there are problems reading from the designated source, anIOException
will be thrown.
-
createDocument
public static Document createDocument()
Initialises the document object which will be used for constructing elements.- Returns:
- The new document
-
getXMLStringForDocument
public static String getXMLStringForDocument(Node node) throws IOException
Returns the XML code of a given node as string.- Parameters:
node
- The node to be transformed- Returns:
- The XML code of the given node as string.
- Throws:
IOException
- Thrown if an unrecoverable error occurs during the course of the transformation
-
getXMLStringForDocument
public static String getXMLStringForDocument(Node node, boolean intend) throws IOException
Returns the XML code of a given node as string.- Parameters:
node
- The node to be transformedintend
- Whether to intend child nodes and text content. Use with care! Text content may contain whitespace and linebreaks afterwards!- Returns:
- The XML code of the given node as string.
- Throws:
IOException
- Thrown if an unrecoverable error occurs during the course of the transformation
-
getXMLStringForInputStream
@Deprecated(since="15.0.0", forRemoval=true) public static String getXMLStringForInputStream(InputStream is) throws IOException
Deprecated, for removal: This API element is subject to removal in a future version.UseStreamTools.readUtf8String(InputStream)
instead.Returns the XML code of a given input stream as string using theDEFAULT_ENCODING
.- Parameters:
is
- The input stream which should be transformed. This method will close the stream after reading.- Returns:
- The xml code of the given input stream as string.
- Throws:
IOException
- Thrown if an unrecoverable error occurs during the course of the transformation
-
getInputStreamForDocument
@Deprecated(since="15.0.0", forRemoval=true) public static AttributedInputStream getInputStreamForDocument(Node node) throws IOException
Deprecated, for removal: This API element is subject to removal in a future version.UsegetStreamForDocument(Node)
instead.Returns an input stream containing the XML code of the given node.- Parameters:
node
- The node to be transformed- Returns:
- The input stream of the XML code of the node. The caller is responsible for closing.
- Throws:
IOException
- Thrown if an unrecoverable error occurs during the course of the transformation.
-
getInputStreamForDocument
@Deprecated(since="15.0.0", forRemoval=true) public static AttributedInputStream getInputStreamForDocument(Node node, boolean intend) throws IOException
Deprecated, for removal: This API element is subject to removal in a future version.UsegetStreamForDocument(Node, boolean)
instead.Returns an input stream containing the XML code of the given node.- Parameters:
node
- The node to be transformedintend
- Whether to intend child nodes and text content. Use with care! Text content may contain whitespace and linebreaks afterwards!- Returns:
- The input stream of the XML code of the node. The caller is responsible for closing.
- Throws:
IOException
- Thrown if an unrecoverable error occurs during the course of the transformation.
-
getByteArrayForDocument
public static byte[] getByteArrayForDocument(Node node) throws IOException
Returns a byte array containing the XML code for the given node.- Parameters:
node
- The node to be transformed.- Returns:
- The byte array of the node.
- Throws:
IOException
-
getByteArrayForDocument
public static byte[] getByteArrayForDocument(Node node, boolean intend) throws IOException
Returns a byte array containing the XML code for the given node.- Parameters:
node
- The node to be transformed.intend
- Whether to intend child nodes and text content. Use with care! Text content may contain whitespace and linebreaks afterwards!- Returns:
- The byte array of the node.
- Throws:
IOException
-
getOutputStreamForDocument
@Deprecated(since="15.0.0", forRemoval=true) public static ByteArrayOutputStream getOutputStreamForDocument(Node node) throws IOException
Deprecated, for removal: This API element is subject to removal in a future version.UsegetStreamForDocument(Node)
instead.Returns an output stream containing the XML code of the given node.- Parameters:
node
- The node to be transformed.- Returns:
- The output stream of the XML code of the node. The caller is responsible for closing.
- Throws:
IOException
- Thrown if an unrecoverable error occurs during the course of the transformation.
-
getOutputStreamForDocument
@Deprecated(since="15.0.0", forRemoval=true) public static ByteArrayOutputStream getOutputStreamForDocument(Node node, boolean intend) throws IOException
Deprecated, for removal: This API element is subject to removal in a future version.UsegetStreamForDocument(Node, boolean)
instead.Returns an output stream containing the XML code of the given node.- Parameters:
node
- The node to be transformed.intend
- Whether to intend child nodes and text content. Use with care! Text content may contain whitespace and linebreaks afterwards!- Returns:
- The output stream of the XML code of the node. The caller is responsible for closing.
- Throws:
IOException
- Thrown if an unrecoverable error occurs during the course of the transformation.
-
getOutputStreamForDocument
@Deprecated(since="15.0.0", forRemoval=true) public static ByteArrayOutputStream getOutputStreamForDocument(Node node, Source xslt) throws IOException
Deprecated, for removal: This API element is subject to removal in a future version.UsegetStreamForDocument(Node, Source)
instead.Returns an output stream containing the XML code of the given node.- Parameters:
node
- The node to be transformed.xslt
- The XSLT style sheet that should be used for the transformer.- Returns:
- The output stream of the XML code of the node. The caller is responsible for closing.
- Throws:
IOException
- Thrown if an unrecoverable error occurs during the course of the transformation.
-
getOutputStreamForDocument
@Deprecated(since="15.0.0", forRemoval=true) public static ByteArrayOutputStream getOutputStreamForDocument(Node node, Source xslt, boolean intend) throws IOException
Deprecated, for removal: This API element is subject to removal in a future version.UsegetStreamForDocument(Node, Source, boolean)
instead.Returns an output stream containing the XML code of the given node using theDEFAULT_ENCODING
.- Parameters:
node
- The node to be transformed.xslt
- The XSLT style sheet that should be used for the transformer.intend
- Whether to intend child nodes and text content. Use with care! Text content may contain whitespace and linebreaks afterwards!- Returns:
- The output stream of the XML code of the node. The caller is responsible for closing.
- Throws:
IOException
- Thrown if an unrecoverable error occurs during the course of the transformation.
-
getStreamForDocument
public static AttributedInputStream getStreamForDocument(Node node) throws IOException
Gets an input stream containing the XML code of the given node.- Parameters:
node
- The node to be transformed.- Returns:
- The output stream of the XML code of the node. The caller is responsible for closing.
- Throws:
IOException
- Thrown if an unrecoverable error occurs during the course of the transformation.
-
getStreamForDocument
public static AttributedInputStream getStreamForDocument(Node node, boolean intend) throws IOException
Gets an input stream containing the XML code of the given node.- Parameters:
node
- The node to be transformed.intend
- Whether to intend child nodes and text content. Use with care! Text content may contain whitespace and linebreaks afterwards!- Returns:
- The output stream of the XML code of the node. The caller is responsible for closing.
- Throws:
IOException
- Thrown if an unrecoverable error occurs during the course of the transformation.
-
getStreamForDocument
public static AttributedInputStream getStreamForDocument(Node node, Source xslt) throws IOException
Gets an input stream containing the XML code of the given node.- Parameters:
node
- The node to be transformed.xslt
- The XSLT style sheet that should be used for the transformer.- Returns:
- The output stream of the XML code of the node. The caller is responsible for closing.
- Throws:
IOException
- Thrown if an unrecoverable error occurs during the course of the transformation.
-
getStreamForDocument
public static AttributedInputStream getStreamForDocument(Node node, Source xslt, boolean intend) throws IOException
Gets an input stream containing the XML code of the given node using theDEFAULT_ENCODING
.- Parameters:
node
- The node to be transformed.xslt
- The XSLT style sheet that should be used for the transformer.intend
- Whether to intend child nodes and text content. Use with care! Text content may contain whitespace and linebreaks afterwards!- Returns:
- The output stream of the XML code of the node. The caller is responsible for closing.
- Throws:
IOException
- Thrown if an unrecoverable error occurs during the course of the transformation.
-
writeDocumentToStream
public static void writeDocumentToStream(Node node, OutputStream out) throws IOException
Writes the node to the given output stream.- Parameters:
node
-out
-- Throws:
IOException
-
writeDocumentToStream
public static void writeDocumentToStream(Node node, OutputStream out, boolean intend) throws IOException
Writes the node to the given output stream using theDEFAULT_ENCODING
.- Parameters:
node
-out
- The stream to which to write the designated node to. Set the encoding appropriately!intend
- Whether to intend child nodes and text content. Use with care! Text content may contain whitespace and linebreaks afterwards!- Throws:
IOException
-
writeDocumentToStream
public static void writeDocumentToStream(Node node, OutputStream out, boolean intend, String encoding) throws IOException
Writes the node to the designated output stream with the designated encoding. Please set this encoding in the stream appropriately.- Parameters:
node
-out
- The stream to which to write the designated node to. Set the enccoding appropriately!intend
- Whether to intend child nodes and text content. Use with care! Text content may contain whitespace and linebreaks afterwards!encoding
- The encoding used for writing the designated node. This has to conform to the encoding of the designated stream and will be set in the XML-header.- Throws:
IOException
-
writeDocumentToStream
public static OutputStream writeDocumentToStream(Node node, OutputStream os, Source xslt) throws IOException
Transforms and writes the XML code of the designated node to the designated output stream using theDEFAULT_ENCODING
.- Parameters:
node
- The node to be transformed.os
- The output stream to write the transformed XML code to. The caller is responsible for closing.xslt
- The XSLT style sheet that should be used for the transformer.- Returns:
- The designated output stream.
- Throws:
IOException
- Thrown if an unrecoverable error occurs during the course of the transformation.
-
writeDocumentToStream
public static OutputStream writeDocumentToStream(Node node, OutputStream os, Source xslt, boolean intend) throws IOException
Transforms and writes the XML code of the designated node to the designated output stream using theDEFAULT_ENCODING
.- Parameters:
node
- The node to be transformed.os
- The output stream to write the transformed XML code to. The caller is responsible for closing.xslt
- The XSLT style sheet that should be used for the transformer.intend
- Whether to intend child nodes and text content. Use with care! Text content may contain whitespace and linebreaks afterwards!- Returns:
- The designated output stream.
- Throws:
IOException
- Thrown if an unrecoverable error occurs during the course of the transformation.
-
writeDocumentToFile
public static void writeDocumentToFile(Node node, File file, Schema schema) throws IOException, XMLFormatException
Exports a DOM node to a file, validates the node before the export, if a schema type is provided.- Parameters:
node
- The DOM node to be exported.file
- The target file.schema
- The schema for validation, or null for storing w/o validation.- Throws:
IOException
XMLFormatException
- Thrown, if the validation fails.
-
writeDocumentToFile
public static void writeDocumentToFile(Node node, File file, Schema schema, boolean intend) throws IOException, XMLFormatException
Exports a DOM node to a file using theDEFAULT_ENCODING
, validates the node before the export, if a schema type is provided.- Parameters:
node
- The DOM node to be exported.file
- The target file.schema
- The schema for validation, or null for storing w/o validation.intend
- Whether to intend child nodes and text content. Use with care! Text content may contain whitespace and linebreaks afterwards!- Throws:
IOException
XMLFormatException
- Thrown, if the validation fails.
-
writeDocumentToFile
public static void writeDocumentToFile(Node node, File file, Schema schema, boolean intend, String encoding) throws IOException, XMLFormatException
Exports a DOM node to a file using the designated encoding. Before exporting the node will be validated if a schema type is provided.- Parameters:
node
- The DOM node to be exported.file
- The target file.schema
- The schema for validation, or null for storing w/o validation.intend
- Whether to intend child nodes and text content. Use with care! Text content may contain whitespace and linebreaks afterwards!encoding
- The encoding used for writing the designated node. This will be used for the output stream as well as in the XML-header.- Throws:
IOException
XMLFormatException
- Thrown, if the validation fails.
-
writeDocumentToWriter
public static void writeDocumentToWriter(Node node, Writer out) throws IOException
Writes the node to the designated writer with no indentation and theDEFAULT_ENCODING
.- Parameters:
node
- The DOM node which to write to the designated writer.out
- The writer to which to write the XML for the designated node.- Throws:
IOException
-
writeDocumentToWriter
public static void writeDocumentToWriter(Node node, Writer out, boolean intend) throws IOException
Writes the node to the designated writer withDEFAULT_ENCODING
.- Parameters:
node
- The DOM node which to write to the designated writer.out
- The writer to which to write the XML for the designated node.intend
- Whether to intend child nodes and text content. Use with care! Text content may contain whitespace and linebreaks afterwards!- Throws:
IOException
-
writeDocumentToWriter
public static void writeDocumentToWriter(Node node, Writer out, boolean intend, String encoding) throws IOException
Writes the node to the designated writer with the designated encoding. Please set this encoding in the stream appropriately.- Parameters:
node
- The DOM node which to write to the designated writer.out
- The stream to which to write the designated node to. Set the encoding appropriately!intend
- Whether to intend child nodes and text content. Use with care! Text content may contain whitespace and linebreaks afterwards!encoding
- The encoding used for writing the designated node. This has to conform to the encoding of the designated stream and will be set in the XML-header.- Throws:
IOException
-
getParsedID
public static int getParsedID(Node node)
Strips off the leading character and parses the integer value.- Parameters:
node
- The node whose text content will be parsed.- Returns:
- The integer value of the ID.
-
getParsedID
public static int getParsedID(String nodeValue)
Strips off the leading character and parses the integer value.- Parameters:
nodeValue
- The input string.- Returns:
- The integer value of the ID.
-
hasTagName
public static boolean hasTagName(Node n, String... names)
This method checks, whether the (local) tag name of the given element matches one of the designated names.- Parameters:
n
- The node, whose tag name should be checked.names
- The names, against the tag name should be checked.- Returns:
- Whether the tag name of the given element equals the given name.
-
hasTagName
public static boolean hasTagName(Element e, String... names)
This method checks, whether the (local) tag name of the given element matches one of the designated names.- Parameters:
e
- The element, whose tag name should be checked.names
- The names, against the tag name should be checked.- Returns:
- Whether the tag name of the given element equals the given name.
-
getTagName
protected static String getTagName(Element e)
This method returns the tag name of the given element. In case the tag name is prefixed with a name space, the local name will be returned.- Parameters:
e
- The element, whose tag name should be returned.- Returns:
- The tag name of the given element.
-
nextElement
public static Element nextElement(Node node, String name)
Find the next element that actually contains data, with the given name.
NOTE: If the current node is an element that matches the name it will be returned!- Parameters:
node
- The current node.name
- The name of the next node.- Returns:
- The next node of type ELEMENT_NODE with the given name.
-
nextElement
public static Element nextElement(Node node)
Find the next element that actually contains data.- Parameters:
node
- The current node.- Returns:
- The next node of type ELEMENT_NODE.
-
-