org.osesb.utilities.xml
Class DOMUtils

java.lang.Object
  extended by org.osesb.utilities.xml.DOMUtils

public class DOMUtils
extends java.lang.Object

Utilities for parsing with DOM.

Since:
Version .9

Constructor Summary
DOMUtils()
           
 
Method Summary
static org.w3c.dom.Element addChildElement(org.w3c.dom.Element parentElement, java.lang.String elementTagName, java.lang.String elementValue)
          Adds a new Element to the end of the list of children of the parentElement.
static org.w3c.dom.Attr createAttribute(java.lang.String name, java.lang.String value)
          Creates and returns a new, unattached Attribute with the given name and optional value.
static org.w3c.dom.Attr createAttribute(java.lang.String namespaceURI, java.lang.String name, java.lang.String value)
          Creates and returns a new, unattached Attribute with the given name, optional namespace, and optional value.
static org.w3c.dom.Element createElement(java.lang.String name)
          Creates and returns an empty, unattached Element with the given name.
static org.w3c.dom.Element createElement(java.lang.String namespaceURI, java.lang.String name)
          Creates and returns an empty, unattached Element with the given namespaceURI and name.
static org.w3c.dom.Element getChildElement(org.w3c.dom.Document document, java.lang.String elementName)
          Returns the first occurence of the XML element with elementName that is an immediate child of Document.
static org.w3c.dom.Element getChildElement(org.w3c.dom.Element parentElement)
          Returns the first immediate child Element of the parentElement.
static org.w3c.dom.Element getChildElement(org.w3c.dom.Element parentElement, java.lang.String elementName)
          Returns the first occurence of the XML element with elementName that is an immediate child of parentElement.
static org.w3c.dom.Element getChildElement(org.w3c.dom.Element parentElement, java.lang.String elementName, java.lang.String attributeName, java.lang.String attributeValue)
          Returns the first occurence of a XML element, with a specified attribute, that is an immediate child of parentElement.
static java.util.List getChildElementsAsList(org.w3c.dom.Element element)
          Returns all the immediate child Elements of an Element as a List of DOM Elements.
static java.util.List getChildElementsAsList(org.w3c.dom.Element element, java.lang.String elementTagName)
          Returns all the named immediate child Elements of an Element as a List of DOM Elements.
static java.util.Map getChildElementsAsMap(org.w3c.dom.Element element)
          Returns all the immediate child Elements of an Element, including attributes, as a Map of DOM EElements, keyed by the Element's tag name.
static org.w3c.dom.Document getDocument(org.w3c.dom.Node node)
          Returns the Document node that contains node.
static org.w3c.dom.Element getElement(org.w3c.dom.Document document, java.lang.String elementName)
          Returns the first occurence of the named XML element that is encountered in a preorder traversal of parentElement.
static org.w3c.dom.Element getElement(org.w3c.dom.Document document, java.lang.String elementName, int index)
          Returns the n'th occurence of a named XML element that is encountered in a preorder traversal of parentElement.
static org.w3c.dom.Element getElement(org.w3c.dom.Element parentElement, java.lang.String elementName)
          Returns the first occurence of the named XML element with elementName that is encountered in a preorder traversal of parentElement.
static org.w3c.dom.Element getElement(org.w3c.dom.Element parentElement, java.lang.String elementName, int index)
          Returns the n'th occurence of the XML element with elementName that is encountered in a preorder traversal of parentElement.
static org.w3c.dom.Element getElement(org.w3c.dom.Element parentElement, java.lang.String elementName, java.lang.String attributeName, java.lang.String attributeValue)
          Returns the first occurence of a XML element, with a specified attribute, that is encountered in a preorder traversal of parentElement.
static org.w3c.dom.Attr[] getElementAttributes(org.w3c.dom.Element element)
          Returns attributes of an Element as an array of org.w3c.dom.Attr
static java.util.Properties getElementAttributesAsProperties(org.w3c.dom.Element element)
          Returns the attributes of an Element as Properties
static java.lang.String getElementAttributeValue(org.w3c.dom.Element element, java.lang.String attributeName)
          Returns the value for an Attribute of an Element.
static java.lang.String getElementValue(org.w3c.dom.Element element)
          Returns the text value of a XML element.
static java.lang.String getNodeValue(org.w3c.dom.Node node)
          Returns the text value of a XML Node.
static boolean isElementEmpty(org.w3c.dom.Element element)
          Tests if a Element is empty.
static void main(java.lang.String[] args)
          Main method for testing and sandboxing.
static org.w3c.dom.Document parseDOM(java.lang.String xmlText)
          Parse a document using a JAXP-compliant DOM parser and JAXP parser default properties.
static org.w3c.dom.Document parseDOM(java.lang.String xmlText, boolean namespaceAware)
          Parse a document using a JAXP-compliant DOM parser, specifying the namespaceAware attribute for the parser.
static org.w3c.dom.Document parseDOM(java.lang.String xmlText, boolean namespaceAware, boolean validating, java.lang.String schemaLanguage, java.io.File[] schemaSource, org.xml.sax.ErrorHandler errorHandler)
          Parse a document using a JAXP-compliant DOM parser specifying factory and parser attributes and passing a File[] of schemaSource(s).
static org.w3c.dom.Document parseDOM(java.lang.String xmlText, boolean namespaceAware, boolean validating, java.lang.String schemaLanguage, java.lang.Object schemaSource, org.xml.sax.ErrorHandler errorHandler)
          Parse a document using a JAXP-compliant DOM parser specifying factory and parser attributes and passing a single schema source.
static org.w3c.dom.Document parseDOM(java.lang.String xmlText, org.xml.sax.EntityResolver entityResolver)
          Parse a document using a JAXP-compliant DOM parser using an EntityResolver to handle external entities.
static org.w3c.dom.Document parseDOM(java.lang.String xmlText, org.xml.sax.EntityResolver entityResolver, boolean namespaceAware, boolean validating, java.lang.String schemaLanguage, org.xml.sax.ErrorHandler errorHandler)
          Parse a document using a JAXP-compliant DOM parser specifying common factory and parser attributes and passing a File[] of schemaSource(s).
static org.w3c.dom.Document parseDOM(java.lang.String xmlText, java.io.File[] schemaSource)
          Parse a document using a JAXP-compliant DOM parser specifying factory and parser attributes and passing a File[] of schemaSource(s).
static org.w3c.dom.Document parseDOM(java.lang.String xmlText, java.lang.Object schemaSource)
          Parse a document using a JAXP-compliant DOM parser with namespaceaware=true, validating=true, schemaLanguage = XML Schema, and passing a schema source.
static org.w3c.dom.Document parseDOM(java.lang.String xmlText, javax.xml.validation.Schema schema)
          Parse a document using a JAXP-compliant DOM parser and a compiled Schema
static org.w3c.dom.Document parseDOM(java.lang.String xmlText, javax.xml.validation.Schema schema, org.xml.sax.ErrorHandler errorHandler)
          Parse a document using a JAXP-compliant DOM parser with validation against a compiled Schema
static org.w3c.dom.Element removeElement(org.w3c.dom.Element element)
          Removes the Element from the DOM tree.
static void setDocumentBuilderAttributes(javax.xml.parsers.DocumentBuilderFactory dbf, boolean namespaceAware, boolean validating, java.lang.String schemaLanguage)
          Set DocumentBuilderFactory attributes
static void setElementValue(org.w3c.dom.Element element, java.lang.String value)
          Sets the Svalue of a XML element.
static void setExternalSchemaLocation(javax.xml.parsers.DocumentBuilderFactory dbf, java.io.File[] schemaSource, java.lang.String xmlText)
          This is method sets the http://apache.org/xml/properties/schema/external-schemaLocation or http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation for a Xerces parser using schemaSources specified as a java.io.File[].
static void setNodeValue(org.w3c.dom.Node node, java.lang.String value)
          Sets the text value of a XML Node.
static boolean validSchemaSource(java.lang.Object schemaSource)
          Validates the schema source for a DocumentBuilderFactory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DOMUtils

public DOMUtils()
Method Detail

parseDOM

public static org.w3c.dom.Document parseDOM(java.lang.String xmlText)
                                     throws javax.xml.parsers.ParserConfigurationException,
                                            java.io.IOException,
                                            org.xml.sax.SAXException,
                                            java.lang.Exception
Parse a document using a JAXP-compliant DOM parser and JAXP parser default properties.

Parameters:
xmlText - The XML String to parse.
Throws:
org.xml.sax.SAXException
javax.xml.parsers.ParserConfigurationException
java.io.IOException
java.lang.Exception

parseDOM

public static org.w3c.dom.Document parseDOM(java.lang.String xmlText,
                                            boolean namespaceAware)
                                     throws org.xml.sax.SAXException,
                                            javax.xml.parsers.ParserConfigurationException,
                                            java.io.IOException,
                                            java.lang.Exception
Parse a document using a JAXP-compliant DOM parser, specifying the namespaceAware attribute for the parser.

Parameters:
xmlText - The XML String to parse
Throws:
org.xml.sax.SAXException
javax.xml.parsers.ParserConfigurationException
java.io.IOException
java.lang.Exception

parseDOM

public static org.w3c.dom.Document parseDOM(java.lang.String xmlText,
                                            java.lang.Object schemaSource)
                                     throws org.xml.sax.SAXException,
                                            javax.xml.parsers.ParserConfigurationException,
                                            java.io.IOException,
                                            java.lang.Exception
Parse a document using a JAXP-compliant DOM parser with namespaceaware=true, validating=true, schemaLanguage = XML Schema, and passing a schema source.

Parameters:
xmlText - The XML String to parse
schemaSource - any JAXP_SCHEMA_SOURCE
Throws:
org.xml.sax.SAXException
javax.xml.parsers.ParserConfigurationException
java.io.IOException
java.lang.Exception

parseDOM

public static org.w3c.dom.Document parseDOM(java.lang.String xmlText,
                                            java.io.File[] schemaSource)
                                     throws org.xml.sax.SAXException,
                                            javax.xml.parsers.ParserConfigurationException,
                                            java.io.IOException,
                                            java.lang.Exception
Parse a document using a JAXP-compliant DOM parser specifying factory and parser attributes and passing a File[] of schemaSource(s).

Parameters:
xmlText - The XML String to parse
schemaSource - File[] of schema sources
Throws:
org.xml.sax.SAXException
javax.xml.parsers.ParserConfigurationException
java.io.IOException
java.lang.Exception

parseDOM

public static org.w3c.dom.Document parseDOM(java.lang.String xmlText,
                                            boolean namespaceAware,
                                            boolean validating,
                                            java.lang.String schemaLanguage,
                                            java.lang.Object schemaSource,
                                            org.xml.sax.ErrorHandler errorHandler)
                                     throws org.xml.sax.SAXException,
                                            javax.xml.parsers.ParserConfigurationException,
                                            java.io.IOException,
                                            java.lang.Exception
Parse a document using a JAXP-compliant DOM parser specifying factory and parser attributes and passing a single schema source.

Note: Setting the DocumentBuilderFactory property XMLParserConstants.JAXP_SCHEMA_SOURCE works consistently for a single schema source, but not for multiple schema sources, such as included schemas.

For multiple schema sources, use the method that takes the schemaSources as a File[].

Alternatively, use the method that accepts an EntityResolver. Using an EntityResolver is a more consistent approach to resolving schema locations.

Parameters:
xmlText - xml String to parse
namespaceAware - If true then DocumentBuilderFactory is configured to produce parsers which are namespace aware
validating - If true then DocumentBuilderFactory is configured to produce parsers which validate the XML content during parse
schemaLanguage - XMLParserConstants.SCHEMA_LANGUAGE_XSD or XMLParserConstants.SCHEMA_LANGUAGE_DTD
schemaSource - Any XMLParserConstants.JAXP_SCHEMA_SOURCE
errorHandler - An error handler
Throws:
org.xml.sax.SAXException
javax.xml.parsers.ParserConfigurationException
java.io.IOException
java.lang.Exception

parseDOM

public static org.w3c.dom.Document parseDOM(java.lang.String xmlText,
                                            boolean namespaceAware,
                                            boolean validating,
                                            java.lang.String schemaLanguage,
                                            java.io.File[] schemaSource,
                                            org.xml.sax.ErrorHandler errorHandler)
                                     throws org.xml.sax.SAXException,
                                            javax.xml.parsers.ParserConfigurationException,
                                            java.io.IOException,
                                            java.lang.Exception
Parse a document using a JAXP-compliant DOM parser specifying factory and parser attributes and passing a File[] of schemaSource(s).

This method uses an alternative to setting the DocumentBuilderFactory property XMLParserConstants.JAXP_SCHEMA_SOURCE, which does not work for multiple schemas. Instead, this method sets the Xerces property "http://apache.org/xml/properties/schema/external-schemaLocation" OR "http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation", depending on whether or not the document has a namespace. This approach works for multiple schemas.

Note that setting these Xerces properties does not appear to work in earlier versions of the Xerces parser that might be encountered in J2EE environments.

Alternatively, use the method that accepts an EntityResolver. Using an EntityResolver is a more consistent approach to resolving schema locations.

Parameters:
xmlText - xml String to parse
namespaceAware - If true then DocumentBuilderFactory is configured to produce parsers which are namespace aware
validating - If true then DocumentBuilderFactory is configured to produce parsers which validate the XML content during parse
schemaLanguage - XMLParserConstants.SCHEMA_LANGUAGE_XSD or XMLParserConstants.SCHEMA_LANGUAGE_DTD
schemaSource - a File[] of schema sources
errorHandler - An error handler
Throws:
org.xml.sax.SAXException
javax.xml.parsers.ParserConfigurationException
java.io.IOException
java.lang.Exception

parseDOM

public static org.w3c.dom.Document parseDOM(java.lang.String xmlText,
                                            org.xml.sax.EntityResolver entityResolver)
                                     throws org.xml.sax.SAXException,
                                            javax.xml.parsers.ParserConfigurationException,
                                            java.io.IOException,
                                            java.lang.Exception
Parse a document using a JAXP-compliant DOM parser using an EntityResolver to handle external entities.

This method uses an EntityResolver to resolve external entities. This method is the preferred way of resolving schema locations over setting the XMLParserConstants.JAXP_SCHEMA_SOURCE DocumentBuilderFactory property or the Xerces properties, "http://apache.org/xml/properties/schema/external-schemaLocation" OR "http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation".

It is the most consistent approach and should work in many Java & J2EE configurations.

Parameters:
xmlText - xml String to parse
entityResolver - Implements org.xml.sax.EntityResolver.
Throws:
org.xml.sax.SAXException
javax.xml.parsers.ParserConfigurationException
java.io.IOException
java.lang.Exception

parseDOM

public static org.w3c.dom.Document parseDOM(java.lang.String xmlText,
                                            org.xml.sax.EntityResolver entityResolver,
                                            boolean namespaceAware,
                                            boolean validating,
                                            java.lang.String schemaLanguage,
                                            org.xml.sax.ErrorHandler errorHandler)
                                     throws org.xml.sax.SAXException,
                                            javax.xml.parsers.ParserConfigurationException,
                                            java.io.IOException,
                                            java.lang.Exception
Parse a document using a JAXP-compliant DOM parser specifying common factory and parser attributes and passing a File[] of schemaSource(s).

This method uses an EntityResolver to resolve schema locations. This method is preferred over setting the XMLParserConstants.JAXP_SCHEMA_SOURCE DocumentBuilderFactory property or the Xerces properties, "http://apache.org/xml/properties/schema/external-schemaLocation" OR "http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation".

It is the most consistent approach and should work in many Java & J2EE configurations.

Parameters:
xmlText - xml String to parse
entityResolver - Implements org.xml.sax.EntityResolver.
namespaceAware - If true then DocumentBuilderFactory is configured to produce parsers which are namespace aware
validating - If true then DocumentBuilderFactory is configured to produce parsers which validate the XML content during parse
schemaLanguage - XMLParserConstants.SCHEMA_LANGUAGE_XSD or XMLParserConstants.SCHEMA_LANGUAGE_DTD
errorHandler - An error handler
Throws:
org.xml.sax.SAXException
javax.xml.parsers.ParserConfigurationException
java.io.IOException
java.lang.Exception

parseDOM

public static org.w3c.dom.Document parseDOM(java.lang.String xmlText,
                                            javax.xml.validation.Schema schema)
                                     throws org.xml.sax.SAXException,
                                            javax.xml.parsers.ParserConfigurationException,
                                            java.io.IOException,
                                            java.lang.Exception
Parse a document using a JAXP-compliant DOM parser and a compiled Schema

Parameters:
xmlText - The XML String to parse
schema - a jaxp v1.3 compiled schema
Throws:
org.xml.sax.SAXException
javax.xml.parsers.ParserConfigurationException
java.io.IOException
java.lang.Exception

parseDOM

public static org.w3c.dom.Document parseDOM(java.lang.String xmlText,
                                            javax.xml.validation.Schema schema,
                                            org.xml.sax.ErrorHandler errorHandler)
                                     throws org.xml.sax.SAXException,
                                            javax.xml.parsers.ParserConfigurationException,
                                            java.io.IOException,
                                            java.lang.Exception
Parse a document using a JAXP-compliant DOM parser with validation against a compiled Schema

Parameters:
xmlText - The XML String to parse
schema - a jaxp v1.3 compiled schema
errorHandler - An error handler
Throws:
org.xml.sax.SAXException
javax.xml.parsers.ParserConfigurationException
java.io.IOException
java.lang.Exception

getDocument

public static org.w3c.dom.Document getDocument(org.w3c.dom.Node node)
Returns the Document node that contains node.


setDocumentBuilderAttributes

public static void setDocumentBuilderAttributes(javax.xml.parsers.DocumentBuilderFactory dbf,
                                                boolean namespaceAware,
                                                boolean validating,
                                                java.lang.String schemaLanguage)
                                         throws java.lang.Exception
Set DocumentBuilderFactory attributes

Parameters:
namespaceAware - If true then DocumentBuilderFactory is configured to produce parsers which are namespace aware
validating - If true then DocumentBuilderFactory is configured to produce parsers which validate the XML content during parse
schemaLanguage - XMLParserConstants.SCHEMA_LANGUAGE_XSD or XMLParserConstants.SCHEMA_LANGUAGE_DTD
Throws:
java.lang.Exception

validSchemaSource

public static boolean validSchemaSource(java.lang.Object schemaSource)
Validates the schema source for a DocumentBuilderFactory.

Parameters:
schemaSource - The JAXP_SCHEMA_SOURCE.

setExternalSchemaLocation

public static void setExternalSchemaLocation(javax.xml.parsers.DocumentBuilderFactory dbf,
                                             java.io.File[] schemaSource,
                                             java.lang.String xmlText)
This is method sets the http://apache.org/xml/properties/schema/external-schemaLocation or http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation for a Xerces parser using schemaSources specified as a java.io.File[].

For namespaced schema locations, each schema location must be specified as a URL, just like the XML schemaLocation attribute. For example, "http://www.altova.com/IPO file:/d:/xml-repository/ipo.xsd". More than one XML Schema can be specified.

For schema locations specified without a namespace, the syntax is a same as for the noNamespaceSchemaLocation attribute in an instance document (e.g."file_name.xsd"). Only one XML Schema can be specified.

Parameters:
dbf - The DocumentBuilderFactory to set the schema locations for.
schemaSource - an array of java.io.File.
xmlText - The XML text that is being parsed/validated.

addChildElement

public static org.w3c.dom.Element addChildElement(org.w3c.dom.Element parentElement,
                                                  java.lang.String elementTagName,
                                                  java.lang.String elementValue)
                                           throws java.lang.Exception
Adds a new Element to the end of the list of children of the parentElement.

Parameters:
parentElement - The Element to add a new child Element to.
elementTagName - The tag name for the new Element.
elementValue - The value for the new Element.
Returns:
the Element that was added.
Throws:
java.lang.Exception - if the Element could not be added.

removeElement

public static org.w3c.dom.Element removeElement(org.w3c.dom.Element element)
                                         throws java.lang.Exception
Removes the Element from the DOM tree.

Parameters:
element - The Element to remove.
Returns:
the Element that was removed.
Throws:
java.lang.Exception - if the Element could not be removed.

getChildElement

public static org.w3c.dom.Element getChildElement(org.w3c.dom.Document document,
                                                  java.lang.String elementName)
Returns the first occurence of the XML element with elementName that is an immediate child of Document.

Parameters:
document - The Document
elementName - The Element name to look for, including the namespace prefix, if any.
Returns:
the Element that was found.

getChildElement

public static org.w3c.dom.Element getChildElement(org.w3c.dom.Element parentElement)
Returns the first immediate child Element of the parentElement.

Parameters:
parentElement - The parent Element
Returns:
the first child Element.

getChildElement

public static org.w3c.dom.Element getChildElement(org.w3c.dom.Element parentElement,
                                                  java.lang.String elementName)
Returns the first occurence of the XML element with elementName that is an immediate child of parentElement.

Parameters:
parentElement - The parent Element
elementName - The Element name to look for, including the namespace prefix, if any.
Returns:
the Element that was found.

getChildElement

public static org.w3c.dom.Element getChildElement(org.w3c.dom.Element parentElement,
                                                  java.lang.String elementName,
                                                  java.lang.String attributeName,
                                                  java.lang.String attributeValue)
Returns the first occurence of a XML element, with a specified attribute, that is an immediate child of parentElement.

Parameters:
parentElement - The parent Element
elementName - The Element name to look for, including the namespace prefix, if any.
attributeName - The Attribute name to look for.
attributeValue - The Attribute value to look for.
Returns:
the Element that was found.

getChildElementsAsMap

public static java.util.Map getChildElementsAsMap(org.w3c.dom.Element element)
Returns all the immediate child Elements of an Element, including attributes, as a Map of DOM EElements, keyed by the Element's tag name.

Parameters:
element - The Element to get the children of.
Returns:
the child Elements of element as a Map of DOM Elements, keyed by Element names (tags)

getChildElementsAsList

public static java.util.List getChildElementsAsList(org.w3c.dom.Element element)
Returns all the immediate child Elements of an Element as a List of DOM Elements.

Parameters:
element - The Element to get the children of.
Returns:
the child Elements of an Element as a List of DOM Elements, in the order they were found.

getChildElementsAsList

public static java.util.List getChildElementsAsList(org.w3c.dom.Element element,
                                                    java.lang.String elementTagName)
Returns all the named immediate child Elements of an Element as a List of DOM Elements.

Parameters:
element - The Element to get the children of.
elementTagName - The tag name of the children, including the namespace prefix, if any.
Returns:
the named child Elements of an Element as a List of DOM Elements, in the order they were found.

getElement

public static org.w3c.dom.Element getElement(org.w3c.dom.Document document,
                                             java.lang.String elementName)
Returns the first occurence of the named XML element that is encountered in a preorder traversal of parentElement.

Parameters:
document - The DOM document to find the Element in.
elementName - The Element name to look for, including the namespace prefix, if any.
Returns:
the Element that was found.

getElement

public static org.w3c.dom.Element getElement(org.w3c.dom.Document document,
                                             java.lang.String elementName,
                                             int index)
Returns the n'th occurence of a named XML element that is encountered in a preorder traversal of parentElement.

Parameters:
document - The DOM document to find the Element in.
elementName - The Element name to look for, including the namespace prefix, if any.
index - The number of the occurence of the XML Element to return.
Returns:
the Element that was found.

getElement

public static org.w3c.dom.Element getElement(org.w3c.dom.Element parentElement,
                                             java.lang.String elementName)
Returns the first occurence of the named XML element with elementName that is encountered in a preorder traversal of parentElement.

Parameters:
parentElement - The parent Element
elementName - The Element name to look for, including the namespace prefix, if any.
Returns:
the Element that was found.

getElement

public static org.w3c.dom.Element getElement(org.w3c.dom.Element parentElement,
                                             java.lang.String elementName,
                                             int index)
Returns the n'th occurence of the XML element with elementName that is encountered in a preorder traversal of parentElement.

Parameters:
parentElement - The parent Element
elementName - The Element name to look for, including the namespace prefix, if any.
index - The index of the Element to return.
Returns:
the Element that was found.

getElement

public static org.w3c.dom.Element getElement(org.w3c.dom.Element parentElement,
                                             java.lang.String elementName,
                                             java.lang.String attributeName,
                                             java.lang.String attributeValue)
Returns the first occurence of a XML element, with a specified attribute, that is encountered in a preorder traversal of parentElement.

Parameters:
parentElement - The parent Element
elementName - The Element name to look for, including the namespace prefix, if any.
attributeName - The Attribute name to look for.
attributeValue - The Attribute value to look for.
Returns:
the Element that was found.

isElementEmpty

public static boolean isElementEmpty(org.w3c.dom.Element element)
Tests if a Element is empty. A Element is empty if it has no children, no value, and no attributes.

Parameters:
element - The XML Element to test.
Returns:
true if the Element is empty, false if it is not.

getNodeValue

public static java.lang.String getNodeValue(org.w3c.dom.Node node)
Returns the text value of a XML Node.

Parameters:
node - The XML Node to get the value of.
Returns:
the value of the XML Node as a String.

setNodeValue

public static void setNodeValue(org.w3c.dom.Node node,
                                java.lang.String value)
Sets the text value of a XML Node.

Parameters:
node - element The XML Node to set the value of.
value - The String value to set.

getElementValue

public static java.lang.String getElementValue(org.w3c.dom.Element element)
Returns the text value of a XML element.

Parameters:
element - The XML Element to get the value of.
Returns:
the value of the XML Element as a String.

setElementValue

public static void setElementValue(org.w3c.dom.Element element,
                                   java.lang.String value)
Sets the Svalue of a XML element.

Parameters:
element - The XML Element to set the value of.
value - The String value to set.

getElementAttributes

public static org.w3c.dom.Attr[] getElementAttributes(org.w3c.dom.Element element)
Returns attributes of an Element as an array of org.w3c.dom.Attr

Parameters:
element - The XML Element to get the attributes of.
Returns:
an array of org.w3c.dom.Attr.

getElementAttributesAsProperties

public static java.util.Properties getElementAttributesAsProperties(org.w3c.dom.Element element)
Returns the attributes of an Element as Properties

Parameters:
element - The XML Element to get the attributes of.
Returns:
The names / values pairs of the attributes as Properties.

getElementAttributeValue

public static java.lang.String getElementAttributeValue(org.w3c.dom.Element element,
                                                        java.lang.String attributeName)
Returns the value for an Attribute of an Element.

Parameters:
element - The document Element.
attributeName - The name of the attribute to get the value of.
Returns:
the value of the attribute as a String.

createElement

public static org.w3c.dom.Element createElement(java.lang.String name)
                                         throws java.lang.Exception
Creates and returns an empty, unattached Element with the given name. The new Element is associated with a new Document that is used to create the Element.

This method is used to create Elements when a Document is not readily available and the Element is for copying into a Document using Document#importNode. For example, see org.osesb.utilities.xpath.jxpath.XMLDataUpdater, which includes a method that will add Elements to target Elements using XPath expressions for the target Elements.

Parameters:
name - The name for the Element.
Returns:
A new empty Element.
Throws:
java.lang.Exception - if an error is encountered while creating the Element.

createElement

public static org.w3c.dom.Element createElement(java.lang.String namespaceURI,
                                                java.lang.String name)
                                         throws java.lang.Exception
Creates and returns an empty, unattached Element with the given namespaceURI and name. The new Element is associated with a new Document that is used to create the Element.

This method is used to create Elements when a Document is not readily available and the Element is for copying into a Document using Document#importNode. For example, see org.osesb.utilities.xpath.jxpath.XMLDataUpdater, which includes a method that will add Elements to target Elements using XPath expressions for the target Elements.

Parameters:
name - The name for the Element.
Returns:
A new empty Element.
Throws:
java.lang.Exception - if an error is encountered while creating the Element.

createAttribute

public static org.w3c.dom.Attr createAttribute(java.lang.String name,
                                               java.lang.String value)
                                        throws java.lang.Exception
Creates and returns a new, unattached Attribute with the given name and optional value. The new Attribute is associated with a new Document that is used to create the Attribute.

This method is used to create Attribbutes when a Document is not readily available and the Attribute is for copying into Document Elements using Document#importNode. For example, see org.osesb.utilities.xpath.jxpath.XMLDataUpdater, which includes a method that will add Attributes to target Elements using XPath expressions for the target Attributes.

Parameters:
name - The name for the Element.
value - An optional value for the Attribute.
Returns:
A new unattached Attribute
Throws:
java.lang.Exception - if an error is encountered while creating the Element.

createAttribute

public static org.w3c.dom.Attr createAttribute(java.lang.String namespaceURI,
                                               java.lang.String name,
                                               java.lang.String value)
                                        throws java.lang.Exception
Creates and returns a new, unattached Attribute with the given name, optional namespace, and optional value. The new Attribute is associated with a new Document that is used to create the Attribute.

This method is used to create Attribbutes when a Document is not readily available and the Attribute is for copying into Document Elements using Document#importNode. For example, see org.osesb.utilities.xpath.jxpath.XMLDataUpdater, which includes a method that will add Attributes to target Elements using XPath expressions for the target Attributes.

Parameters:
namespaceURI - An optional namespaceURI for the Attribute.
name - The name for the Element.
value - An optional value for the Attribute.
Returns:
A new unattached Attribute
Throws:
java.lang.Exception - if an error is encountered while creating the Element.

main

public static void main(java.lang.String[] args)
Main method for testing and sandboxing.