public static String readElement ( Element rootElement , String elementName ) throws DocumentException { String result = null ; Element element = rootElement . element ( elementName ) ; if ( element != null ) { // Make sure the element does not have any child element if ( ! element . isTextOnly ( ) ) { throw new DocumentException ( "Unexpected non-text content found in element [" + elementName + "]" ) ; } result = element . getText ( ) ; } return result ; }
Read an element from the XML .