deegree 2.3 (2010/04/09 10:10 build-4-official)

org.deegree.framework.xml
Class XMLTools

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

public final class XMLTools
extends 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: 20895 $, $Date: 2009-11-19 15:59:59 +0100 (Do, 19. Nov 2009) $
Author:
Markus Schneider , Andreas Poth , last edited by: $Author: aschmitz $

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

getElement

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

getNodeAsString

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

getNodeAsBoolean

public static boolean getNodeAsBoolean(Node contextNode,
                                       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(Node contextNode,
                               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(Node contextNode,
                                     String xPathQuery,
                                     NamespaceContext nsContext,
                                     double defaultValue)
                              throws XMLParsingException
Parameters:
contextNode -
xPathQuery -
nsContext -
defaultValue -
Returns:
the node's double value
Throws:
XMLParsingException

getNodeAsURI

public static URI getNodeAsURI(Node contextNode,
                               String xPathQuery,
                               NamespaceContext nsContext,
                               URI defaultValue)
                        throws XMLParsingException
Parameters:
contextNode -
xPathQuery -
nsContext -
defaultValue -
Returns:
the node as URI
Throws:
XMLParsingException

getNodeAsQualifiedName

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

getNodes

public static List<Node> getNodes(Node contextNode,
                                  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 String[] getNodesAsStrings(Node contextNode,
                                         String xPathQuery,
                                         NamespaceContext nsContext)
                                  throws XMLParsingException
Parameters:
contextNode -
xPathQuery -
nsContext -
Returns:
the list of nodes as strings
Throws:
XMLParsingException

getNodesAsStringList

public static List<String> getNodesAsStringList(Node contextNode,
                                                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 URI[] getNodesAsURIs(Node contextNode,
                                   String xPathQuery,
                                   NamespaceContext nsContext)
                            throws XMLParsingException
Parameters:
contextNode -
xPathQuery -
nsContext -
Returns:
the nodes as URIs
Throws:
XMLParsingException

getNodesAsQualifiedNames

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

getRequiredNode

public static Node getRequiredNode(Node contextNode,
                                   String xPathQuery,
                                   NamespaceContext nsContext)
                            throws XMLParsingException
Parameters:
contextNode -
xPathQuery -
nsContext -
Returns:
the node
Throws:
XMLParsingException

getRequiredElement

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

getRequiredNodeAsString

public static String getRequiredNodeAsString(Node contextNode,
                                             String xPathQuery,
                                             NamespaceContext nsContext)
                                      throws XMLParsingException
Parameters:
contextNode -
xPathQuery -
nsContext -
Returns:
the node as string
Throws:
XMLParsingException

getRequiredNodeAsString

public static String getRequiredNodeAsString(Node contextNode,
                                             String xPathQuery,
                                             NamespaceContext nsContext,
                                             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 String[] getRequiredNodeAsStrings(Node contextNode,
                                                String xPathQuery,
                                                NamespaceContext nsContext,
                                                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(Node contextNode,
                                               String xPathQuery,
                                               NamespaceContext nsContext)
                                        throws XMLParsingException
Parameters:
contextNode -
xPathQuery -
nsContext -
Returns:
the node as boolean
Throws:
XMLParsingException

getRequiredNodeAsInt

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

getRequiredNodeAsDouble

public static double getRequiredNodeAsDouble(Node contextNode,
                                             String xPathQuery,
                                             NamespaceContext nsContext)
                                      throws XMLParsingException
Parameters:
contextNode -
xPathQuery -
nsContext -
Returns:
the node as double
Throws:
XMLParsingException

getRequiredNodeAsDoubles

public static double[] getRequiredNodeAsDoubles(Node contextNode,
                                                String xPathQuery,
                                                NamespaceContext nsContext,
                                                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 URI getRequiredNodeAsURI(Node contextNode,
                                       String xPathQuery,
                                       NamespaceContext nsContext)
                                throws XMLParsingException
Parameters:
contextNode -
xPathQuery -
nsContext -
Returns:
the node as URI
Throws:
XMLParsingException

getRequiredNodeAsQualifiedName

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

getRequiredNodes

public static List<Node> getRequiredNodes(Node contextNode,
                                          String xPathQuery,
                                          NamespaceContext nsContext)
                                   throws XMLParsingException
Parameters:
contextNode -
xPathQuery -
nsContext -
Returns:
the nodes
Throws:
XMLParsingException

getRequiredElements

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

getElements

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

getRequiredNodesAsStrings

public static String[] getRequiredNodesAsStrings(Node contextNode,
                                                 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(Node contextNode,
                                                               String xPathQuery,
                                                               NamespaceContext nsContext)
                                                        throws XMLParsingException
Parameters:
contextNode -
xPathQuery -
nsContext -
Returns:
the qualified names
Throws:
XMLParsingException

checkValue

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

appendElement

public static Element appendElement(Element element,
                                    URI namespaceURI,
                                    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(Element element,
                                   String prefix,
                                   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(Element element,
                                          URI namespace)
Appends the default namespace binding for the specified element.

Parameters:
element -
namespace -

appendNSBindings

public static void appendNSBindings(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 String getStringValue(Node node)
Returns the text contained in the specified element.

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

getStringValue

public static String getStringValue(String name,
                                    URI namespace,
                                    Node node,
                                    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 String getRequiredStringValue(String name,
                                            URI namespace,
                                            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 String getRequiredAttrValue(String name,
                                          URI namespaceURI,
                                          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(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 URI getNamespaceForPrefix(String prefix,
                                        Node node)
                                 throws 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:
URISyntaxException

getRequiredChildElement

@Deprecated
public static Element getRequiredChildElement(String name,
                                                         URI namespaceURI,
                                                         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 Element getChildElement(String name,
                                                 URI namespaceURI,
                                                 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(String name,
                                                      URI namespaceURI,
                                                      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 Document create()
Create a new and empty DOM document.

Returns:
a new and empty DOM document.

getDocumentBuilder

public static DocumentBuilder getDocumentBuilder()
Create a new document builder with:

Returns:
new document builder

getAttrValue

@Deprecated
public static String getAttrValue(Node node,
                                             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 String getAttrValue(Node node,
                                  URI namespaceURI,
                                  String attrName,
                                  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 Document parse(Reader reader)
                      throws IOException,
                             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:
IOException
SAXException

parse

@Deprecated
public static Document parse(InputStream is)
                      throws IOException,
                             SAXException
Deprecated. 

Parses an XML document and returns a DOM object.

Parameters:
is - accessing the resource to parse
Returns:
a DOM object
Throws:
IOException
SAXException

copyNode

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

Parameters:
source -
dest -
Returns:
the copied node

insertNodeInto

public static Node insertNodeInto(Node source,
                                  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 Element getFirstChildElement(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 Element getChildElement(Node node,
                                                 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(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(Element target,
                                String nodeValue)
sets the value of an existing node

Parameters:
target -
nodeValue -

appendElement

public static Element appendElement(Element element,
                                    URI namespaceURI,
                                    String name,
                                    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 String getAsPrettyString(String xml)
Parameters:
xml -
Returns:
the formatted string, or the original XML string if something went wrong

getStringFragmentAsElement

public static Element getStringFragmentAsElement(String fragment)
                                          throws SAXException,
                                                 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:
IOException
SAXException

importStringFragment

public static Element importStringFragment(String fragment,
                                           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 String escape(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

deegree 2.3 (2010/04/09 10:10 build-4-official)

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