| 
deegree 2.6-pre (2011/11/29 00:10 build-378-unofficial) | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.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 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(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 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 | 
|---|
public static Node getNode(Node contextNode,
                           String xPathQuery,
                           NamespaceContext nsContext)
                    throws XMLParsingException
contextNode - xPathQuery - nsContext - 
XMLParsingException
public static Element getElement(Node contextNode,
                                 String xpath,
                                 NamespaceContext nsContext)
                          throws XMLParsingException
contextNode - xpath - nsContext - 
XMLParsingException
ClassCastException - if the node was not an element
public static String getNodeAsString(Node contextNode,
                                     String xPathQuery,
                                     NamespaceContext nsContext,
                                     String defaultValue)
                              throws XMLParsingException
contextNode - xPathQuery - nsContext - defaultValue - 
XMLParsingException
public static boolean getNodeAsBoolean(Node contextNode,
                                       String xPathQuery,
                                       NamespaceContext nsContext,
                                       boolean defaultValue)
                                throws XMLParsingException
contextNode - xPathQuery - nsContext - defaultValue - 
XMLParsingException
public static int getNodeAsInt(Node contextNode,
                               String xPathQuery,
                               NamespaceContext nsContext,
                               int defaultValue)
                        throws XMLParsingException
contextNode - xPathQuery - nsContext - defaultValue - 
XMLParsingException
public static double getNodeAsDouble(Node contextNode,
                                     String xPathQuery,
                                     NamespaceContext nsContext,
                                     double defaultValue)
                              throws XMLParsingException
contextNode - xPathQuery - nsContext - defaultValue - 
XMLParsingException
public static URI getNodeAsURI(Node contextNode,
                               String xPathQuery,
                               NamespaceContext nsContext,
                               URI defaultValue)
                        throws XMLParsingException
contextNode - xPathQuery - nsContext - defaultValue - 
XMLParsingException
public static QualifiedName getNodeAsQualifiedName(Node contextNode,
                                                   String xPathQuery,
                                                   NamespaceContext nsContext,
                                                   QualifiedName defaultValue)
                                            throws XMLParsingException
contextNode - xPathQuery - nsContext - defaultValue - 
XMLParsingException
public static List<Node> getNodes(Node contextNode,
                                  String xPathQuery,
                                  NamespaceContext nsContext)
                           throws XMLParsingException
contextNode - xPathQuery - nsContext - 
XMLParsingException
public static String[] getNodesAsStrings(Node contextNode,
                                         String xPathQuery,
                                         NamespaceContext nsContext)
                                  throws XMLParsingException
contextNode - xPathQuery - nsContext - 
XMLParsingException
public static List<String> getNodesAsStringList(Node contextNode,
                                                String xPathQuery,
                                                NamespaceContext nsContext)
                                         throws XMLParsingException
contextNode - to get the strings fromxPathQuery - finding the nodesnsContext - to find the namespaces from.
null
XMLParsingException
public static URI[] getNodesAsURIs(Node contextNode,
                                   String xPathQuery,
                                   NamespaceContext nsContext)
                            throws XMLParsingException
contextNode - xPathQuery - nsContext - 
XMLParsingException
public static QualifiedName[] getNodesAsQualifiedNames(Node contextNode,
                                                       String xPathQuery,
                                                       NamespaceContext nsContext)
                                                throws XMLParsingException
contextNode - xPathQuery - nsContext - 
XMLParsingException
public static Node getRequiredNode(Node contextNode,
                                   String xPathQuery,
                                   NamespaceContext nsContext)
                            throws XMLParsingException
contextNode - xPathQuery - nsContext - 
XMLParsingException
public static Element getRequiredElement(Node contextNode,
                                         String xpath,
                                         NamespaceContext nsContext)
                                  throws XMLParsingException
contextNode - xpath - nsContext - 
XMLParsingException
ClassCastException - if the node was not an element
public static String getRequiredNodeAsString(Node contextNode,
                                             String xPathQuery,
                                             NamespaceContext nsContext)
                                      throws XMLParsingException
contextNode - xPathQuery - nsContext - 
XMLParsingException
public static String getRequiredNodeAsString(Node contextNode,
                                             String xPathQuery,
                                             NamespaceContext nsContext,
                                             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 String[] getRequiredNodeAsStrings(Node contextNode,
                                                String xPathQuery,
                                                NamespaceContext nsContext,
                                                String regex)
                                         throws XMLParsingException
contextNode - xPathQuery - nsContext - regex - 
XMLParsingException
public static boolean getRequiredNodeAsBoolean(Node contextNode,
                                               String xPathQuery,
                                               NamespaceContext nsContext)
                                        throws XMLParsingException
contextNode - xPathQuery - nsContext - 
XMLParsingException
public static int getRequiredNodeAsInt(Node contextNode,
                                       String xPathQuery,
                                       NamespaceContext nsContext)
                                throws XMLParsingException
contextNode - xPathQuery - nsContext - 
XMLParsingException
public static double getRequiredNodeAsDouble(Node contextNode,
                                             String xPathQuery,
                                             NamespaceContext nsContext)
                                      throws XMLParsingException
contextNode - xPathQuery - nsContext - 
XMLParsingException
public static double[] getRequiredNodeAsDoubles(Node contextNode,
                                                String xPathQuery,
                                                NamespaceContext nsContext,
                                                String regex)
                                         throws XMLParsingException
contextNode - xPathQuery - nsContext - regex - 
XMLParsingException
public static URI getRequiredNodeAsURI(Node contextNode,
                                       String xPathQuery,
                                       NamespaceContext nsContext)
                                throws XMLParsingException
contextNode - xPathQuery - nsContext - 
XMLParsingException
public static QualifiedName getRequiredNodeAsQualifiedName(Node contextNode,
                                                           String xPathQuery,
                                                           NamespaceContext nsContext)
                                                    throws XMLParsingException
contextNode - xPathQuery - nsContext - 
XMLParsingException
public static List<Node> getRequiredNodes(Node contextNode,
                                          String xPathQuery,
                                          NamespaceContext nsContext)
                                   throws XMLParsingException
contextNode - xPathQuery - nsContext - 
XMLParsingException
public static List<Element> getRequiredElements(Node contextNode,
                                                String xpath,
                                                NamespaceContext nsContext)
                                         throws XMLParsingException
contextNode - xpath - nsContext - 
XMLParsingException
ClassCastException - if the resulting nodes of the xpath are not elements
public static List<Element> getElements(Node contextNode,
                                        String xpath,
                                        NamespaceContext nsContext)
                                 throws XMLParsingException
contextNode - xpath - nsContext - 
XMLParsingException
ClassCastException - if the resulting nodes of the xpath are not elements
public static String[] getRequiredNodesAsStrings(Node contextNode,
                                                 String xPathQuery,
                                                 NamespaceContext nsContext)
                                          throws XMLParsingException
contextNode - xPathQuery - nsContext - 
XMLParsingException
public static QualifiedName[] getRequiredNodesAsQualifiedNames(Node contextNode,
                                                               String xPathQuery,
                                                               NamespaceContext nsContext)
                                                        throws XMLParsingException
contextNode - xPathQuery - nsContext - 
XMLParsingException
public static void checkValue(String value,
                              String[] validValues)
                       throws XMLParsingException
value - validValues - 
XMLParsingException
public static Element appendElement(Element element,
                                    URI namespaceURI,
                                    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 node
public static void appendNSBinding(Element element,
                                   String prefix,
                                   URI namespace)
element - prefix - namespace - 
public static void appendNSDefaultBinding(Element element,
                                          URI namespace)
element - namespace - 
public static void appendNSBindings(Element element,
                                    NamespaceContext nsContext)
NOTE: The prebound prefix "xml" is skipped.
element - nsContext - public static String getStringValue(Node node)
node - current element
public static String getStringValue(String name,
                                    URI namespace,
                                    Node node,
                                    String defaultValue)
name - name of the child elementnamespace - namespace of the child elementnode - current elementdefaultValue - default value if element is missing
public static String getRequiredStringValue(String name,
                                            URI namespace,
                                            Node node)
                                     throws XMLParsingException
name - name of the child elementnamespace - namespace of the child elementnode - current element
XMLParsingException - if the specified child element is missing
public static String getRequiredAttrValue(String name,
                                          URI namespaceURI,
                                          Node node)
                                   throws XMLParsingException
name - name of attributenamespaceURI - namespace of attributenode - current element
XMLParsingException - if specified attribute is missing
public static QualifiedName getQualifiedNameValue(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 URI getNamespaceForPrefix(String prefix,
                                        Node node)
                                 throws URISyntaxException
prefix - node - 
URISyntaxException
@Deprecated
public static Element getRequiredChildElement(String name,
                                                         URI namespaceURI,
                                                         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 Element getChildElement(String name,
                                                 URI namespaceURI,
                                                 Node node)
name - name of the child elementnamespaceURI - namespace of the child elementnode - current element
@Deprecated
public static ElementList getChildElements(String name,
                                                      URI namespaceURI,
                                                      Node node)
name - name of the child elementsnamespaceURI - namespaceURI of the child elementsnode - current element
public static Document create()
public static DocumentBuilder getDocumentBuilder()
@Deprecated
public static String getAttrValue(Node node,
                                             String attrName)
node - current elementattrName - local name of the attribute
instead
public static String getAttrValue(Node node,
                                  URI namespaceURI,
                                  String attrName,
                                  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 Document parse(Reader reader)
                      throws IOException,
                             SAXException
reader - accessing the resource to parse
null
IOException
SAXException
@Deprecated
public static Document parse(InputStream is)
                      throws IOException,
                             SAXException
is - accessing the resource to parse
IOException
SAXException
public static Node copyNode(Node source,
                            Node dest)
source - dest - 
public static Node insertNodeInto(Node source,
                                  Node dest)
The node can be from the same document or a different one (it is automatically imported, if necessary).
source - dest - 
public static Element getFirstChildElement(Node node)
node - 
@Deprecated
public static Element getChildElement(Node node,
                                                 String name)
node - name - 
public static ElementList getChildElements(Node node)
node - 
public static void setNodeValue(Element target,
                                String nodeValue)
target - nodeValue - 
public static Element appendElement(Element element,
                                    URI namespaceURI,
                                    String name,
                                    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 String getAsPrettyString(String xml)
xml - 
public static Element getStringFragmentAsElement(String fragment)
                                          throws SAXException,
                                                 IOException
fragment - 
IOException
SAXException
public static Element importStringFragment(String fragment,
                                           Document doc)
getStringFragmentAsElement(java.lang.String), but does not throw exceptions and immediately imports the node
 into another document.
fragment - doc - 
public static String escape(String str)
str - 
public static String escape(Node root)
str - 
  | 
deegree 2.6-pre (2011/11/29 00:10 build-378-unofficial) | |||||||||
| 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