issrg.utils.xml
Class XMLUtils

java.lang.Object
  extended by issrg.utils.xml.XMLUtils

public final class XMLUtils
extends java.lang.Object

Class containing utility methods for working with XML documents. Some useful operations which may eliminate certain repetitive constructs from the code are defined.

Author:
sfl

Method Summary
static java.util.List<java.util.List<java.lang.String>> getAttributeValuesOnChildren(org.w3c.dom.Element element, java.lang.String childName, java.lang.Iterable<java.lang.String> attributeNames)
          Gets the values of specified attributes on child elements specified by name.
static java.lang.String[] getAttributeValuesOnChildren(org.w3c.dom.Element element, java.lang.String childName, java.lang.String attributeName)
          Return an array of values of attributes specified by attributeName on all the element children of the Element element that have the name "childName".
static boolean isElement(org.w3c.dom.Node n)
          Helper method to test whether a node is an element.
static void setAttributesOnChildElements(org.w3c.dom.Document document, org.w3c.dom.Element parentElement, java.lang.String[] attValues, java.lang.String childElementName, java.lang.String childAttName)
          Sets the values of attributes with name childAttName on child elements of parentElement with name childElementName to values specified in the array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getAttributeValuesOnChildren

public static java.lang.String[] getAttributeValuesOnChildren(org.w3c.dom.Element element,
                                                              java.lang.String childName,
                                                              java.lang.String attributeName)
Return an array of values of attributes specified by attributeName on all the element children of the Element element that have the name "childName".

Parameters:
element - The parent element to search
childName - The name of child elements to process
attributeName - The attribute name on a child element to include in the result
Returns:
array of values of attributes specified by attributeName on all the element children with name "childName" of Element specified by element

getAttributeValuesOnChildren

public static java.util.List<java.util.List<java.lang.String>> getAttributeValuesOnChildren(org.w3c.dom.Element element,
                                                                                            java.lang.String childName,
                                                                                            java.lang.Iterable<java.lang.String> attributeNames)
Gets the values of specified attributes on child elements specified by name. The method returns a two dimensional List of String. Each row corresponds to the attribute values on one child element. The values of each row are in the same order as specified by the list attributeNames. If an attribute is missing, then the empty string is given as its value.

Parameters:
element - the parent element
childName - the name of the child element for which certain attribute values should be collected
attributeNames - a List of attribute names
Returns:

setAttributesOnChildElements

public static void setAttributesOnChildElements(org.w3c.dom.Document document,
                                                org.w3c.dom.Element parentElement,
                                                java.lang.String[] attValues,
                                                java.lang.String childElementName,
                                                java.lang.String childAttName)
Sets the values of attributes with name childAttName on child elements of parentElement with name childElementName to values specified in the array. Note that all previously declared child elements with that name are discarded to simulate the behaviour of an attribute.

Parameters:
document - The Document to which the elements in question belong
parentElement - the element to create child elements on
attValues - the values of the attributes
childElementName - the name of child elements to create
childAttName - the name of the attribute used. This will be set to the appropriate value from the array

isElement

public static boolean isElement(org.w3c.dom.Node n)
Helper method to test whether a node is an element.

Parameters:
n - Node to test
Returns:
whether a node is an element