src/main/java/org/jboss/util/xml/XmlHelper.java
public static String getElementContent(Element element, String defaultStr)
      throws Exception
   {
      if (element == null)
         return defaultStr;

      NodeList children = element.getChildNodes();
      String result = "";
      for (int i = 0; i < children.getLength(); i++)
      {
         if (children.item(i).getNodeType() == Node.TEXT_NODE || 
             children.item(i).getNodeType() == Node.CDATA_SECTION_NODE)
         {
            result += children.item(i).getNodeValue();
         }
         else if( children.item(i).getNodeType() == Node.COMMENT_NODE )
         {
            // Ignore comment nodes
         }
      }
      return result.trim();
   }
public static String getElementContent(Element element, String defaultStr)
      throws Exception
   {
      if (element == null)
         return defaultStr;

      NodeList children = element.getChildNodes();
      String result = "";
      for (int i = 0; i < children.getLength(); i++)
      {
         if (children.item(i).getNodeType() == Node.TEXT_NODE || 
             children.item(i).getNodeType() == Node.CDATA_SECTION_NODE)
         {
            result += children.item(i).getNodeValue();
         }
         else if( children.item(i).getNodeType() == Node.COMMENT_NODE )
         {
            // Ignore comment nodes
         }
      }
      return result.trim();
   }
public static String getElementContent ( Element element , String defaultStr ) throws Exception { if ( element == null ) return defaultStr ; NodeList children = element . getChildNodes ( ) ; String result = "" ; for ( int i = 0 ; i < children . getLength ( ) ; i ++ ) { if ( children . item ( i ) . getNodeType ( ) == Node . TEXT_NODE || children . item ( i ) . getNodeType ( ) == Node . CDATA_SECTION_NODE ) { result += children . item ( i ) . getNodeValue ( ) ; } else if ( children . item ( i ) . getNodeType ( ) == Node . COMMENT_NODE ) { // Ignore comment nodes } } return result . trim ( ) ; }
Get the content of the given element.

@param element       The element to get the content for.
@param defaultStr    The default to return when there is no content.
@return              The content of the element or the default.
@throws Exception
Get the content of the given element .