public class XMLHelperTools
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
ENCODING
The encoding that should be used for writing xml files.
|
protected static java.util.logging.Logger |
logger
The logger instance of this class.
|
| Constructor and Description |
|---|
XMLHelperTools() |
| Modifier and Type | Method and Description |
|---|---|
static org.w3c.dom.Document |
createDocument()
Initialises the document object which will be used for constructing
elements.
|
static byte[] |
getByteArrayForDocument(org.w3c.dom.Node node)
Returns a byte array containing the XML code for the given node.
|
static byte[] |
getByteArrayForDocument(org.w3c.dom.Node node,
boolean intend)
Returns a byte array containing the XML code for the given node.
|
static org.w3c.dom.Document |
getDocumentFromFile(java.io.File file,
javax.xml.validation.Schema schema,
org.xml.sax.ErrorHandler errorHandler)
Read a Document from a stream.
|
static org.w3c.dom.Document |
getDocumentFromStream(java.io.InputStream inputStream)
Parse a Stream and converts it to a Document
|
static org.w3c.dom.Document |
getDocumentFromStream(java.io.InputStream inputStream,
javax.xml.validation.Schema schema,
org.xml.sax.ErrorHandler errorHandler,
boolean nsAware)
Read a Document from a file.
|
static org.w3c.dom.Document |
getDocumentFromString(java.lang.String string,
javax.xml.validation.Schema schema)
Parse a string and converts it to a Document.
|
static org.w3c.dom.Element |
getElement(org.w3c.dom.Node node)
Finds an DOM Element for a given Node.
|
static java.io.InputStream |
getInputStreamForDocument(org.w3c.dom.Node node)
Returns an input stream containing the XML code of the given node.
|
static java.io.InputStream |
getInputStreamForDocument(org.w3c.dom.Node node,
boolean intend)
Returns an input stream containing the XML code of the given node.
|
static java.io.ByteArrayOutputStream |
getOutputStreamForDocument(org.w3c.dom.Node node)
Returns an output stream containing the XML code of the given node.
|
static java.io.ByteArrayOutputStream |
getOutputStreamForDocument(org.w3c.dom.Node node,
boolean intend)
Returns an output stream containing the XML code of the given node.
|
static java.io.ByteArrayOutputStream |
getOutputStreamForDocument(org.w3c.dom.Node node,
javax.xml.transform.Source xslt)
Returns an output stream containing the XML code of the given node.
|
static java.io.ByteArrayOutputStream |
getOutputStreamForDocument(org.w3c.dom.Node node,
javax.xml.transform.Source xslt,
boolean intend)
Returns an output stream containing the XML code of the given node.
|
static int |
getParsedID(org.w3c.dom.Node node)
Strips off the leading character and parses the integer value.
|
static int |
getParsedID(java.lang.String nodeValue)
Strips off the leading character and parses the integer value.
|
protected static java.lang.String |
getTagName(org.w3c.dom.Element e)
This method returns the tag name of the given element.
|
static java.lang.String |
getXMLStringForDocument(org.w3c.dom.Node node)
Returns the XML code of a given node as string.
|
static java.lang.String |
getXMLStringForDocument(org.w3c.dom.Node node,
boolean intend)
Returns the XML code of a given node as string.
|
static java.lang.String |
getXMLStringForInputStream(java.io.InputStream is)
Returns the xml code of a given input stream as string.
|
static boolean |
hasTagName(org.w3c.dom.Element e,
java.lang.String name)
This method checks, whether the (local) tag name of the given element
matches the given name.
|
static boolean |
hasTagName(org.w3c.dom.Node n,
java.lang.String name)
This method checks, whether the (local) tag name of the given element
matches the given name.
|
static boolean |
isStreamValid(java.io.InputStream is,
javax.xml.validation.Schema schema)
Returns whether the given
Node is valid against the given Schema. |
static boolean |
isValid(org.w3c.dom.Node node,
javax.xml.validation.Schema schema)
Returns whether the given
node is valid against the given Schema. |
static org.w3c.dom.Element |
nextElement(org.w3c.dom.Node node)
Find the next element that actually contains data.
|
static org.w3c.dom.Element |
nextElement(org.w3c.dom.Node node,
java.lang.String name)
Find the next element that actually contains data, with the given name.
|
static java.lang.String |
replaceWithXMLEntities(java.lang.String string)
Replaces all occurrences of special characters that may not appear directly
in XML (<, >, &, ' and ") with their corresponding XML entities.
|
static void |
validateAndPrintDoc(org.w3c.dom.Node node,
javax.xml.validation.Schema schema)
Checks, if a node uses a valid schema.
|
static void |
validateDocument(org.w3c.dom.Node node,
javax.xml.validation.Schema schema)
Checks, if a node uses a valid schema.
|
static void |
validateStream(java.io.InputStream is,
javax.xml.validation.Schema schema)
Checks, if a node uses a valid schema.
|
static void |
writeDocumentToFile(org.w3c.dom.Node node,
java.io.File file,
javax.xml.validation.Schema schema)
Exports a DOM node to a file, validates the node before the export, if a schema type is
provided.
|
static void |
writeDocumentToFile(org.w3c.dom.Node node,
java.io.File file,
javax.xml.validation.Schema schema,
boolean intend)
Exports a DOM node to a file, validates the node before the export, if a schema type is
provided.
|
static void |
writeDocumentToStream(org.w3c.dom.Node node,
java.io.OutputStream out)
Writes the node to the given output stream.
|
static void |
writeDocumentToStream(org.w3c.dom.Node node,
java.io.OutputStream out,
boolean intend)
Writes the node to the given output stream.
|
public static final java.lang.String ENCODING
for more possible encodings,
Constant Field Valuesprotected static final java.util.logging.Logger logger
public static boolean isValid(org.w3c.dom.Node node,
javax.xml.validation.Schema schema)
node is valid against the given Schema.node - The node to be validated.schema - The schema to validate the node against.Node is valid against the given Schema.public static boolean isStreamValid(java.io.InputStream is,
javax.xml.validation.Schema schema)
Node is valid against the given Schema.is - The input stream containing the XML data to be validated.schema - The schema to validate the node against.Node is valid against the given Schema.public static void validateAndPrintDoc(org.w3c.dom.Node node,
javax.xml.validation.Schema schema)
throws XMLFormatException,
java.io.IOException
System.out.node - The node, that wants to be checked.schema - The Schema, the node has to use, to be valid.XMLFormatException - when the validation fails.java.io.IOException - when conversion to string representation fails.public static void validateDocument(org.w3c.dom.Node node,
javax.xml.validation.Schema schema)
throws XMLFormatException
node - The node, that wants to be checked.schema - The Schema, the node has to use, to be valid.XMLFormatException - when the validation failspublic static void validateStream(java.io.InputStream is,
javax.xml.validation.Schema schema)
throws XMLFormatException
is - The input stream containing the XML data.schema - The Schema, the node has to use, to be valid.XMLFormatException - when the validation failspublic static java.lang.String replaceWithXMLEntities(java.lang.String string)
string - the string to be convertedpublic static org.w3c.dom.Document getDocumentFromString(java.lang.String string,
javax.xml.validation.Schema schema)
throws XMLFormatException,
java.io.IOException
string - The string, that shall be converted.schema - The XML Schema to validate the document against or
null to omit validation.XMLFormatException - if the document is not well-formedjava.io.IOException - if error occurs while reading from the filepublic static org.w3c.dom.Document getDocumentFromFile(java.io.File file,
javax.xml.validation.Schema schema,
org.xml.sax.ErrorHandler errorHandler)
throws XMLFormatException,
java.io.FileNotFoundException,
java.io.IOException
file - schema - The XML Schema to validate the document against or
null to omit validationerrorHandler - The optional error handler that will be used for the
document builderXMLFormatException - if the document is not well-formed or doesn't
conform to the given Schemajava.io.FileNotFoundException - if the file does not exist or can't be openedjava.io.IOException - if error occurs while reading from the filepublic static org.w3c.dom.Document getDocumentFromStream(java.io.InputStream inputStream)
throws XMLFormatException,
java.io.IOException
inputStream - The stream that shall be convertedXMLFormatException - if the document is not well-formedjava.io.IOException - if error occurs while reading from the streampublic static org.w3c.dom.Document getDocumentFromStream(java.io.InputStream inputStream,
javax.xml.validation.Schema schema,
org.xml.sax.ErrorHandler errorHandler,
boolean nsAware)
throws XMLFormatException,
java.io.IOException
inputStream - The InputStream which should be parsed or null.schema - The XML Schema to validate the document against or
null to omit validation.errorHandler - The optional error handler that will be used for the
document builder.nsAware - Whether the input stream should be parsed namespace aware.XMLFormatException - if the document is not well-formed or doesn't
conform to the given Schemajava.io.IOException - if error occurs while reading from the streampublic static org.w3c.dom.Document createDocument()
public static java.lang.String getXMLStringForDocument(org.w3c.dom.Node node)
throws java.io.IOException
node - The node to be transformedjava.io.IOException - Thrown if an unrecoverable error occurs during the course of the
transformationpublic static java.lang.String getXMLStringForDocument(org.w3c.dom.Node node,
boolean intend)
throws java.io.IOException
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!java.io.IOException - Thrown if an unrecoverable error occurs during the course of the
transformationpublic static java.lang.String getXMLStringForInputStream(java.io.InputStream is)
throws java.io.IOException
is - The input stream which should be transformed.java.io.IOException - Thrown if an unrecoverable error occurs during the
course of the transformationpublic static java.io.InputStream getInputStreamForDocument(org.w3c.dom.Node node)
throws java.io.IOException
node - The node to be transformedjava.io.IOException - Thrown if an unrecoverable error occurs during the course of the
transformation.public static java.io.InputStream getInputStreamForDocument(org.w3c.dom.Node node,
boolean intend)
throws java.io.IOException
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!java.io.IOException - Thrown if an unrecoverable error occurs during the course of the
transformation.public static byte[] getByteArrayForDocument(org.w3c.dom.Node node)
throws java.io.IOException
node - The node to be transformed.java.io.IOExceptionpublic static byte[] getByteArrayForDocument(org.w3c.dom.Node node,
boolean intend)
throws java.io.IOException
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!java.io.IOExceptionpublic static java.io.ByteArrayOutputStream getOutputStreamForDocument(org.w3c.dom.Node node)
throws java.io.IOException
node - The node to be transformed.java.io.IOException - Thrown if an unrecoverable error occurs during the course of the
transformation.public static java.io.ByteArrayOutputStream getOutputStreamForDocument(org.w3c.dom.Node node,
boolean intend)
throws java.io.IOException
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!java.io.IOException - Thrown if an unrecoverable error occurs during the course of the
transformation.public static java.io.ByteArrayOutputStream getOutputStreamForDocument(org.w3c.dom.Node node,
javax.xml.transform.Source xslt)
throws java.io.IOException
node - The node to be transformed.xslt - The XSLT style sheet that should be used for the transformer.java.io.IOException - Thrown if an unrecoverable error occurs during the course of the
transformation.public static java.io.ByteArrayOutputStream getOutputStreamForDocument(org.w3c.dom.Node node,
javax.xml.transform.Source xslt,
boolean intend)
throws java.io.IOException
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!java.io.IOException - Thrown if an unrecoverable error occurs during the course of the
transformation.public static void writeDocumentToStream(org.w3c.dom.Node node,
java.io.OutputStream out)
throws java.io.IOException
node - out - java.io.IOExceptionpublic static void writeDocumentToStream(org.w3c.dom.Node node,
java.io.OutputStream out,
boolean intend)
throws java.io.IOException
node - out - intend - Whether to intend child nodes and text content. Use with care! Text content may
contain whitespace and linebreaks afterwards!java.io.IOExceptionpublic static void writeDocumentToFile(org.w3c.dom.Node node,
java.io.File file,
javax.xml.validation.Schema schema)
throws java.io.IOException,
XMLFormatException
node - The DOM node to be exported.file - The target file.schema - The schema for validation, or null for storing w/o validation.java.io.IOExceptionXMLFormatException - Thrown, if the validation fails.public static void writeDocumentToFile(org.w3c.dom.Node node,
java.io.File file,
javax.xml.validation.Schema schema,
boolean intend)
throws java.io.IOException,
XMLFormatException
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!java.io.IOExceptionXMLFormatException - Thrown, if the validation fails.public static int getParsedID(org.w3c.dom.Node node)
node - The node whose text content will be parsed.public static int getParsedID(java.lang.String nodeValue)
nodeValue - The input string.public static boolean hasTagName(org.w3c.dom.Node n,
java.lang.String name)
n - The node, whose tag name should be checked.name - The name, against the tag name should be checked.public static boolean hasTagName(org.w3c.dom.Element e,
java.lang.String name)
e - The element, whose tag name should be checked.name - The name, against the tag name should be checked.protected static java.lang.String getTagName(org.w3c.dom.Element e)
e - The element, whose tag name should be returned.public static org.w3c.dom.Element nextElement(org.w3c.dom.Node node,
java.lang.String name)
node - The current node.name - The name of the next node.public static org.w3c.dom.Element nextElement(org.w3c.dom.Node node)
node - The current node.public static org.w3c.dom.Element getElement(org.w3c.dom.Node node)
node - the DOM object