Package africa.absa.inception.core.xml
Class XmlUtil
- java.lang.Object
-
- africa.absa.inception.core.xml.XmlUtil
-
public class XmlUtil extends Object
The XmlUtil class provides utility methods for working with XML documents.- Author:
- Marcus Portmann
-
-
Constructor Summary
Constructors Constructor Description XmlUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static DateasDate(XMLGregorianCalendar calendar)Converts a javax.xml.datatype.XMLGregorianCalendar instance to a java.util.Date instance.static XMLGregorianCalendarasXMLGregorianCalendar(Date date)Converts a java.util.Date instance to a javax.xml.datatype.XMLGregorianCalendar instance.static Optional<Element>getChildElement(Element element, String name)Returns the child element with the specified name for the specified element.static Optional<Boolean>getChildElementBoolean(Element element, String name)Returns the boolean value of the text content for the child element with the specified name for the specified element.static List<Element>getChildElements(Element element, String name)Returns the child elements with the specified name for the specified element.static Optional<String>getChildElementText(Element element, String name)Returns the text content for the child element with the specified name for the specified element.static QNamegetQName(Document document, String qname)Returns the javax.xml.namespace.QName instance for the specified QName.static QNamegetQName(Element element, String qname)Returns the javax.xml.namespace.QName instance for the specified QName.static booleanhasChildElement(Element element, String name)Returns true if the specified element has a child with the specified name or false otherwise.
-
-
-
Method Detail
-
asDate
public static Date asDate(XMLGregorianCalendar calendar)
Converts a javax.xml.datatype.XMLGregorianCalendar instance to a java.util.Date instance.- Parameters:
calendar- the javax.xml.datatype.XMLGregorianCalendar instance to convert- Returns:
- the converted java.util.Date instance
-
asXMLGregorianCalendar
public static XMLGregorianCalendar asXMLGregorianCalendar(Date date)
Converts a java.util.Date instance to a javax.xml.datatype.XMLGregorianCalendar instance.- Parameters:
date- the java.util.Date instance to convert- Returns:
- the converted javax.xml.datatype.XMLGregorianCalendar instance
-
getChildElement
public static Optional<Element> getChildElement(Element element, String name)
Returns the child element with the specified name for the specified element.- Parameters:
element- the parent elementname- the name of the child element to return- Returns:
- an Optional containing the child element or an empty Optional if a child element with the specified name could not be found
-
getChildElementBoolean
public static Optional<Boolean> getChildElementBoolean(Element element, String name)
Returns the boolean value of the text content for the child element with the specified name for the specified element.- Parameters:
element- the parent elementname- the name of the child element to return- Returns:
- an Optional containing the boolean value of the text content for the child element or an empty Optional if a child element with the specified name could not be found
-
getChildElementText
public static Optional<String> getChildElementText(Element element, String name)
Returns the text content for the child element with the specified name for the specified element.- Parameters:
element- the parent elementname- the name of the child element to return- Returns:
- an Optional containing the text content for the child element or an empty Optional if a child element with the specified name could not be found
-
getChildElements
public static List<Element> getChildElements(Element element, String name)
Returns the child elements with the specified name for the specified element.- Parameters:
element- the parent elementname- the name of the child elements to return- Returns:
- the child elements with the specified name for the specified element
-
getQName
public static QName getQName(Document document, String qname)
Returns the javax.xml.namespace.QName instance for the specified QName.- Parameters:
document- the org.w3c.dom.Document instance used to determine the namespace URI for the QName if the namespace is referenced using a prefix as part of the name parameterqname- the QName- Returns:
- the javax.xml.namespace.QName instance for the specified QName
-
getQName
public static QName getQName(Element element, String qname)
Returns the javax.xml.namespace.QName instance for the specified QName.- Parameters:
element- the org.w3c.dom.Element instance used to determine the namespace URI for the QName if the namespace is referenced using a prefix as part of the name parameterqname- the QName- Returns:
- the javax.xml.namespace.QName instance for the specified QName
-
hasChildElement
public static boolean hasChildElement(Element element, String name)
Returns true if the specified element has a child with the specified name or false otherwise.- Parameters:
element- the parent elementname- the name of the child element- Returns:
- true if the specified element has a child with the specified name or false otherwise
-
-