public final class DOMUtils
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static boolean |
createXPathElements(org.w3c.dom.Node node,
java.lang.String xpathStr,
XPathFactory xpf)
Attempts to create the needed elements under the provided node so that the given XPath
will match an element when evaluated against the node.
|
static org.w3c.dom.Node |
getElement(org.w3c.dom.Node node)
Returns the corresponding element.
|
static org.w3c.dom.Document |
getOwnerDocument(org.w3c.dom.Node node)
Gets the owner Document of a Node.
|
static DOMSerializer |
getSerializer()
Gets the shared serializer instance.
|
static DOMSerializer |
getSpecificSerializer()
Gets a specific serializer instance.
|
static DOMSerializer |
getSpecificSerializer(java.lang.String className)
Gets a specific serializer instance, using the specified implementiona
This should be used whenever you need to change the serilaizer settings, or
need to always use a specific implementation regardless of the platform configuration.
|
static java.lang.String |
getText(org.w3c.dom.Node node)
Returns the textual contents of a Node.
|
static javax.xml.transform.Templates |
getXSLTemplates(java.lang.String filename)
Attempts to load a Templates object for the XSL stylesheet at the given filename.
|
static javax.xml.transform.Templates |
getXSLTemplates(java.lang.String filename,
javax.xml.transform.ErrorListener listener)
Attempts to load a Templates object for the XSL stylesheet at the given filename.
|
static javax.xml.transform.Transformer |
getXSLTransformer(java.lang.String filename)
Attempts to load a Transformer object for the XSL stylesheet at the given filename.
|
static javax.xml.transform.Transformer |
getXSLTransformer(java.lang.String filename,
javax.xml.transform.ErrorListener listener)
Attempts to load a Transformer object for the XSL stylesheet at the given filename.
|
static javax.xml.transform.Transformer |
getXSLTransformer(javax.xml.transform.Templates templates)
Attempts to create a Transformer object from a given XSL Templates.
|
static javax.xml.transform.Transformer |
getXSLTransformer(javax.xml.transform.Templates templates,
javax.xml.transform.ErrorListener listener)
Attempts to create a Transformer object from a given XSL Templates, attaching the given
ErrorListener to the returned Transformer for reporting transform errors.
|
static boolean |
hasNonTextChildNodes(org.w3c.dom.Node node)
Checks whether the provided DOM Node contains any child nodes that are not text nodes.
|
static org.w3c.dom.Document |
newDocument()
Returns a new empty DOM Document.
|
static org.w3c.dom.Document |
newDocument(java.io.InputStream is)
Returns a new DOM Document containing the XML read from the supplied InputStream.
|
static org.w3c.dom.Document |
newDocument(java.lang.String xmlString)
Returns a new DOM Document containing the XML in the supplied string.
|
static void |
setText(org.w3c.dom.Node targetNode,
java.lang.String text)
Sets the contents of the provided node to the given text.
|
public static org.w3c.dom.Document getOwnerDocument(org.w3c.dom.Node node)
getOwnerDocument
method in that it does not return null
if the Node argument
is a Document.node
- The node whose owner Document is required.public static org.w3c.dom.Node getElement(org.w3c.dom.Node node)
node
- The node to find an element for.public static java.lang.String getText(org.w3c.dom.Node node)
node
- The node whose child text is required.public static void setText(org.w3c.dom.Node targetNode, java.lang.String text)
targetNode
- target nodetext
- textpublic static boolean hasNonTextChildNodes(org.w3c.dom.Node node)
node
- The DOM node to check the children of.public static org.w3c.dom.Document newDocument()
public static org.w3c.dom.Document newDocument(java.lang.String xmlString)
xmlString
- The String containing the XML content to parse into the new Documentpublic static org.w3c.dom.Document newDocument(java.io.InputStream is)
is
- The InputStream to read the XML content from.public static DOMSerializer getSerializer()
public static DOMSerializer getSpecificSerializer()
public static DOMSerializer getSpecificSerializer(java.lang.String className)
className
- The name of the serializer implementation to use.public static boolean createXPathElements(org.w3c.dom.Node node, java.lang.String xpathStr, XPathFactory xpf)
node
- The DOM node that the XPath should be evalauted from.xpathStr
- The XPath string to try and make match.xpf
- The XPathFactory that has the namespace context etc that should be used.public static javax.xml.transform.Templates getXSLTemplates(java.lang.String filename) throws javax.xml.transform.TransformerFactoryConfigurationError, javax.xml.transform.TransformerConfigurationException
filename
- The absolute path of the XSL file to load.javax.xml.transform.TransformerFactoryConfigurationError
- if error initialising the TransformerFactory or XMLReaderjavax.xml.transform.TransformerConfigurationException
- if error creating Templatespublic static javax.xml.transform.Transformer getXSLTransformer(javax.xml.transform.Templates templates) throws javax.xml.transform.TransformerConfigurationException
templates
- The Templates to create the transformer from.javax.xml.transform.TransformerConfigurationException
- if error creating Transformerpublic static javax.xml.transform.Transformer getXSLTransformer(java.lang.String filename) throws javax.xml.transform.TransformerFactoryConfigurationError, javax.xml.transform.TransformerConfigurationException
filename
- The absolute path of the XSL file to load.javax.xml.transform.TransformerFactoryConfigurationError
- if error initialising the TransformerFactory or XMLReaderjavax.xml.transform.TransformerConfigurationException
- if error creating Templates or Transformerpublic static javax.xml.transform.Templates getXSLTemplates(java.lang.String filename, javax.xml.transform.ErrorListener listener) throws javax.xml.transform.TransformerFactoryConfigurationError, javax.xml.transform.TransformerConfigurationException
filename
- The absolute path of the XSL file to load.listener
- The ErrorListener to use.javax.xml.transform.TransformerFactoryConfigurationError
- if error initialising the TransformerFactory or XMLReaderjavax.xml.transform.TransformerConfigurationException
- if error creating Templatespublic static javax.xml.transform.Transformer getXSLTransformer(javax.xml.transform.Templates templates, javax.xml.transform.ErrorListener listener) throws javax.xml.transform.TransformerConfigurationException
templates
- The Templates to create the transformer from.listener
- The ErrorListener to use.javax.xml.transform.TransformerConfigurationException
- if error creating Transformerpublic static javax.xml.transform.Transformer getXSLTransformer(java.lang.String filename, javax.xml.transform.ErrorListener listener) throws javax.xml.transform.TransformerFactoryConfigurationError, javax.xml.transform.TransformerConfigurationException
filename
- The absolute path of the XSL file to load.listener
- The ErrorListener to use.javax.xml.transform.TransformerFactoryConfigurationError
- if error initialising the TransformerFactory or XMLReaderjavax.xml.transform.TransformerConfigurationException
- if error creating Templates or TransformerCopyright © 2007 Hyfinity Ltd. All Rights Reserved.