Package org.jboss.util.xml
Class XmlHelper
- java.lang.Object
-
- org.jboss.util.xml.XmlHelper
-
public class XmlHelper extends java.lang.Object
A utility class to cover up the rough bits of xml parsing- Version:
- $Revision$
-
-
Constructor Summary
Constructors Constructor Description XmlHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.util.Iterator
getChildrenByTagName(org.w3c.dom.Element element, java.lang.String tagName)
Returns an iterator over the children of the given element with the given tag name.static java.lang.String
getElementContent(org.w3c.dom.Element element)
Get the content of the given element.static java.lang.String
getElementContent(org.w3c.dom.Element element, java.lang.String defaultStr)
Get the content of the given element.static org.w3c.dom.Element
getOptionalChild(org.w3c.dom.Element element, java.lang.String tagName)
Gets the child of the specified element having the specified name.static org.w3c.dom.Element
getOptionalChild(org.w3c.dom.Element element, java.lang.String tagName, org.w3c.dom.Element defaultElement)
Gets the child of the specified element having the specified name.static boolean
getOptionalChildBooleanContent(org.w3c.dom.Element element, java.lang.String name)
static java.lang.String
getOptionalChildContent(org.w3c.dom.Element element, java.lang.String tagName)
Macro to get the content of an optional child element.static org.w3c.dom.Element
getUniqueChild(org.w3c.dom.Element element, java.lang.String tagName)
Gets the child of the specified element having the specified unique name.static java.lang.String
getUniqueChildContent(org.w3c.dom.Element element, java.lang.String tagName)
Macro to get the content of a unique child element.static void
write(java.io.Writer out, org.w3c.dom.Document dom)
-
-
-
Method Detail
-
write
public static void write(java.io.Writer out, org.w3c.dom.Document dom) throws java.lang.Exception
- Throws:
java.lang.Exception
-
getChildrenByTagName
public static java.util.Iterator getChildrenByTagName(org.w3c.dom.Element element, java.lang.String tagName)
Returns an iterator over the children of the given element with the given tag name.- Parameters:
element
- The parent elementtagName
- The name of the desired child- Returns:
- An interator of children or null if element is null.
-
getUniqueChild
public static org.w3c.dom.Element getUniqueChild(org.w3c.dom.Element element, java.lang.String tagName) throws java.lang.Exception
Gets the child of the specified element having the specified unique name. If there are more than one children elements with the same name and exception is thrown.- Parameters:
element
- The parent elementtagName
- The name of the desired child- Returns:
- The named child.
- Throws:
java.lang.Exception
- Child was not found or was not unique.
-
getOptionalChild
public static org.w3c.dom.Element getOptionalChild(org.w3c.dom.Element element, java.lang.String tagName) throws java.lang.Exception
Gets the child of the specified element having the specified name. If the child with this name doesn't exist then null is returned instead.- Parameters:
element
- the parent elementtagName
- the name of the desired child- Returns:
- either the named child or null
- Throws:
java.lang.Exception
-
getOptionalChild
public static org.w3c.dom.Element getOptionalChild(org.w3c.dom.Element element, java.lang.String tagName, org.w3c.dom.Element defaultElement) throws java.lang.Exception
Gets the child of the specified element having the specified name. If the child with this name doesn't exist then the supplied default element is returned instead.- Parameters:
element
- the parent elementtagName
- the name of the desired childdefaultElement
- the element to return if the child doesn't exist- Returns:
- either the named child or the supplied default
- Throws:
java.lang.Exception
-
getElementContent
public static java.lang.String getElementContent(org.w3c.dom.Element element) throws java.lang.Exception
Get the content of the given element.- Parameters:
element
- The element to get the content for.- Returns:
- The content of the element or null.
- Throws:
java.lang.Exception
-
getElementContent
public static java.lang.String getElementContent(org.w3c.dom.Element element, java.lang.String defaultStr) throws java.lang.Exception
Get the content of the given element.- Parameters:
element
- The element to get the content for.defaultStr
- The default to return when there is no content.- Returns:
- The content of the element or the default.
- Throws:
java.lang.Exception
-
getUniqueChildContent
public static java.lang.String getUniqueChildContent(org.w3c.dom.Element element, java.lang.String tagName) throws java.lang.Exception
Macro to get the content of a unique child element.- Parameters:
element
- The parent element.tagName
- The name of the desired child.- Returns:
- The element content or null.
- Throws:
java.lang.Exception
-
getOptionalChildContent
public static java.lang.String getOptionalChildContent(org.w3c.dom.Element element, java.lang.String tagName) throws java.lang.Exception
Macro to get the content of an optional child element.- Parameters:
element
- The parent element.tagName
- The name of the desired child.- Returns:
- The element content or null.
- Throws:
java.lang.Exception
-
getOptionalChildBooleanContent
public static boolean getOptionalChildBooleanContent(org.w3c.dom.Element element, java.lang.String name) throws java.lang.Exception
- Throws:
java.lang.Exception
-
-