xml
Class DOMHelper

java.lang.Object
  extended by xml.DOMHelper

public class DOMHelper
extends Object

A class consisting of helper methods for dealing with DOMS.


Constructor Summary
DOMHelper()
           
 
Method Summary
static Element addTextNode(Element parent, String text)
          Adds a single text node to this element.
static List<String> getStringsFromElements(List<Node> scan)
          Converts a list of elements that have a text node as their first child to a list of the text values of these child nodes.
static List<String> getTextElementContent(Node xml, String tagname)
          Scans the DOM for all occurences of the element with the given name.
static List<Node> getTextElements(Node xml, String tagname)
          Scans the DOM for all occurrences of elements with the given tag name.
static String singleAttribute(Node xml, String tag, String att)
          Scans the node for the sole occurence of the stated element.
static Element singleElement(Node xml, String tagname)
          Scans the node for the occurence of the given element.
static String singleText(Node xml, String tagname)
          Scans the node for the occurrence of the given element.
static String toElementName(String upper)
          Converts a string into a typical element notation, thus to lower case except the starting char.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DOMHelper

public DOMHelper()
Method Detail

singleText

public static final String singleText(Node xml,
                                      String tagname)
Scans the node for the occurrence of the given element. If the element is found and present only once and has a text node as the first child, the value of this text node is trimmed and returned. If this is not fulfilled, null is returned.

Parameters:
xml - Either an Element or a Document

toElementName

public static final String toElementName(String upper)
Converts a string into a typical element notation, thus to lower case except the starting char.


singleElement

public static final Element singleElement(Node xml,
                                          String tagname)
Scans the node for the occurence of the given element. If it is present only once, this element is returned, otherwise null is returned.


singleAttribute

public static final String singleAttribute(Node xml,
                                           String tag,
                                           String att)
Scans the node for the sole occurence of the stated element. The atrribute stated to this element is returned.


getTextElements

public static final List<Node> getTextElements(Node xml,
                                               String tagname)
Scans the DOM for all occurrences of elements with the given tag name. If the element found has a text node as its first child, this element is stored in the returned list.

Returns:
A list of elements or an empty list.

getStringsFromElements

public static final List<String> getStringsFromElements(List<Node> scan)
Converts a list of elements that have a text node as their first child to a list of the text values of these child nodes.

Returns:
A list of strings or an empty list.

getTextElementContent

public static final List<String> getTextElementContent(Node xml,
                                                       String tagname)
Scans the DOM for all occurences of the element with the given name. All elements found whose first child node is a text node contribute its text value to the list of returned items.
This public method calls the methods getTextElements(org.w3c.dom.Node, java.lang.String) and getStringsFromElements(java.util.List).

Returns:
A list of strings or an empty list.

addTextNode

public static final Element addTextNode(Element parent,
                                        String text)
Adds a single text node to this element. The text node is filled with the value supplied and added as the last child to the element. The element is then returned.