de.knipp.rritoolkit
Class XmlHelper

java.lang.Object
  extended by de.knipp.rritoolkit.XmlHelper

public class XmlHelper
extends java.lang.Object

helper class that simplifies the parsing of DOM trees

Version:
$Revision: 14936 $
Author:
Klaus Malorny

Constructor Summary
private XmlHelper()
          private constructor to prevent instantiation
 
Method Summary
static boolean asBoolean(java.lang.String text, boolean defaultValue)
          return a boolean value of a given string,
static java.util.List<org.w3c.dom.Element> getElements(org.w3c.dom.Node node)
          return a list of all child elements of the given node
static java.util.List<org.w3c.dom.Element> getElements(org.w3c.dom.Node node, javax.xml.namespace.QName qName)
          return a list of all child elements of the given node which match the given namespace and local name.
static java.util.List<org.w3c.dom.Element> getElements(org.w3c.dom.Node node, java.lang.String localName)
          return a list of all child elements of the given node which match the given local name.
static java.util.List<org.w3c.dom.Element> getElements(org.w3c.dom.Node node, java.lang.String uri, java.lang.String localName)
          return a list of all child elements of the given node which match the given namespace and local name.
static org.w3c.dom.Element getFirstElement(org.w3c.dom.Node node)
          return the first element
static org.w3c.dom.Element getFirstElement(org.w3c.dom.Node node, javax.xml.namespace.QName qName)
          return the first element with the given namespace/local name
static org.w3c.dom.Element getFirstElement(org.w3c.dom.Node node, java.lang.String localName)
          return the first element with the given local name
static org.w3c.dom.Element getFirstElement(org.w3c.dom.Node node, java.lang.String uri, java.lang.String localName)
          return the first element with the given namespace/local name
static java.lang.String getFirstElementText(org.w3c.dom.Node node, javax.xml.namespace.QName qName)
          return the the text first element with the given namespace/local name
static java.lang.String getFirstElementText(org.w3c.dom.Node node, java.lang.String localName)
          return the text of the first matching element
static java.lang.String getFirstElementText(org.w3c.dom.Node node, java.lang.String uri, java.lang.String localName)
          return the the text first element with the given namespace/local name
static org.w3c.dom.Element getNextElement(org.w3c.dom.Element el)
          return the next sibling element
static boolean isNilled(org.w3c.dom.Element el)
          return whether the given element is nilled
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XmlHelper

private XmlHelper()
private constructor to prevent instantiation

Method Detail

getElements

public static java.util.List<org.w3c.dom.Element> getElements(org.w3c.dom.Node node)
                                                       throws org.w3c.dom.DOMException
return a list of all child elements of the given node

Parameters:
node - the parent node
Returns:
a list containing the elements
Throws:
org.w3c.dom.DOMException - on DOM exceptison

getElements

public static java.util.List<org.w3c.dom.Element> getElements(org.w3c.dom.Node node,
                                                              java.lang.String localName)
                                                       throws org.w3c.dom.DOMException
return a list of all child elements of the given node which match the given local name. The functionality is similar to Element.getElementsByTagName, but it returns a list, which is iterable.

Parameters:
node - the parent node
localName - the element's local name
Returns:
a list containing the elements
Throws:
org.w3c.dom.DOMException - on DOM exceptions

getElements

public static java.util.List<org.w3c.dom.Element> getElements(org.w3c.dom.Node node,
                                                              java.lang.String uri,
                                                              java.lang.String localName)
                                                       throws org.w3c.dom.DOMException
return a list of all child elements of the given node which match the given namespace and local name. Please note that the prefix of the elements are not tested. The functionality is similar to Element.getElementsByTagName, but it returns a list, which is iterable.

Parameters:
node - the parent node
uri - the namespace URI
localName - the element's local name. If null, all elements matching the given namespace are returned
Returns:
a list containing the elements
Throws:
org.w3c.dom.DOMException - on DOM exceptions

getElements

public static java.util.List<org.w3c.dom.Element> getElements(org.w3c.dom.Node node,
                                                              javax.xml.namespace.QName qName)
                                                       throws org.w3c.dom.DOMException
return a list of all child elements of the given node which match the given namespace and local name. Please note that the prefix of the elements are not tested. The functionality is similar to Element.getElementsByTagName, but it returns a list, which is iterable.

Parameters:
node - the parent node
qName - the qualified name
Returns:
a list containing the elements
Throws:
org.w3c.dom.DOMException - on DOM exceptions

getFirstElement

public static org.w3c.dom.Element getFirstElement(org.w3c.dom.Node node)
                                           throws org.w3c.dom.DOMException
return the first element

Parameters:
node - the parent node
Returns:
the first element or null if there is no matching element
Throws:
org.w3c.dom.DOMException - on DOM exceptions

getNextElement

public static org.w3c.dom.Element getNextElement(org.w3c.dom.Element el)
return the next sibling element

Parameters:
el - the element
Returns:
the next element or null if there is no next sibling element

getFirstElement

public static org.w3c.dom.Element getFirstElement(org.w3c.dom.Node node,
                                                  java.lang.String localName)
                                           throws org.w3c.dom.DOMException
return the first element with the given local name

Parameters:
node - the parent node
localName - the element's local name
Returns:
the first element or null if there is no matching element
Throws:
org.w3c.dom.DOMException - on DOM exceptions

getFirstElement

public static org.w3c.dom.Element getFirstElement(org.w3c.dom.Node node,
                                                  java.lang.String uri,
                                                  java.lang.String localName)
                                           throws org.w3c.dom.DOMException
return the first element with the given namespace/local name

Parameters:
node - the parent node
uri - the namespace URI
localName - the element's local name. If null, the first element matching the given namespace is returned
Returns:
the first element or null if there is no matching element
Throws:
org.w3c.dom.DOMException - on DOM exceptions

getFirstElement

public static org.w3c.dom.Element getFirstElement(org.w3c.dom.Node node,
                                                  javax.xml.namespace.QName qName)
                                           throws org.w3c.dom.DOMException
return the first element with the given namespace/local name

Parameters:
node - the parent node
qName - the qualified name
Returns:
the first element or null if there is no matching element
Throws:
org.w3c.dom.DOMException - on DOM exceptions

getFirstElementText

public static java.lang.String getFirstElementText(org.w3c.dom.Node node,
                                                   java.lang.String localName)
                                            throws org.w3c.dom.DOMException
return the text of the first matching element

Parameters:
node - the parent node
localName - the element's local name
Returns:
the text of the first element or null if there is no matching element
Throws:
org.w3c.dom.DOMException - on DOM exceptions

getFirstElementText

public static java.lang.String getFirstElementText(org.w3c.dom.Node node,
                                                   java.lang.String uri,
                                                   java.lang.String localName)
                                            throws org.w3c.dom.DOMException
return the the text first element with the given namespace/local name

Parameters:
node - the parent node
uri - the namespace URI
localName - the element's local name. If null, the first element matching the given namespace is returned
Returns:
the text of the first element or null if there is no matching element
Throws:
org.w3c.dom.DOMException - on DOM exceptions

getFirstElementText

public static java.lang.String getFirstElementText(org.w3c.dom.Node node,
                                                   javax.xml.namespace.QName qName)
                                            throws org.w3c.dom.DOMException
return the the text first element with the given namespace/local name

Parameters:
node - the parent node
qName - the qualified name
Returns:
the text of the first element or null if there is no matching element
Throws:
org.w3c.dom.DOMException - on DOM exceptions

asBoolean

public static boolean asBoolean(java.lang.String text,
                                boolean defaultValue)
return a boolean value of a given string,

Parameters:
text - the text, may be null
defaultValue - the default value
Returns:
the value of text, as defined by the boolean XML Schema datatype, or the default value if text is null or invalid

isNilled

public static boolean isNilled(org.w3c.dom.Element el)
                        throws org.w3c.dom.DOMException
return whether the given element is nilled

Parameters:
el - the element
Returns:
true if nilled, i.e. has the xsi:nil attribute with true as a value
Throws:
org.w3c.dom.DOMException - on DOM exceptions


Copyright © 2005-2011 Knipp Medien und Kommunikation GmbH