Package eu.woolplatform.utils.xml
Class XMLDocumentParser
- java.lang.Object
-
- eu.woolplatform.utils.xml.XMLDocumentParser
-
public class XMLDocumentParser extends Object
This class contains methods to read and validate data from an XML DOM.
-
-
Constructor Summary
Constructors Constructor Description XMLDocumentParser()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ElementgetChild(Element parent, String name)Returns the first child element with the specified name.<T> TparseAttrValue(Element elem, String name, XMLValueParser<T> parser, T defaultVal)Retrieves the value of the specified attribute and parses it using the specified parser.<T> TparseContent(Element elem, XMLValueParser<T> parser)Retrieves the string content of the specified element and parses it using the specified parser.<T> TparseElemValue(Element parent, String name, XMLValueParser<T> parser, T defaultVal)Retrieves the string content of the specified child element and parses it using the specified parser.<T> TparseRequiredAttrValue(Element elem, String name, XMLValueParser<T> parser)Retrieves the value of a required attribute and parses it using the specified parser.<T> TparseRequiredElemValue(Element parent, String name, XMLValueParser<T> parser)Retrieves the string content of a required child element and parses it using the specified parser.StringparseStringContent(Element elem)Parses the string content of the specified element.
-
-
-
Method Detail
-
parseElemValue
public <T> T parseElemValue(Element parent, String name, XMLValueParser<T> parser, T defaultVal) throws ParseException
Retrieves the string content of the specified child element and parses it using the specified parser. If the child element is not found, it returns the default value.- Type Parameters:
T- the value type- Parameters:
parent- the parent elementname- the name of the child elementparser- the parserdefaultVal- the default value- Returns:
- the parsed value or the default value
- Throws:
ParseException- if the string content of the child element is invalid- See Also:
parseStringContent(Element)
-
parseAttrValue
public <T> T parseAttrValue(Element elem, String name, XMLValueParser<T> parser, T defaultVal) throws ParseException
Retrieves the value of the specified attribute and parses it using the specified parser. If the attribute is not found, it returns the default value.- Type Parameters:
T- the value type- Parameters:
elem- the elementname- the name of the attributeparser- the parserdefaultVal- the default value- Returns:
- the parsed value or the default value
- Throws:
ParseException- if the attribute value is invalid
-
parseRequiredElemValue
public <T> T parseRequiredElemValue(Element parent, String name, XMLValueParser<T> parser) throws ParseException
Retrieves the string content of a required child element and parses it using the specified parser. If the child element is not found, it throws an exception.- Type Parameters:
T- the value type- Parameters:
parent- the parent elementname- the name of the child elementparser- the parser- Returns:
- the parsed value
- Throws:
ParseException- if the child element is not found or the string content of the child element is invalid- See Also:
parseStringContent(Element)
-
parseRequiredAttrValue
public <T> T parseRequiredAttrValue(Element elem, String name, XMLValueParser<T> parser) throws ParseException
Retrieves the value of a required attribute and parses it using the specified parser. If the attribute is not found, it throws an exception.- Type Parameters:
T- the value type- Parameters:
elem- the elementname- the name of the attributeparser- the parser- Returns:
- the parsed value
- Throws:
ParseException- if the attribute is not found or the attribute value is invalid
-
parseContent
public <T> T parseContent(Element elem, XMLValueParser<T> parser) throws ParseException
Retrieves the string content of the specified element and parses it using the specified parser.- Type Parameters:
T- the value type- Parameters:
elem- the elementparser- the parser- Returns:
- the parsed value
- Throws:
ParseException- if the string content is invalid- See Also:
parseStringContent(Element)
-
parseStringContent
public String parseStringContent(Element elem)
Parses the string content of the specified element. It will trim white space at the start and end. If the element contains other nodes than text nodes, then those nodes and any white space around them will be replaced by a single space.- Parameters:
elem- the element- Returns:
- the string content
-
-