com.sfm.ap210.jsdai.utils
Class DomUtils

java.lang.Object
  extended by com.sfm.ap210.jsdai.utils.DomUtils

public abstract class DomUtils
extends java.lang.Object

Generic utility methods and helpers for dealing with DOM data


Constructor Summary
DomUtils()
           
 
Method Summary
static java.lang.Iterable<org.w3c.dom.Element> Children(org.w3c.dom.Element element)
          Get all child elements of the given element
static java.lang.Iterable<org.w3c.dom.Element> Children(org.w3c.dom.Node node, java.lang.String tag)
          Get all child elements of the given node with the given tag
static java.lang.Iterable<org.w3c.dom.Element> Descendents(org.w3c.dom.Element root, java.lang.String tag)
          Get all descendent elements of the given node with the given tag
static java.lang.Iterable<org.w3c.dom.Element> Elements(org.w3c.dom.Document dom, java.lang.String tag)
          Get all elements of the given document with the given tag
static org.w3c.dom.Element FirstDescendent(org.w3c.dom.Element root, java.lang.String tag)
          Get the first descendent node of the given element with the given tag
static org.w3c.dom.Element FirstElement(org.w3c.dom.Document dom, java.lang.String tag)
          Get the first element in the given docuemnt with the given tag
static org.w3c.dom.Document loadXML(java.io.File file)
          Load an XML file into a DOM structure from file
static org.w3c.dom.Document newDocument(java.lang.String root)
          Create a new DOM instance with the given root node
static java.lang.Iterable<org.w3c.dom.Node> NodeSequence(org.w3c.dom.NodeList nodes)
          Obtain an iterable view of the given NodeList
static java.util.List<org.w3c.dom.Element> Parents(org.w3c.dom.Element elem, java.lang.String tag)
          Get the parent elements of the given element with the given tag
static
<T> java.lang.Iterable<T>
Sequence(org.w3c.dom.NodeList nodes)
          Return an iterable view of the given NodeList with items of the given type
static void writeXML(org.w3c.dom.Document xml, java.io.File file)
          Write the DOM document to the provided file
 
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

NodeSequence

public static java.lang.Iterable<org.w3c.dom.Node> NodeSequence(org.w3c.dom.NodeList nodes)
Obtain an iterable view of the given NodeList

Parameters:
nodes -
Returns:

Sequence

public static <T> java.lang.Iterable<T> Sequence(org.w3c.dom.NodeList nodes)
Return an iterable view of the given NodeList with items of the given type

Type Parameters:
T -
Parameters:
nodes -
Returns:

Elements

public static java.lang.Iterable<org.w3c.dom.Element> Elements(org.w3c.dom.Document dom,
                                                               java.lang.String tag)
Get all elements of the given document with the given tag

Parameters:
dom -
tag -
Returns:

Children

public static java.lang.Iterable<org.w3c.dom.Element> Children(org.w3c.dom.Element element)
Get all child elements of the given element

Parameters:
element -
Returns:

Children

public static java.lang.Iterable<org.w3c.dom.Element> Children(org.w3c.dom.Node node,
                                                               java.lang.String tag)
Get all child elements of the given node with the given tag

Parameters:
node -
tag -
Returns:

Descendents

public static java.lang.Iterable<org.w3c.dom.Element> Descendents(org.w3c.dom.Element root,
                                                                  java.lang.String tag)
Get all descendent elements of the given node with the given tag

Parameters:
root -
tag -
Returns:

FirstDescendent

public static org.w3c.dom.Element FirstDescendent(org.w3c.dom.Element root,
                                                  java.lang.String tag)
Get the first descendent node of the given element with the given tag

Parameters:
root -
tag -
Returns:

FirstElement

public static org.w3c.dom.Element FirstElement(org.w3c.dom.Document dom,
                                               java.lang.String tag)
Get the first element in the given docuemnt with the given tag

Parameters:
dom -
tag -
Returns:

Parents

public static java.util.List<org.w3c.dom.Element> Parents(org.w3c.dom.Element elem,
                                                          java.lang.String tag)
Get the parent elements of the given element with the given tag

Parameters:
elem -
tag -
Returns:

loadXML

public static org.w3c.dom.Document loadXML(java.io.File file)
                                    throws org.xml.sax.SAXException,
                                           java.io.IOException
Load an XML file into a DOM structure from file

Parameters:
file -
Returns:
Throws:
org.xml.sax.SAXException
java.io.IOException

newDocument

public static org.w3c.dom.Document newDocument(java.lang.String root)
Create a new DOM instance with the given root node

Parameters:
root -
Returns:

writeXML

public static void writeXML(org.w3c.dom.Document xml,
                            java.io.File file)
                     throws java.io.IOException
Write the DOM document to the provided file

Parameters:
xml -
file -
Throws:
java.io.IOException