de.nava.informa.utils
Class XmlPathUtils

java.lang.Object
  extended by de.nava.informa.utils.XmlPathUtils

public class XmlPathUtils
extends Object

Utility class providing methods access XML attributes and elements using a path.

Author:
Michael Harhen

Method Summary
static String getAttributeValue(org.jdom.Element parent, String childPath, String attribute)
          Returns the value of the attribute of the child element reached by the given path.
static String[] getAttributeValues(org.jdom.Element element, String[] attributes)
          Returns the values of the attributes of given element.
static String[] getAttributeValues(org.jdom.Element parent, String childPath, String[] attributes)
          Returns the value of the child element reached by the given path.
static String getElementValue(org.jdom.Element parent, String childPath)
          Returns the value of an element's child element reached by the given path.
static String[] getElementValues(org.jdom.Element parent, String[] children)
          Returns the values of the specified sub-elements of the child parent element.
static String[] getElementValues(org.jdom.Element parent, String childPath, String[] elements)
          Returns the values of the specified sub-elements of the child element reached by the given path.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getElementValue

public static String getElementValue(org.jdom.Element parent,
                                     String childPath)
Returns the value of an element's child element reached by the given path. Traverses the DOM tree from the parent until the child is reached.

Parameters:
parent - the parent Element
childPath - a path to the root of the elements. Paths are specified as element names, separated by a "/". Namespaces are allowed. e.g. "aaa:bbb/ccc:ddd/eee".
Returns:
the value of the child.
If parent is null, returns null. If childPath is null, returns the value of the parent.

getElementValues

public static String[] getElementValues(org.jdom.Element parent,
                                        String childPath,
                                        String[] elements)
Returns the values of the specified sub-elements of the child element reached by the given path. This is useful in cases where a child has several children. Traverses the DOM tree from the parent until the root is reached, then reads the specified elements.

Parameters:
parent - the parent Element
childPath - a path to the root of the elements. Paths are specified as element names, separated by a "/". Namespaces are allowed. e.g. "aaa:bbb/ccc:ddd/eee".
elements - An array of element names. May contain namespace specifiers.
Returns:
an array containing the value of each element.
If parent or elements is null, returns null. If childPath is null, returns the specified sub-elements of the parent.

getElementValues

public static String[] getElementValues(org.jdom.Element parent,
                                        String[] children)
Returns the values of the specified sub-elements of the child parent element. This is useful in cases where an element has several children.

Parameters:
parent - the parent Element
children - An array of child element names. May contain namespace specifiers.
Returns:
an array containing the value of each child element.
If parent or children is null, returns null.

getAttributeValue

public static String getAttributeValue(org.jdom.Element parent,
                                       String childPath,
                                       String attribute)
Returns the value of the attribute of the child element reached by the given path. Traverses the DOM tree from the parent until the child is reached, then reads the given attribute.

Parameters:
parent - the parent Element
childPath - a path to the root of the elements. Paths are specified as element names, separated by a "/".
attribute - the attribute. May contain a namespace specifier e.g. "rdf:resource".
Returns:
the value of the attribute.
If parent or attribute is null, returns null . If childPath is null, returns the specified attribute of the parent.

getAttributeValues

public static String[] getAttributeValues(org.jdom.Element parent,
                                          String childPath,
                                          String[] attributes)
Returns the value of the child element reached by the given path. This is useful in cases where a child has several attributes. Traverses the DOM tree from the parent until the child is reached.

Parameters:
parent - the parent Element
childPath - a path to the root of the elements. Paths are specified as element names, separated by a "/". Namespaces are allowed. e.g. "aaa:bbb/ccc:ddd/eee".
attributes - - An array of element names. May contain namespace specifiers.
Returns:
the value of the child.
If parent or attributes is null, returns null. If childPath is null, returns the specified attributes of the parent.

getAttributeValues

public static String[] getAttributeValues(org.jdom.Element element,
                                          String[] attributes)
Returns the values of the attributes of given element. This is useful in cases where an element has several attributes.

Parameters:
element - the Element
attributes - An array of attribute names. May contain namespace specifiers.
Returns:
an array containing the values of the element's attributes.
If element or attributes is null, returns null .


Copyright © 2002-2007 Niko Schmuck. All Rights Reserved.