deegree 2.5 (2011/06/29 09:44 build-8-official)

org.deegree.framework.xml
Class XMLTools

java.lang.Object
  extended by org.deegree.framework.xml.XMLTools

public final class XMLTools
extends java.lang.Object

XML Tools based on JAXP 1.1 for parsing documents and retrieving node values/node attributes. Furthermore this utility class provides node retrieval based on XPath expressions.

Version:
$Revision: 27386 $, $Date: 2010-10-19 13:13:49 +0200 (Di, 19 Okt 2010) $
Author:
Markus Schneider , Andreas Poth , last edited by: $Author: apoth $

Method Summary
static org.w3c.dom.Element appendElement(org.w3c.dom.Element element, java.net.URI namespaceURI, java.lang.String name)
          Creates a new Element node from the given parameters and appends it to the also specified Element.
static org.w3c.dom.Element appendElement(org.w3c.dom.Element element, java.net.URI namespaceURI, java.lang.String name, java.lang.String nodeValue)
          Creates a new Element node from the given parameters and appends it to the also specified Element.
static void appendNSBinding(org.w3c.dom.Element element, java.lang.String prefix, java.net.URI namespace)
          Appends a namespace binding for the specified element that binds the given prefix to the given namespace using a special attribute: xmlns:prefix=namespace
static void appendNSBindings(org.w3c.dom.Element element, NamespaceContext nsContext)
          Appends the given namespace bindings to the specified element.
static void appendNSDefaultBinding(org.w3c.dom.Element element, java.net.URI namespace)
          Appends the default namespace binding for the specified element.
static void checkValue(java.lang.String value, java.lang.String[] validValues)
           
static org.w3c.dom.Node copyNode(org.w3c.dom.Node source, org.w3c.dom.Node dest)
          Copies one node to another node.
static org.w3c.dom.Document create()
          Create a new and empty DOM document.
static java.lang.String escape(org.w3c.dom.Node root)
          This method escapes Strings for XML by creating a DOM document, setting the text in an attribute, exporting it to text and extracting the escaped string.
static java.lang.String escape(java.lang.String str)
          This method escapes Strings for XML by creating a DOM document, setting the text in an attribute, exporting it to text and extracting the escaped string.
static java.lang.String getAsPrettyString(java.lang.String xml)
           
static java.lang.String getAttrValue(org.w3c.dom.Node node, java.lang.String attrName)
          Deprecated. use
static java.lang.String getAttrValue(org.w3c.dom.Node node, java.net.URI namespaceURI, java.lang.String attrName, java.lang.String defaultVal)
          Returns the specified attribute value of the given node.
static org.w3c.dom.Element getChildElement(org.w3c.dom.Node node, java.lang.String name)
          Deprecated. Returns the first child element of the submitted node that matches the given local name.
static org.w3c.dom.Element getChildElement(java.lang.String name, java.net.URI namespaceURI, org.w3c.dom.Node node)
          Deprecated.  
static ElementList getChildElements(org.w3c.dom.Node node)
          Returns all child elements of the given node.
static ElementList getChildElements(java.lang.String name, java.net.URI namespaceURI, org.w3c.dom.Node node)
          Deprecated.  
static javax.xml.parsers.DocumentBuilder getDocumentBuilder()
          Create a new document builder with: namespace awareness = true whitespace ignoring = false validating = false expandind entity references = false
static org.w3c.dom.Element getElement(org.w3c.dom.Node contextNode, java.lang.String xpath, NamespaceContext nsContext)
           
static java.util.List<org.w3c.dom.Element> getElements(org.w3c.dom.Node contextNode, java.lang.String xpath, NamespaceContext nsContext)
           
static org.w3c.dom.Element getFirstChildElement(org.w3c.dom.Node node)
          Returns the first child element of the submitted node.
static java.net.URI getNamespaceForPrefix(java.lang.String prefix, org.w3c.dom.Node node)
          Returns the namespace URI that is bound to a given prefix at a certain node in the DOM tree.
static org.w3c.dom.Node getNode(org.w3c.dom.Node contextNode, java.lang.String xPathQuery, NamespaceContext nsContext)
           
static boolean getNodeAsBoolean(org.w3c.dom.Node contextNode, java.lang.String xPathQuery, NamespaceContext nsContext, boolean defaultValue)
           
static double getNodeAsDouble(org.w3c.dom.Node contextNode, java.lang.String xPathQuery, NamespaceContext nsContext, double defaultValue)
           
static int getNodeAsInt(org.w3c.dom.Node contextNode, java.lang.String xPathQuery, NamespaceContext nsContext, int defaultValue)
           
static QualifiedName getNodeAsQualifiedName(org.w3c.dom.Node contextNode, java.lang.String xPathQuery, NamespaceContext nsContext, QualifiedName defaultValue)
           
static java.lang.String getNodeAsString(org.w3c.dom.Node contextNode, java.lang.String xPathQuery, NamespaceContext nsContext, java.lang.String defaultValue)
           
static java.net.URI getNodeAsURI(org.w3c.dom.Node contextNode, java.lang.String xPathQuery, NamespaceContext nsContext, java.net.URI defaultValue)
           
static java.util.List<org.w3c.dom.Node> getNodes(org.w3c.dom.Node contextNode, java.lang.String xPathQuery, NamespaceContext nsContext)
          returns a list of nodes matching the passed XPath
static QualifiedName[] getNodesAsQualifiedNames(org.w3c.dom.Node contextNode, java.lang.String xPathQuery, NamespaceContext nsContext)
           
static java.util.List<java.lang.String> getNodesAsStringList(org.w3c.dom.Node contextNode, java.lang.String xPathQuery, NamespaceContext nsContext)
           
static java.lang.String[] getNodesAsStrings(org.w3c.dom.Node contextNode, java.lang.String xPathQuery, NamespaceContext nsContext)
           
static java.net.URI[] getNodesAsURIs(org.w3c.dom.Node contextNode, java.lang.String xPathQuery, NamespaceContext nsContext)
           
static QualifiedName getQualifiedNameValue(org.w3c.dom.Node node)
          Parses the value of the submitted Node as a QualifiedName.
static java.lang.String getRequiredAttrValue(java.lang.String name, java.net.URI namespaceURI, org.w3c.dom.Node node)
          Returns the value of the specified node attribute.
static org.w3c.dom.Element getRequiredChildElement(java.lang.String name, java.net.URI namespaceURI, org.w3c.dom.Node node)
          Deprecated.  
static org.w3c.dom.Element getRequiredElement(org.w3c.dom.Node contextNode, java.lang.String xpath, NamespaceContext nsContext)
           
static java.util.List<org.w3c.dom.Element> getRequiredElements(org.w3c.dom.Node contextNode, java.lang.String xpath, NamespaceContext nsContext)
           
static org.w3c.dom.Node getRequiredNode(org.w3c.dom.Node contextNode, java.lang.String xPathQuery, NamespaceContext nsContext)
           
static boolean getRequiredNodeAsBoolean(org.w3c.dom.Node contextNode, java.lang.String xPathQuery, NamespaceContext nsContext)
           
static double getRequiredNodeAsDouble(org.w3c.dom.Node contextNode, java.lang.String xPathQuery, NamespaceContext nsContext)
           
static double[] getRequiredNodeAsDoubles(org.w3c.dom.Node contextNode, java.lang.String xPathQuery, NamespaceContext nsContext, java.lang.String regex)
          Returns the parts of the targeted node value which are separated by the specified regex.
static int getRequiredNodeAsInt(org.w3c.dom.Node contextNode, java.lang.String xPathQuery, NamespaceContext nsContext)
           
static QualifiedName getRequiredNodeAsQualifiedName(org.w3c.dom.Node contextNode, java.lang.String xPathQuery, NamespaceContext nsContext)
           
static java.lang.String getRequiredNodeAsString(org.w3c.dom.Node contextNode, java.lang.String xPathQuery, NamespaceContext nsContext)
           
static java.lang.String getRequiredNodeAsString(org.w3c.dom.Node contextNode, java.lang.String xPathQuery, NamespaceContext nsContext, java.lang.String[] validValues)
           
static java.lang.String[] getRequiredNodeAsStrings(org.w3c.dom.Node contextNode, java.lang.String xPathQuery, NamespaceContext nsContext, java.lang.String regex)
          Returns the parts of the targeted node value which are separated by the specified regex.
static java.net.URI getRequiredNodeAsURI(org.w3c.dom.Node contextNode, java.lang.String xPathQuery, NamespaceContext nsContext)
           
static java.util.List<org.w3c.dom.Node> getRequiredNodes(org.w3c.dom.Node contextNode, java.lang.String xPathQuery, NamespaceContext nsContext)
           
static QualifiedName[] getRequiredNodesAsQualifiedNames(org.w3c.dom.Node contextNode, java.lang.String xPathQuery, NamespaceContext nsContext)
           
static java.lang.String[] getRequiredNodesAsStrings(org.w3c.dom.Node contextNode, java.lang.String xPathQuery, NamespaceContext nsContext)
          Returns the content of the nodes matching the XPathQuery as a String array.
static java.lang.String getRequiredStringValue(java.lang.String name, java.net.URI namespace, org.w3c.dom.Node node)
          Returns the text contained in the specified child element of the given element.
static org.w3c.dom.Element getStringFragmentAsElement(java.lang.String fragment)
          Converts an XML fragment string into a DOM node.
static java.lang.String getStringValue(org.w3c.dom.Node node)
          Returns the text contained in the specified element.
static java.lang.String getStringValue(java.lang.String name, java.net.URI namespace, org.w3c.dom.Node node, java.lang.String defaultValue)
          Returns the text contained in the specified child element of the given element.
static org.w3c.dom.Element importStringFragment(java.lang.String fragment, org.w3c.dom.Document doc)
          Works like getStringFragmentAsElement(java.lang.String), but does not throw exceptions and immediately imports the node into another document.
static org.w3c.dom.Node insertNodeInto(org.w3c.dom.Node source, org.w3c.dom.Node dest)
          Appends a node to an element.
static org.w3c.dom.Document parse(java.io.InputStream is)
          Deprecated.  
static org.w3c.dom.Document parse(java.io.Reader reader)
          Parses an XML document and returns a DOM object.
static void setNodeValue(org.w3c.dom.Element target, java.lang.String nodeValue)
          sets the value of an existing node
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getNode

public static org.w3c.dom.Node getNode(org.w3c.dom.Node contextNode,
                                       java.lang.String xPathQuery,
                                       NamespaceContext nsContext)
                                throws XMLParsingException
Parameters:
contextNode -
xPathQuery -
nsContext -
Returns:
Node
Throws:
XMLParsingException

getElement

public static org.w3c.dom.Element getElement(org.w3c.dom.Node contextNode,
                                             java.lang.String xpath,
                                             NamespaceContext nsContext)
                                      throws XMLParsingException
Parameters:
contextNode -
xpath -
nsContext -
Returns:
the element
Throws:
XMLParsingException
java.lang.ClassCastException - if the node was not an element

getNodeAsString

public static java.lang.String getNodeAsString(org.w3c.dom.Node contextNode,
                                               java.lang.String xPathQuery,
                                               NamespaceContext nsContext,
                                               java.lang.String defaultValue)
                                        throws XMLParsingException
Parameters:
contextNode -
xPathQuery -
nsContext -
defaultValue -
Returns:
the node's String value
Throws:
XMLParsingException

getNodeAsBoolean

public static boolean getNodeAsBoolean(org.w3c.dom.Node contextNode,
                                       java.lang.String xPathQuery,
                                       NamespaceContext nsContext,
                                       boolean defaultValue)
                                throws XMLParsingException
Parameters:
contextNode -
xPathQuery -
nsContext -
defaultValue -
Returns:
the node's boolean value
Throws:
XMLParsingException

getNodeAsInt

public static int getNodeAsInt(org.w3c.dom.Node contextNode,
                               java.lang.String xPathQuery,
                               NamespaceContext nsContext,
                               int defaultValue)
                        throws XMLParsingException
Parameters:
contextNode -
xPathQuery -
nsContext -
defaultValue -
Returns:
the node's integer value
Throws:
XMLParsingException

getNodeAsDouble

public static double getNodeAsDouble(org.w3c.dom.Node contextNode,
                                     java.lang.String xPathQuery,
                                     NamespaceContext nsContext,
                                     double defaultValue)
                              throws XMLParsingException
Parameters:
contextNode -
xPathQuery -
nsContext -
defaultValue -
Returns:
the node's double value
Throws:
XMLParsingException

getNodeAsURI

public static java.net.URI getNodeAsURI(org.w3c.dom.Node contextNode,
                                        java.lang.String xPathQuery,
                                        NamespaceContext nsContext,
                                        java.net.URI defaultValue)
                                 throws XMLParsingException
Parameters:
contextNode -
xPathQuery -
nsContext -
defaultValue -
Returns:
the node as URI
Throws:
XMLParsingException

getNodeAsQualifiedName

public static QualifiedName getNodeAsQualifiedName(org.w3c.dom.Node contextNode,
                                                   java.lang.String xPathQuery,
                                                   NamespaceContext nsContext,
                                                   QualifiedName defaultValue)
                                            throws XMLParsingException
Parameters:
contextNode -
xPathQuery -
nsContext -
defaultValue -
Returns:
the node as qualified name
Throws:
XMLParsingException

getNodes

public static java.util.List<org.w3c.dom.Node> getNodes(org.w3c.dom.Node contextNode,
                                                        java.lang.String xPathQuery,
                                                        NamespaceContext nsContext)
                                                 throws XMLParsingException
returns a list of nodes matching the passed XPath

Parameters:
contextNode -
xPathQuery -
nsContext -
Returns:
a list of nodes matching the passed XPath
Throws:
XMLParsingException

getNodesAsStrings

public static java.lang.String[] getNodesAsStrings(org.w3c.dom.Node contextNode,
                                                   java.lang.String xPathQuery,
                                                   NamespaceContext nsContext)
                                            throws XMLParsingException
Parameters:
contextNode -
xPathQuery -
nsContext -
Returns:
the list of nodes as strings
Throws:
XMLParsingException

getNodesAsStringList

public static java.util.List<java.lang.String> getNodesAsStringList(org.w3c.dom.Node contextNode,
                                                                    java.lang.String xPathQuery,
                                                                    NamespaceContext nsContext)
                                                             throws XMLParsingException
Parameters:
contextNode - to get the strings from
xPathQuery - finding the nodes
nsContext - to find the namespaces from.
Returns:
the list of nodes as strings or an empty list, never null
Throws:
XMLParsingException

getNodesAsURIs

public static java.net.URI[] getNodesAsURIs(org.w3c.dom.Node contextNode,
                                            java.lang.String xPathQuery,
                                            NamespaceContext nsContext)
                                     throws XMLParsingException
Parameters:
contextNode -
xPathQuery -
nsContext -
Returns:
the nodes as URIs
Throws:
XMLParsingException

getNodesAsQualifiedNames

public static QualifiedName[] getNodesAsQualifiedNames(org.w3c.dom.Node contextNode,
                                                       java.lang.String xPathQuery,
                                                       NamespaceContext nsContext)
                                                throws XMLParsingException
Parameters:
contextNode -
xPathQuery -
nsContext -
Returns:
the nodes as qualified names
Throws:
XMLParsingException

getRequiredNode

public static org.w3c.dom.Node getRequiredNode(org.w3c.dom.Node contextNode,
                                               java.lang.String xPathQuery,
                                               NamespaceContext nsContext)
                                        throws XMLParsingException
Parameters:
contextNode -
xPathQuery -
nsContext -
Returns:
the node
Throws:
XMLParsingException

getRequiredElement

public static org.w3c.dom.Element getRequiredElement(org.w3c.dom.Node contextNode,
                                                     java.lang.String xpath,
                                                     NamespaceContext nsContext)
                                              throws XMLParsingException
Parameters:
contextNode -
xpath -
nsContext -
Returns:
the element
Throws:
XMLParsingException
java.lang.ClassCastException - if the node was not an element

getRequiredNodeAsString

public static java.lang.String getRequiredNodeAsString(org.w3c.dom.Node contextNode,
                                                       java.lang.String xPathQuery,
                                                       NamespaceContext nsContext)
                                                throws XMLParsingException
Parameters:
contextNode -
xPathQuery -
nsContext -
Returns:
the node as string
Throws:
XMLParsingException

getRequiredNodeAsString

public static java.lang.String getRequiredNodeAsString(org.w3c.dom.Node contextNode,
                                                       java.lang.String xPathQuery,
                                                       NamespaceContext nsContext,
                                                       java.lang.String[] validValues)
                                                throws XMLParsingException
Parameters:
contextNode - the parent of the requested node
xPathQuery - the node to get out of the dom
nsContext - context of the node
validValues - the values that are valid for the required node
Returns:
one of the String valid String values
Throws:
XMLParsingException - if no Node was found or the text of the Node was not present in the given valid strings.

getRequiredNodeAsStrings

public static java.lang.String[] getRequiredNodeAsStrings(org.w3c.dom.Node contextNode,
                                                          java.lang.String xPathQuery,
                                                          NamespaceContext nsContext,
                                                          java.lang.String regex)
                                                   throws XMLParsingException
Returns the parts of the targeted node value which are separated by the specified regex.

Parameters:
contextNode -
xPathQuery -
nsContext -
regex -
Returns:
the parts of the targeted node value which are separated by the specified regex.
Throws:
XMLParsingException

getRequiredNodeAsBoolean

public static boolean getRequiredNodeAsBoolean(org.w3c.dom.Node contextNode,
                                               java.lang.String xPathQuery,
                                               NamespaceContext nsContext)
                                        throws XMLParsingException
Parameters:
contextNode -
xPathQuery -
nsContext -
Returns:
the node as boolean
Throws:
XMLParsingException

getRequiredNodeAsInt

public static int getRequiredNodeAsInt(org.w3c.dom.Node contextNode,
                                       java.lang.String xPathQuery,
                                       NamespaceContext nsContext)
                                throws XMLParsingException
Parameters:
contextNode -
xPathQuery -
nsContext -
Returns:
the node as integer
Throws:
XMLParsingException

getRequiredNodeAsDouble

public static double getRequiredNodeAsDouble(org.w3c.dom.Node contextNode,
                                             java.lang.String xPathQuery,
                                             NamespaceContext nsContext)
                                      throws XMLParsingException
Parameters:
contextNode -
xPathQuery -
nsContext -
Returns:
the node as double
Throws:
XMLParsingException

getRequiredNodeAsDoubles

public static double[] getRequiredNodeAsDoubles(org.w3c.dom.Node contextNode,
                                                java.lang.String xPathQuery,
                                                NamespaceContext nsContext,
                                                java.lang.String regex)
                                         throws XMLParsingException
Returns the parts of the targeted node value which are separated by the specified regex. The string parts are converted to doubles.

Parameters:
contextNode -
xPathQuery -
nsContext -
regex -
Returns:
the parts of the targeted node value which are separated by the specified regex.
Throws:
XMLParsingException

getRequiredNodeAsURI

public static java.net.URI getRequiredNodeAsURI(org.w3c.dom.Node contextNode,
                                                java.lang.String xPathQuery,
                                                NamespaceContext nsContext)
                                         throws XMLParsingException
Parameters:
contextNode -
xPathQuery -
nsContext -
Returns:
the node as URI
Throws:
XMLParsingException

getRequiredNodeAsQualifiedName

public static QualifiedName getRequiredNodeAsQualifiedName(org.w3c.dom.Node contextNode,
                                                           java.lang.String xPathQuery,
                                                           NamespaceContext nsContext)
                                                    throws XMLParsingException
Parameters:
contextNode -
xPathQuery -
nsContext -
Returns:
the node as qualified name
Throws:
XMLParsingException

getRequiredNodes

public static java.util.List<org.w3c.dom.Node> getRequiredNodes(org.w3c.dom.Node contextNode,
                                                                java.lang.String xPathQuery,
                                                                NamespaceContext nsContext)
                                                         throws XMLParsingException
Parameters:
contextNode -
xPathQuery -
nsContext -
Returns:
the nodes
Throws:
XMLParsingException

getRequiredElements

public static java.util.List<org.w3c.dom.Element> getRequiredElements(org.w3c.dom.Node contextNode,
                                                                      java.lang.String xpath,
                                                                      NamespaceContext nsContext)
                                                               throws XMLParsingException
Parameters:
contextNode -
xpath -
nsContext -
Returns:
a list of Elements
Throws:
XMLParsingException
java.lang.ClassCastException - if the resulting nodes of the xpath are not elements

getElements

public static java.util.List<org.w3c.dom.Element> getElements(org.w3c.dom.Node contextNode,
                                                              java.lang.String xpath,
                                                              NamespaceContext nsContext)
                                                       throws XMLParsingException
Parameters:
contextNode -
xpath -
nsContext -
Returns:
a list of Elements
Throws:
XMLParsingException
java.lang.ClassCastException - if the resulting nodes of the xpath are not elements

getRequiredNodesAsStrings

public static java.lang.String[] getRequiredNodesAsStrings(org.w3c.dom.Node contextNode,
                                                           java.lang.String xPathQuery,
                                                           NamespaceContext nsContext)
                                                    throws XMLParsingException
Returns the content of the nodes matching the XPathQuery as a String array. At least one node must match the query otherwise an exception will be thrown.

Parameters:
contextNode -
xPathQuery -
nsContext -
Returns:
the content of the nodes matching the XPathQuery as a String array.
Throws:
XMLParsingException

getRequiredNodesAsQualifiedNames

public static QualifiedName[] getRequiredNodesAsQualifiedNames(org.w3c.dom.Node contextNode,
                                                               java.lang.String xPathQuery,
                                                               NamespaceContext nsContext)
                                                        throws XMLParsingException
Parameters:
contextNode -
xPathQuery -
nsContext -
Returns:
the qualified names
Throws:
XMLParsingException

checkValue

public static void checkValue(java.lang.String value,
                              java.lang.String[] validValues)
                       throws XMLParsingException
Parameters:
value -
validValues -
Throws:
XMLParsingException

appendElement

public static org.w3c.dom.Element appendElement(org.w3c.dom.Element element,
                                                java.net.URI namespaceURI,
                                                java.lang.String name)
Creates a new Element node from the given parameters and appends it to the also specified Element.

Parameters:
element - Element that the new Element is appended to
namespaceURI - use null for default namespace
name - qualified name
Returns:
the appended Element node

appendNSBinding

public static void appendNSBinding(org.w3c.dom.Element element,
                                   java.lang.String prefix,
                                   java.net.URI namespace)
Appends a namespace binding for the specified element that binds the given prefix to the given namespace using a special attribute: xmlns:prefix=namespace

Parameters:
element -
prefix -
namespace -

appendNSDefaultBinding

public static void appendNSDefaultBinding(org.w3c.dom.Element element,
                                          java.net.URI namespace)
Appends the default namespace binding for the specified element.

Parameters:
element -
namespace -

appendNSBindings

public static void appendNSBindings(org.w3c.dom.Element element,
                                    NamespaceContext nsContext)
Appends the given namespace bindings to the specified element.

NOTE: The prebound prefix "xml" is skipped.

Parameters:
element -
nsContext -

getStringValue

public static java.lang.String getStringValue(org.w3c.dom.Node node)
Returns the text contained in the specified element.

Parameters:
node - current element
Returns:
the textual contents of the element

getStringValue

public static java.lang.String getStringValue(java.lang.String name,
                                              java.net.URI namespace,
                                              org.w3c.dom.Node node,
                                              java.lang.String defaultValue)
Returns the text contained in the specified child element of the given element.

Parameters:
name - name of the child element
namespace - namespace of the child element
node - current element
defaultValue - default value if element is missing
Returns:
the textual contents of the element or the given default value, if missing

getRequiredStringValue

public static java.lang.String getRequiredStringValue(java.lang.String name,
                                                      java.net.URI namespace,
                                                      org.w3c.dom.Node node)
                                               throws XMLParsingException
Returns the text contained in the specified child element of the given element.

Parameters:
name - name of the child element
namespace - namespace of the child element
node - current element
Returns:
the textual contents of the element or null, if it is missing
Throws:
XMLParsingException - if the specified child element is missing

getRequiredAttrValue

public static java.lang.String getRequiredAttrValue(java.lang.String name,
                                                    java.net.URI namespaceURI,
                                                    org.w3c.dom.Node node)
                                             throws XMLParsingException
Returns the value of the specified node attribute.

Parameters:
name - name of attribute
namespaceURI - namespace of attribute
node - current element
Returns:
the textual contents of the attribute
Throws:
XMLParsingException - if specified attribute is missing

getQualifiedNameValue

public static QualifiedName getQualifiedNameValue(org.w3c.dom.Node node)
                                           throws XMLParsingException
Parses the value of the submitted Node as a QualifiedName.

To parse the text contents of an Element node, the actual text node must be given, not the Element node itself.

Parameters:
node -
Returns:
object representation of the element
Throws:
XMLParsingException

getNamespaceForPrefix

public static java.net.URI getNamespaceForPrefix(java.lang.String prefix,
                                                 org.w3c.dom.Node node)
                                          throws java.net.URISyntaxException
Returns the namespace URI that is bound to a given prefix at a certain node in the DOM tree.

Parameters:
prefix -
node -
Returns:
namespace URI that is bound to the given prefix, null otherwise
Throws:
java.net.URISyntaxException

getRequiredChildElement

@Deprecated
public static org.w3c.dom.Element getRequiredChildElement(java.lang.String name,
                                                                     java.net.URI namespaceURI,
                                                                     org.w3c.dom.Node node)
                                                   throws XMLParsingException
Deprecated. 

Returns the specified child element of the given element. If there is more than one element with that name, the first one is returned.

Parameters:
name - name of the child element
namespaceURI - namespaceURI of the child element
node - current element
Returns:
the element or null, if it is missing
Throws:
XMLParsingException - if the specified child element is missing
XMLParsingException
To do:
refactoring required

getChildElement

@Deprecated
public static org.w3c.dom.Element getChildElement(java.lang.String name,
                                                             java.net.URI namespaceURI,
                                                             org.w3c.dom.Node node)
Deprecated. 

Returns the specified child element of the given element. If there is more than one with that name, the first one is returned.

Parameters:
name - name of the child element
namespaceURI - namespace of the child element
node - current element
Returns:
the element or null, if it is missing
To do:
refactoring required

getChildElements

@Deprecated
public static ElementList getChildElements(java.lang.String name,
                                                      java.net.URI namespaceURI,
                                                      org.w3c.dom.Node node)
Deprecated. 

Returns the specified child elements of the given element.

Parameters:
name - name of the child elements
namespaceURI - namespaceURI of the child elements
node - current element
Returns:
list of matching child elements

create

public static org.w3c.dom.Document create()
Create a new and empty DOM document.

Returns:
a new and empty DOM document.

getDocumentBuilder

public static javax.xml.parsers.DocumentBuilder getDocumentBuilder()
Create a new document builder with:

Returns:
new document builder

getAttrValue

@Deprecated
public static java.lang.String getAttrValue(org.w3c.dom.Node node,
                                                       java.lang.String attrName)
Deprecated. use

Returns the specified attribute value of the given node.

Parameters:
node - current element
attrName - local name of the attribute
Returns:
the value of the attribute or null, if it is missing
See Also:
instead

getAttrValue

public static java.lang.String getAttrValue(org.w3c.dom.Node node,
                                            java.net.URI namespaceURI,
                                            java.lang.String attrName,
                                            java.lang.String defaultVal)
Returns the specified attribute value of the given node.

Parameters:
node - current element
namespaceURI - namespace of the attribute
attrName - local name of the attribute
defaultVal - default value to be returned if attribute is nat available
Returns:
the value of the attribute or null, if it is missing

parse

public static org.w3c.dom.Document parse(java.io.Reader reader)
                                  throws java.io.IOException,
                                         org.xml.sax.SAXException
Parses an XML document and returns a DOM object. The underlying input stream is closed at the end.

Parameters:
reader - accessing the resource to parse
Returns:
a DOM object, if en error occurs the response is null
Throws:
java.io.IOException
org.xml.sax.SAXException

parse

@Deprecated
public static org.w3c.dom.Document parse(java.io.InputStream is)
                                  throws java.io.IOException,
                                         org.xml.sax.SAXException
Deprecated. 

Parses an XML document and returns a DOM object.

Parameters:
is - accessing the resource to parse
Returns:
a DOM object
Throws:
java.io.IOException
org.xml.sax.SAXException

copyNode

public static org.w3c.dom.Node copyNode(org.w3c.dom.Node source,
                                        org.w3c.dom.Node dest)
Copies one node to another node.

Parameters:
source -
dest -
Returns:
the copied node

insertNodeInto

public static org.w3c.dom.Node insertNodeInto(org.w3c.dom.Node source,
                                              org.w3c.dom.Node dest)
Appends a node to an element.

The node can be from the same document or a different one (it is automatically imported, if necessary).

Parameters:
source -
dest -
Returns:
the element that is appended to

getFirstChildElement

public static org.w3c.dom.Element getFirstChildElement(org.w3c.dom.Node node)
Returns the first child element of the submitted node.

Parameters:
node -
Returns:
the first child element of the submitted node.

getChildElement

@Deprecated
public static org.w3c.dom.Element getChildElement(org.w3c.dom.Node node,
                                                             java.lang.String name)
Deprecated. Returns the first child element of the submitted node that matches the given local name.

Parameters:
node -
name -
Returns:
the child element

getChildElements

public static ElementList getChildElements(org.w3c.dom.Node node)
Returns all child elements of the given node.

Parameters:
node -
Returns:
all child elements of the given node.

setNodeValue

public static void setNodeValue(org.w3c.dom.Element target,
                                java.lang.String nodeValue)
sets the value of an existing node

Parameters:
target -
nodeValue -

appendElement

public static org.w3c.dom.Element appendElement(org.w3c.dom.Element element,
                                                java.net.URI namespaceURI,
                                                java.lang.String name,
                                                java.lang.String nodeValue)
Creates a new Element node from the given parameters and appends it to the also specified Element. Adds a text node to the newly generated Element as well.

Parameters:
element - Element that the new Element is appended to
namespaceURI - use null for default namespace
name - qualified name
nodeValue - value for a text node that is appended to the generated element
Returns:
the appended Element node

getAsPrettyString

public static java.lang.String getAsPrettyString(java.lang.String xml)
Parameters:
xml -
Returns:
the formatted string, or the original XML string if something went wrong

getStringFragmentAsElement

public static org.w3c.dom.Element getStringFragmentAsElement(java.lang.String fragment)
                                                      throws org.xml.sax.SAXException,
                                                             java.io.IOException
Converts an XML fragment string into a DOM node. The fragment should NOT contain the XML prolog. Appends ALL default namespace bindings for ease of use with broken fragments.

Parameters:
fragment -
Returns:
a DOM element
Throws:
java.io.IOException
org.xml.sax.SAXException

importStringFragment

public static org.w3c.dom.Element importStringFragment(java.lang.String fragment,
                                                       org.w3c.dom.Document doc)
Works like getStringFragmentAsElement(java.lang.String), but does not throw exceptions and immediately imports the node into another document.

Parameters:
fragment -
doc -
Returns:
an element in the new document

escape

public static java.lang.String escape(java.lang.String str)
This method escapes Strings for XML by creating a DOM document, setting the text in an attribute, exporting it to text and extracting the escaped string. That means that it's slow, and the method of property using DOM to create the XML is a million times better. But if you're forced to use StringBuffers, here you have a little helper.

Parameters:
str -
Returns:
the escaped string

escape

public static java.lang.String escape(org.w3c.dom.Node root)
This method escapes Strings for XML by creating a DOM document, setting the text in an attribute, exporting it to text and extracting the escaped string. That means that it's slow, and the method of property using DOM to create the XML is a million times better. But if you're forced to use StringBuffers, here you have a little helper.

Parameters:
str -
Returns:
the escaped string

deegree 2.5 (2011/06/29 09:44 build-8-official)

an open source project founded by lat/lon, Bonn, Germany.
For more information visit: http://www.deegree.org