|
deegree 2.5 (2011/06/29 09:44 build-8-official) | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.deegree.framework.xml.XMLTools
public final class XMLTools
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.
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 |
---|
public static org.w3c.dom.Node getNode(org.w3c.dom.Node contextNode, java.lang.String xPathQuery, NamespaceContext nsContext) throws XMLParsingException
contextNode
- xPathQuery
- nsContext
-
XMLParsingException
public static org.w3c.dom.Element getElement(org.w3c.dom.Node contextNode, java.lang.String xpath, NamespaceContext nsContext) throws XMLParsingException
contextNode
- xpath
- nsContext
-
XMLParsingException
java.lang.ClassCastException
- if the node was not an elementpublic static java.lang.String getNodeAsString(org.w3c.dom.Node contextNode, java.lang.String xPathQuery, NamespaceContext nsContext, java.lang.String defaultValue) throws XMLParsingException
contextNode
- xPathQuery
- nsContext
- defaultValue
-
XMLParsingException
public static boolean getNodeAsBoolean(org.w3c.dom.Node contextNode, java.lang.String xPathQuery, NamespaceContext nsContext, boolean defaultValue) throws XMLParsingException
contextNode
- xPathQuery
- nsContext
- defaultValue
-
XMLParsingException
public static int getNodeAsInt(org.w3c.dom.Node contextNode, java.lang.String xPathQuery, NamespaceContext nsContext, int defaultValue) throws XMLParsingException
contextNode
- xPathQuery
- nsContext
- defaultValue
-
XMLParsingException
public static double getNodeAsDouble(org.w3c.dom.Node contextNode, java.lang.String xPathQuery, NamespaceContext nsContext, double defaultValue) throws XMLParsingException
contextNode
- xPathQuery
- nsContext
- defaultValue
-
XMLParsingException
public static java.net.URI getNodeAsURI(org.w3c.dom.Node contextNode, java.lang.String xPathQuery, NamespaceContext nsContext, java.net.URI defaultValue) throws XMLParsingException
contextNode
- xPathQuery
- nsContext
- defaultValue
-
XMLParsingException
public static QualifiedName getNodeAsQualifiedName(org.w3c.dom.Node contextNode, java.lang.String xPathQuery, NamespaceContext nsContext, QualifiedName defaultValue) throws XMLParsingException
contextNode
- xPathQuery
- nsContext
- defaultValue
-
XMLParsingException
public static java.util.List<org.w3c.dom.Node> getNodes(org.w3c.dom.Node contextNode, java.lang.String xPathQuery, NamespaceContext nsContext) throws XMLParsingException
contextNode
- xPathQuery
- nsContext
-
XMLParsingException
public static java.lang.String[] getNodesAsStrings(org.w3c.dom.Node contextNode, java.lang.String xPathQuery, NamespaceContext nsContext) throws XMLParsingException
contextNode
- xPathQuery
- nsContext
-
XMLParsingException
public static java.util.List<java.lang.String> getNodesAsStringList(org.w3c.dom.Node contextNode, java.lang.String xPathQuery, NamespaceContext nsContext) throws XMLParsingException
contextNode
- to get the strings fromxPathQuery
- finding the nodesnsContext
- to find the namespaces from.
null
XMLParsingException
public static java.net.URI[] getNodesAsURIs(org.w3c.dom.Node contextNode, java.lang.String xPathQuery, NamespaceContext nsContext) throws XMLParsingException
contextNode
- xPathQuery
- nsContext
-
XMLParsingException
public static QualifiedName[] getNodesAsQualifiedNames(org.w3c.dom.Node contextNode, java.lang.String xPathQuery, NamespaceContext nsContext) throws XMLParsingException
contextNode
- xPathQuery
- nsContext
-
XMLParsingException
public static org.w3c.dom.Node getRequiredNode(org.w3c.dom.Node contextNode, java.lang.String xPathQuery, NamespaceContext nsContext) throws XMLParsingException
contextNode
- xPathQuery
- nsContext
-
XMLParsingException
public static org.w3c.dom.Element getRequiredElement(org.w3c.dom.Node contextNode, java.lang.String xpath, NamespaceContext nsContext) throws XMLParsingException
contextNode
- xpath
- nsContext
-
XMLParsingException
java.lang.ClassCastException
- if the node was not an elementpublic static java.lang.String getRequiredNodeAsString(org.w3c.dom.Node contextNode, java.lang.String xPathQuery, NamespaceContext nsContext) throws XMLParsingException
contextNode
- xPathQuery
- nsContext
-
XMLParsingException
public static java.lang.String getRequiredNodeAsString(org.w3c.dom.Node contextNode, java.lang.String xPathQuery, NamespaceContext nsContext, java.lang.String[] validValues) throws XMLParsingException
contextNode
- the parent of the requested nodexPathQuery
- the node to get out of the domnsContext
- context of the nodevalidValues
- the values that are valid for the required node
XMLParsingException
- if no Node was found or the text of the Node was not present in the given valid strings.public static java.lang.String[] getRequiredNodeAsStrings(org.w3c.dom.Node contextNode, java.lang.String xPathQuery, NamespaceContext nsContext, java.lang.String regex) throws XMLParsingException
contextNode
- xPathQuery
- nsContext
- regex
-
XMLParsingException
public static boolean getRequiredNodeAsBoolean(org.w3c.dom.Node contextNode, java.lang.String xPathQuery, NamespaceContext nsContext) throws XMLParsingException
contextNode
- xPathQuery
- nsContext
-
XMLParsingException
public static int getRequiredNodeAsInt(org.w3c.dom.Node contextNode, java.lang.String xPathQuery, NamespaceContext nsContext) throws XMLParsingException
contextNode
- xPathQuery
- nsContext
-
XMLParsingException
public static double getRequiredNodeAsDouble(org.w3c.dom.Node contextNode, java.lang.String xPathQuery, NamespaceContext nsContext) throws XMLParsingException
contextNode
- xPathQuery
- nsContext
-
XMLParsingException
public static double[] getRequiredNodeAsDoubles(org.w3c.dom.Node contextNode, java.lang.String xPathQuery, NamespaceContext nsContext, java.lang.String regex) throws XMLParsingException
contextNode
- xPathQuery
- nsContext
- regex
-
XMLParsingException
public static java.net.URI getRequiredNodeAsURI(org.w3c.dom.Node contextNode, java.lang.String xPathQuery, NamespaceContext nsContext) throws XMLParsingException
contextNode
- xPathQuery
- nsContext
-
XMLParsingException
public static QualifiedName getRequiredNodeAsQualifiedName(org.w3c.dom.Node contextNode, java.lang.String xPathQuery, NamespaceContext nsContext) throws XMLParsingException
contextNode
- xPathQuery
- nsContext
-
XMLParsingException
public static java.util.List<org.w3c.dom.Node> getRequiredNodes(org.w3c.dom.Node contextNode, java.lang.String xPathQuery, NamespaceContext nsContext) throws XMLParsingException
contextNode
- xPathQuery
- nsContext
-
XMLParsingException
public static java.util.List<org.w3c.dom.Element> getRequiredElements(org.w3c.dom.Node contextNode, java.lang.String xpath, NamespaceContext nsContext) throws XMLParsingException
contextNode
- xpath
- nsContext
-
XMLParsingException
java.lang.ClassCastException
- if the resulting nodes of the xpath are not elementspublic static java.util.List<org.w3c.dom.Element> getElements(org.w3c.dom.Node contextNode, java.lang.String xpath, NamespaceContext nsContext) throws XMLParsingException
contextNode
- xpath
- nsContext
-
XMLParsingException
java.lang.ClassCastException
- if the resulting nodes of the xpath are not elementspublic static java.lang.String[] getRequiredNodesAsStrings(org.w3c.dom.Node contextNode, java.lang.String xPathQuery, NamespaceContext nsContext) throws XMLParsingException
contextNode
- xPathQuery
- nsContext
-
XMLParsingException
public static QualifiedName[] getRequiredNodesAsQualifiedNames(org.w3c.dom.Node contextNode, java.lang.String xPathQuery, NamespaceContext nsContext) throws XMLParsingException
contextNode
- xPathQuery
- nsContext
-
XMLParsingException
public static void checkValue(java.lang.String value, java.lang.String[] validValues) throws XMLParsingException
value
- validValues
-
XMLParsingException
public static org.w3c.dom.Element appendElement(org.w3c.dom.Element element, java.net.URI namespaceURI, java.lang.String name)
Element
node from the given parameters and appends it to the also specified
Element
.
element
- Element
that the new Element
is appended tonamespaceURI
- use null for default namespacename
- qualified name
Element
nodepublic static void appendNSBinding(org.w3c.dom.Element element, java.lang.String prefix, java.net.URI namespace)
element
- prefix
- namespace
- public static void appendNSDefaultBinding(org.w3c.dom.Element element, java.net.URI namespace)
element
- namespace
- public static void appendNSBindings(org.w3c.dom.Element element, NamespaceContext nsContext)
NOTE: The prebound prefix "xml" is skipped.
element
- nsContext
- public static java.lang.String getStringValue(org.w3c.dom.Node node)
node
- current element
public static java.lang.String getStringValue(java.lang.String name, java.net.URI namespace, org.w3c.dom.Node node, java.lang.String defaultValue)
name
- name of the child elementnamespace
- namespace of the child elementnode
- current elementdefaultValue
- default value if element is missing
public static java.lang.String getRequiredStringValue(java.lang.String name, java.net.URI namespace, org.w3c.dom.Node node) throws XMLParsingException
name
- name of the child elementnamespace
- namespace of the child elementnode
- current element
XMLParsingException
- if the specified child element is missingpublic static java.lang.String getRequiredAttrValue(java.lang.String name, java.net.URI namespaceURI, org.w3c.dom.Node node) throws XMLParsingException
name
- name of attributenamespaceURI
- namespace of attributenode
- current element
XMLParsingException
- if specified attribute is missingpublic static QualifiedName getQualifiedNameValue(org.w3c.dom.Node node) throws XMLParsingException
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.
node
-
XMLParsingException
public static java.net.URI getNamespaceForPrefix(java.lang.String prefix, org.w3c.dom.Node node) throws java.net.URISyntaxException
prefix
- node
-
java.net.URISyntaxException
@Deprecated public static org.w3c.dom.Element getRequiredChildElement(java.lang.String name, java.net.URI namespaceURI, org.w3c.dom.Node node) throws XMLParsingException
name
- name of the child elementnamespaceURI
- namespaceURI of the child elementnode
- current element
XMLParsingException
- if the specified child element is missing
XMLParsingException
@Deprecated public static org.w3c.dom.Element getChildElement(java.lang.String name, java.net.URI namespaceURI, org.w3c.dom.Node node)
name
- name of the child elementnamespaceURI
- namespace of the child elementnode
- current element
@Deprecated public static ElementList getChildElements(java.lang.String name, java.net.URI namespaceURI, org.w3c.dom.Node node)
name
- name of the child elementsnamespaceURI
- namespaceURI of the child elementsnode
- current element
public static org.w3c.dom.Document create()
public static javax.xml.parsers.DocumentBuilder getDocumentBuilder()
@Deprecated public static java.lang.String getAttrValue(org.w3c.dom.Node node, java.lang.String attrName)
node
- current elementattrName
- local name of the attribute
instead
public static java.lang.String getAttrValue(org.w3c.dom.Node node, java.net.URI namespaceURI, java.lang.String attrName, java.lang.String defaultVal)
node
- current elementnamespaceURI
- namespace of the attributeattrName
- local name of the attributedefaultVal
- default value to be returned if attribute is nat available
public static org.w3c.dom.Document parse(java.io.Reader reader) throws java.io.IOException, org.xml.sax.SAXException
reader
- accessing the resource to parse
null
java.io.IOException
org.xml.sax.SAXException
@Deprecated public static org.w3c.dom.Document parse(java.io.InputStream is) throws java.io.IOException, org.xml.sax.SAXException
is
- accessing the resource to parse
java.io.IOException
org.xml.sax.SAXException
public static org.w3c.dom.Node copyNode(org.w3c.dom.Node source, org.w3c.dom.Node dest)
source
- dest
-
public static org.w3c.dom.Node insertNodeInto(org.w3c.dom.Node source, org.w3c.dom.Node dest)
The node can be from the same document or a different one (it is automatically imported, if necessary).
source
- dest
-
public static org.w3c.dom.Element getFirstChildElement(org.w3c.dom.Node node)
node
-
@Deprecated public static org.w3c.dom.Element getChildElement(org.w3c.dom.Node node, java.lang.String name)
node
- name
-
public static ElementList getChildElements(org.w3c.dom.Node node)
node
-
public static void setNodeValue(org.w3c.dom.Element target, java.lang.String nodeValue)
target
- nodeValue
- public static org.w3c.dom.Element appendElement(org.w3c.dom.Element element, java.net.URI namespaceURI, java.lang.String name, java.lang.String nodeValue)
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.
element
- Element
that the new Element
is appended tonamespaceURI
- use null for default namespacename
- qualified namenodeValue
- value for a text node that is appended to the generated element
Element
nodepublic static java.lang.String getAsPrettyString(java.lang.String xml)
xml
-
public static org.w3c.dom.Element getStringFragmentAsElement(java.lang.String fragment) throws org.xml.sax.SAXException, java.io.IOException
fragment
-
java.io.IOException
org.xml.sax.SAXException
public static org.w3c.dom.Element importStringFragment(java.lang.String fragment, org.w3c.dom.Document doc)
getStringFragmentAsElement(java.lang.String)
, but does not throw exceptions and immediately imports the node
into another document.
fragment
- doc
-
public static java.lang.String escape(java.lang.String str)
str
-
public static java.lang.String escape(org.w3c.dom.Node root)
str
-
|
deegree 2.5 (2011/06/29 09:44 build-8-official) | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
an open source project founded by lat/lon, Bonn, Germany.
For more information visit: http://www.deegree.org