Package PamUtils
Class XMLHelper
java.lang.Object
PamUtils.XMLHelper
A utility class to cover up the rough bits of xml parsing
 From http://www.java2s.com/Code/Java/XML/Returnsaniteratoroverthechildrenofthegivenelementwiththegiventagname.htm
- Version:
 - $Revision: 2787 $
 - Author:
 - Chris Kimpton
 
- 
Constructor Summary
Constructors - 
Method Summary
Modifier and TypeMethodDescriptionstatic IteratorgetChildrenByTagName(Element element, String tagName) Returns an iterator over the children of the given element with the given tag name.static StringgetElementContent(Element element) Get the content of the given element.static StringgetElementContent(Element element, String defaultStr) Get the content of the given element.static ElementgetOptionalChild(Element element, String tagName) Gets the child of the specified element having the specified name.static ElementgetOptionalChild(Element element, String tagName, Element defaultElement) Gets the child of the specified element having the specified name.static booleangetOptionalChildBooleanContent(Element element, String name) static StringgetOptionalChildContent(Element element, String tagName) Macro to get the content of an optional child element.static ElementgetUniqueChild(Element element, String tagName) Gets the child of the specified element having the specified unique name.static StringgetUniqueChildContent(Element element, String tagName) Macro to get the content of a unique child element. 
- 
Constructor Details
- 
XMLHelper
public XMLHelper() 
 - 
 - 
Method Details
- 
getChildrenByTagName
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
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:
 Exception- Child was not found or was not unique.
 - 
getOptionalChild
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:
 Exception
 - 
getOptionalChild
public static Element getOptionalChild(Element element, String tagName, Element defaultElement) throws 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:
 Exception
 - 
getElementContent
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:
 Exception
 - 
getElementContent
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:
 Exception
 - 
getUniqueChildContent
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:
 Exception
 - 
getOptionalChildContent
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:
 Exception
 - 
getOptionalChildBooleanContent
- Throws:
 Exception
 
 -