Package org.dspace.app.util
Class XMLUtils
- java.lang.Object
-
- org.dspace.app.util.XMLUtils
-
public class XMLUtils extends Object
Simple class to read information from small XML using DOM manipulation- Author:
- Andrea Bollini
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringgetElementAttribute(Element dataRoot, String name, String attr)static List<Element>getElementList(Element dataRoot, String name)static StringgetElementValue(Element dataRoot, String name)static List<String[]>getElementValueArrayList(Element rootElement, String subElementName, String... fieldsName)root/subElement[]/field1, field2, fieldNstatic List<String>getElementValueList(Element rootElement, String subElementName)static ElementgetSingleElement(Element dataRoot, String name)Return the first element child with the specified name
-
-
-
Method Detail
-
getElementList
public static List<Element> getElementList(Element dataRoot, String name)
- Parameters:
dataRoot- the starting nodename- the name of the subelement to find- Returns:
- the list of all DOM Element with the provided name direct child of the starting node
-
getElementAttribute
public static String getElementAttribute(Element dataRoot, String name, String attr)
- Parameters:
dataRoot- the starting nodename- the name of the sub elementattr- the attribute to get- Returns:
- the value of the attribute for the sub element with the specified name in the starting node
-
getElementValue
public static String getElementValue(Element dataRoot, String name)
- Parameters:
dataRoot- the starting nodename- the name of the sub element- Returns:
- the text content of the sub element with the specified name in the starting node
-
getSingleElement
public static Element getSingleElement(Element dataRoot, String name)
Return the first element child with the specified name- Parameters:
dataRoot- the starting nodename- the name of sub element to look for- Returns:
- the first child element or null if no present
-
getElementValueList
public static List<String> getElementValueList(Element rootElement, String subElementName)
- Parameters:
rootElement- the starting nodesubElementName- the name of the subelement to find- Returns:
- a list of string including all the text contents of the sub element with the specified name. If there are not sub element with the supplied name the method will return null
-
getElementValueArrayList
public static List<String[]> getElementValueArrayList(Element rootElement, String subElementName, String... fieldsName)
root/subElement[]/field1, field2, fieldN- Parameters:
rootElement- the starting nodesubElementName- the name of the sub element to work onfieldsName- the names of the sub-sub-elements from which get the text content- Returns:
- a list of array strings. The length of the array is equals to the number of fields required. For any fields the first textual value found in the sub element is used, null if no value is present
-
-