org.lateralnz.common.util
Class XMLUtils

java.lang.Object
  extended by org.lateralnz.common.util.XMLUtils
All Implemented Interfaces:
Constants

public final class XMLUtils
extends java.lang.Object
implements Constants

common XML utility functions


Field Summary
 
Fields inherited from interface org.lateralnz.common.util.Constants
AMPERSAND, AND, APPLICATION_X_WWW_FORM_URLENCODED, ASTERISK, AT, BACK_SLASH, CHAR_LEFT_CHEV, CHAR_RIGHT_CHEV, COLON, COMMA, CRLF, DASH, DELETE, DOLLAR, DOT, DOT_CLASS, DOT_JAVA, EIGHT, EMPTY, EQUALS, FALSE, FILE_SEPARATOR, FIVE, FORWARD_SLASH, FOUR, FULLSTOP, HASH, HAT, INSERT, LEFT_BRACE, LEFT_BRACKET, LEFT_CHEV, MAX_LEN_APPCODE, MAX_LEN_APPGROUP, MAX_LEN_MSGCODE, MAX_LEN_MSGTEXT, MINUS_ONE, N, NEWLINE, NINE, NO, NULL_STRING, OFF, ON, ONE, ONE_DAY, ONE_HOUR, ONE_MINUTE, ONE_WEEK, PATH_SEPARATOR, PERCENT, PIPE, PLUS, QUESTION_MARK, QUOTE, REQUIRED, REQUIRES_NEW, RETURN, RIGHT_BRACE, RIGHT_BRACKET, RIGHT_CHEV, SELECT, SEMICOLON, SEVEN, SINGLE_QUOTE, SIX, SPACE, SQ_LEFT_BRACKET, SQ_RIGHT_BRACKET, SUPPORTS, TEXT_HTML, TEXT_PLAIN, TEXT_XML, THREE, TRUE, TWO, UNDERSCORE, UPDATE, UTF_8, Y, YES, ZERO
 
Method Summary
static java.lang.String flatten(org.w3c.dom.Node xml)
          flatten an XML node into a string (reverse parse?)
static java.lang.String getAttributeValue(org.w3c.dom.Node xml, java.lang.String attribute, java.lang.String def)
          get the value of an xml attribute.
static java.lang.String getFirstChildElementValue(org.w3c.dom.Element e, java.lang.String elemName)
          get the 'first child' element value of an element
static org.w3c.dom.Node getNamedNode(org.w3c.dom.Node node, java.lang.String name)
          get the first node with a specified name
static java.util.List getNodesByName(org.w3c.dom.Node node, java.lang.String name)
          get a list of XML nodes based upon their nodename
static java.lang.String getNodeType(org.w3c.dom.Node n)
          get the node type as text
static java.lang.String getNodeValue(org.w3c.dom.Node n)
          return the value of a node
static boolean hasAttribute(org.w3c.dom.Node xml, java.lang.String attribute)
          return true if a node contains an attribute
static org.w3c.dom.Document parse(java.lang.String xml)
          parse an xml string into a org.w3c.dom.Document object
static java.lang.String preprocess(java.lang.String xml)
          preprocess and xml string, removing all leading and trailing whitespace from each line, and removing carriage returns and newlines from each line except where they fall within a CDATA section.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

flatten

public static final java.lang.String flatten(org.w3c.dom.Node xml)
flatten an XML node into a string (reverse parse?)


getAttributeValue

public static final java.lang.String getAttributeValue(org.w3c.dom.Node xml,
                                                       java.lang.String attribute,
                                                       java.lang.String def)
                                                throws java.lang.Exception
get the value of an xml attribute. For example, given:
   something
 
calling getattribute(node, "att2", "blah") should return "test2"

Throws:
java.lang.Exception

getFirstChildElementValue

public static final java.lang.String getFirstChildElementValue(org.w3c.dom.Element e,
                                                               java.lang.String elemName)
get the 'first child' element value of an element


getNamedNode

public static final org.w3c.dom.Node getNamedNode(org.w3c.dom.Node node,
                                                  java.lang.String name)
get the first node with a specified name


getNodesByName

public static final java.util.List getNodesByName(org.w3c.dom.Node node,
                                                  java.lang.String name)
get a list of XML nodes based upon their nodename


getNodeValue

public static final java.lang.String getNodeValue(org.w3c.dom.Node n)
return the value of a node


getNodeType

public static final java.lang.String getNodeType(org.w3c.dom.Node n)
get the node type as text


hasAttribute

public static final boolean hasAttribute(org.w3c.dom.Node xml,
                                         java.lang.String attribute)
                                  throws java.lang.Exception
return true if a node contains an attribute

Throws:
java.lang.Exception

parse

public static final org.w3c.dom.Document parse(java.lang.String xml)
                                        throws org.xml.sax.SAXException,
                                               java.io.IOException
parse an xml string into a org.w3c.dom.Document object

Throws:
org.xml.sax.SAXException
java.io.IOException

preprocess

public static final java.lang.String preprocess(java.lang.String xml)
                                         throws java.lang.Exception
preprocess and xml string, removing all leading and trailing whitespace from each line, and removing carriage returns and newlines from each line except where they fall within a CDATA section.

Throws:
java.lang.Exception