org.ops4j.util.xml
Class ElementHelper

java.lang.Object
  extended by org.ops4j.util.xml.ElementHelper

public final class ElementHelper
extends java.lang.Object

Utility class supporting the XML document parsing.

Version:
$Id: ElementHelper.java 10301 2008-01-26 07:01:32Z adreghiciu@gmail.com $
Author:
Open Participation Software for Java

Method Summary
static java.lang.String getAttribute(org.w3c.dom.Element node, java.lang.String key)
          Return the value of an element attribute.
static java.lang.String getAttribute(org.w3c.dom.Element node, java.lang.String key, java.lang.String def)
          Return the value of an element attribute.
static org.w3c.dom.Element getChild(org.w3c.dom.Element root, java.lang.String name)
          Return a named child relative to a supplied element.
static org.w3c.dom.Element[] getChildren(org.w3c.dom.Element root)
          Return all children of the supplied parent.
static org.w3c.dom.Element[] getChildren(org.w3c.dom.Element root, java.lang.String name)
          Return all children matching the supplied element name.
static org.w3c.dom.Element getRootElement(java.io.InputStream input)
          Return the root element of the supplied input stream.
static java.lang.String getValue(org.w3c.dom.Element node)
          Return the value of an element.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getRootElement

public static org.w3c.dom.Element getRootElement(java.io.InputStream input)
                                          throws javax.xml.parsers.ParserConfigurationException,
                                                 java.io.IOException,
                                                 org.xml.sax.SAXException
Return the root element of the supplied input stream.

Parameters:
input - the input stream containing a XML definition
Returns:
the root element
Throws:
java.io.IOException - If an underlying I/O problem occured.
javax.xml.parsers.ParserConfigurationException - if there is a severe problem in the XML parsing subsystem.
org.xml.sax.SAXException - If the XML is malformed in some way.

getChild

public static org.w3c.dom.Element getChild(org.w3c.dom.Element root,
                                           java.lang.String name)
Return a named child relative to a supplied element.

Parameters:
root - the parent DOM element
name - the name of a child element
Returns:
the child element of null if the child does not exist

getChildren

public static org.w3c.dom.Element[] getChildren(org.w3c.dom.Element root,
                                                java.lang.String name)
Return all children matching the supplied element name.

Parameters:
root - the parent DOM element
name - the name against which child element will be matched
Returns:
the array of child elements with a matching name

getChildren

public static org.w3c.dom.Element[] getChildren(org.w3c.dom.Element root)
Return all children of the supplied parent.

Parameters:
root - the parent DOM element
Returns:
the array of all children

getValue

public static java.lang.String getValue(org.w3c.dom.Element node)
Return the value of an element.

Parameters:
node - the DOM node
Returns:
the node value

getAttribute

public static java.lang.String getAttribute(org.w3c.dom.Element node,
                                            java.lang.String key)
Return the value of an element attribute.

Parameters:
node - the DOM node
key - the attribute key
Returns:
the attribute value or null if the attribute is undefined

getAttribute

public static java.lang.String getAttribute(org.w3c.dom.Element node,
                                            java.lang.String key,
                                            java.lang.String def)
Return the value of an element attribute.

Parameters:
node - the DOM node
key - the attribute key
def - the default value if the attribute is undefined
Returns:
the attribute value or the default value if undefined


Copyright © 2006-2009 OPS4J - Open Participation Software for Java. All Rights Reserved.