org.ow2.util.xml
Class XMLUtils

java.lang.Object
  extended by org.ow2.util.xml.XMLUtils

public final class XMLUtils
extends Object

Class with some useful methods on XML document.


Method Summary
static String getAttributeValue(Element base, String name)
          Returns the value of the attribute of the given element.
static String getChildStringValueForElement(Element base, String name)
          Returns the value of the child node with the given name.
static QName getChildValueAsQName(Element base, String name)
          Extract a node's child value as a QName.
[base element (declaring the prefix/namespace mapping)] #text-value: "prefix:local-part"
static Properties getPropertiesValueElement(String ns, Element base, String name)
          Returns a Properties object matching the given node.
static List<String> getStringListValueElement(Element base, String name)
          Returns a list of value for the given node.
static List<String> getStringListValueElement(String ns, Element base, String name)
          Returns a list of value for the given node.
static String getStringValueElement(Element base, String name)
          Returns the value of the given node.
static String getStringValueElement(Element base, String name, boolean trim)
          Returns the value of the given node.
static String getStringValueElement(String ns, Element base, String name)
          Returns the value of the given node or null if the node is not found.
static String getStringValueElement(String ns, Element base, String name, boolean trim)
          Returns the value of the given node or null if the node is not found.
static QName getValueAsQName(Element base)
          Extract a node's value as a QName.
[base element (declaring the prefix/namespace mapping)] #text-value: "prefix:local-part"
static Document newDocument(boolean namespaceAware)
          Creates a new empty Document.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getStringValueElement

public static String getStringValueElement(Element base,
                                           String name)
Returns the value of the given node. (value trimed by default)

Parameters:
base - the element from where to search.
name - of the element to get.
Returns:
the value of this element.

getStringValueElement

public static String getStringValueElement(Element base,
                                           String name,
                                           boolean trim)
Returns the value of the given node.

Parameters:
base - the element from where to search.
name - of the element to get.
trim - trim or not the value
Returns:
the value of this element.

getAttributeValue

public static String getAttributeValue(Element base,
                                       String name)
Returns the value of the attribute of the given element.

Parameters:
base - the element from where to search.
name - of the attribute to get.
Returns:
the value of this element.

getStringValueElement

public static String getStringValueElement(String ns,
                                           Element base,
                                           String name)
Returns the value of the given node or null if the node is not found.

Parameters:
ns - the namespace.
base - the element from where to search.
name - of the element to get.
Returns:
the value of this element or null if the element does not exists.

getStringValueElement

public static String getStringValueElement(String ns,
                                           Element base,
                                           String name,
                                           boolean trim)
Returns the value of the given node or null if the node is not found.

Parameters:
ns - the namespace.
base - the element from where to search.
name - of the element to get.
trim - trim or not the returned value
Returns:
the value of this element or null if the element does not exists.

getChildStringValueForElement

public static String getChildStringValueForElement(Element base,
                                                   String name)
Returns the value of the child node with the given name.

Parameters:
base - the element from where to search.
name - of the element to get.
Returns:
the value of this element.

getPropertiesValueElement

public static Properties getPropertiesValueElement(String ns,
                                                   Element base,
                                                   String name)
Returns a Properties object matching the given node. Parse the following XML structure:
[base element] <ns:name> (only 1) <ns:property @name @value /> (0..n)

Parameters:
ns - the namespace.
base - the element from where to search.
name - of the element to get.
Returns:
the value of this element.

getStringListValueElement

public static List<String> getStringListValueElement(String ns,
                                                     Element base,
                                                     String name)
Returns a list of value for the given node.

Parameters:
ns - the namespace.
base - the element from where to search.
name - of the element to get.
Returns:
the list of value of this element.

getStringListValueElement

public static List<String> getStringListValueElement(Element base,
                                                     String name)
Returns a list of value for the given node.

Parameters:
base - the element from where to search.
name - of the element to get.
Returns:
the list of value of this element.

getChildValueAsQName

public static QName getChildValueAsQName(Element base,
                                         String name)
Extract a node's child value as a QName.
[base element (declaring the prefix/namespace mapping)] #text-value: "prefix:local-part"

Parameters:
element - the element from where to search.
Returns:
The node's value as a QName.

getValueAsQName

public static QName getValueAsQName(Element base)
Extract a node's value as a QName.
[base element (declaring the prefix/namespace mapping)] #text-value: "prefix:local-part"

Parameters:
base - the element from where to search.
Returns:
The node's value as a QName.

newDocument

public static Document newDocument(boolean namespaceAware)
Creates a new empty Document.

Parameters:
namespaceAware - true if the created Document have to support namespaces.
Returns:
a new empty Document


Copyright © 2007-2012 OW2 Consortium. All Rights Reserved.