Package PamUtils

Class XMLHelper

java.lang.Object
PamUtils.XMLHelper

public class XMLHelper extends Object
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 Details

    • XMLHelper

      public XMLHelper()
  • Method Details

    • getChildrenByTagName

      public static Iterator getChildrenByTagName(Element element, String tagName)
      Returns an iterator over the children of the given element with the given tag name.
      Parameters:
      element - The parent element
      tagName - The name of the desired child
      Returns:
      An interator of children or null if element is null.
    • getUniqueChild

      public static Element getUniqueChild(Element element, String tagName) throws 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 element
      tagName - The name of the desired child
      Returns:
      The named child.
      Throws:
      Exception - Child was not found or was not unique.
    • getOptionalChild

      public static Element getOptionalChild(Element element, String tagName) throws 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 element
      tagName - 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 element
      tagName - the name of the desired child
      defaultElement - the element to return if the child doesn't exist
      Returns:
      either the named child or the supplied default
      Throws:
      Exception
    • getElementContent

      public static String getElementContent(Element element) throws 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:
      Exception
    • getElementContent

      public static String getElementContent(Element element, String defaultStr) throws 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:
      Exception
    • getUniqueChildContent

      public static String getUniqueChildContent(Element element, String tagName) throws 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:
      Exception
    • getOptionalChildContent

      public static String getOptionalChildContent(Element element, String tagName) throws 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:
      Exception
    • getOptionalChildBooleanContent

      public static boolean getOptionalChildBooleanContent(Element element, String name) throws Exception
      Throws:
      Exception