com.cafesoft.core.xml.dom
Class XmlDomUtils

java.lang.Object
  |
  +--com.cafesoft.core.xml.dom.XmlDomUtils

public class XmlDomUtils
extends Object

Provides static methods for handling XML Document Object Mode (DOM) trees.

Since:
11/7/01

Constructor Summary
XmlDomUtils()
           
 
Method Summary
static Element getChildElementByTagName(Element parent, String tagName)
          Get a single child Element by tag name.
static NodeList getChildElementNodes(Element parent)
          Get Node children that are Elements.
static List getChildElementsByTagName(Element parent, String tagName)
          Get all child Elements by tag name.
static String getChildTextData(Element parent)
          Get the data associated with a Text node within a parent Element.
static boolean nameSpaceURIMatches(Node node1, Node node2)
          Return true if the namespace of the two Nodes matches.
static Document parseDocument(Reader reader)
          Parse the Document Object Model (DOM) from a reader.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XmlDomUtils

public XmlDomUtils()
Method Detail

parseDocument

public static Document parseDocument(Reader reader)
                              throws IOException,
                                     SAXException,
                                     ParserConfigurationException
Parse the Document Object Model (DOM) from a reader.

If validation is desired, set the following System property: System.setProperty("validateXML", "true")

Parameters:
reader - the Reader from which the XML data is available.
Returns:
a loaded XML DOM Document.
Throws:
IOException - if an error reading the XML data.
SAXException - if an error parsing the XML data.
ParserConfigurationException - if JAXP is unable to configure a suitable Parser.

getChildElementByTagName

public static Element getChildElementByTagName(Element parent,
                                               String tagName)
Get a single child Element by tag name.

This method may be of use when a given parent is known to have one Element with the given tag name.

Parameters:
parent - the parent Element.
tagName - the tag name for the child Element.
Returns:
the first child Element of a parent Element with a given tag name. If more than one child Element with the given name, then the first child is returned. If no children with the given name, then null is returned.

getChildElementsByTagName

public static List getChildElementsByTagName(Element parent,
                                             String tagName)
Get all child Elements by tag name.

This method is of use when a given parent can have zero or more Elements with the given tag name.

Parameters:
parent - the parent Element.
tagName - the tag name for the child Element.
Returns:
a List of Element instances with the given tag name or an zero-length List if no Elements with the tag name.

getChildElementNodes

public static NodeList getChildElementNodes(Element parent)
Get Node children that are Elements.

This method returns a NodeList of all first-generation child Nodes that are of type: Node.ELEMENT_NODE.

Parameters:
parent - the parent Element.
Returns:
a NodeList of all child nodes of type: Node.ELEMENT_NODE

getChildTextData

public static String getChildTextData(Element parent)
Get the data associated with a Text node within a parent Element.

Parameters:
parent - the parent Element containing the Text node.
Returns:
the data associated with the first Text node within the specified parent Element. If the parent does not contain any Text nodes, then return null.

nameSpaceURIMatches

public static boolean nameSpaceURIMatches(Node node1,
                                          Node node2)
Return true if the namespace of the two Nodes matches.

Parameters:
node1 - the first Node.
node2 - the second Node.
Returns:
true if the namespace of the two Nodes matches. If neither Node is in a namespace, then return true.


Generated on 10:40:31 AM September 10, 2003, © 1996-2003 Cafésoft LLC. All rights reserved.