public final class XmlUtils extends Object
Modifier and Type | Method and Description |
---|---|
static String |
getAttributeValue(Element element,
String attributeName)
Gets the optional attribute with the given name from the given element.
|
static String |
getAttributeValue(Element element,
String attributeName,
String defaultValue)
Gets the optional attribute with the given name from the given element.
|
static Element |
getChildElement(Element parentElement,
String childElementName)
Gets the child element with the given name from the given parent element.
|
static com.google.common.collect.ImmutableList<Element> |
getChildElements(Element parentElement,
String... childElementNames)
Gets the child elements with the given names from the given parent element.
|
static String |
getRequiredAttributeValue(Element element,
String attributeName)
Gets the required attribute with the given name from the given element.
|
static Document |
parseAndValidate(org.springframework.core.io.Resource xmlResource,
EntityResolver entityResolver,
ErrorHandler errorHandler)
Parse the given XML resource into a document and applies schema validation during the parsing process.
|
static Document |
parseAndValidate(String xml,
EntityResolver entityResolver,
ErrorHandler errorHandler)
Parses the given XML string into a document and applies schema validation during the parsing process.
|
static Document |
parseWithoutValidate(String xml,
ErrorHandler errorHandler)
Parses the given XML string into a document without applying any validation during the parsing process.
|
public static String getRequiredAttributeValue(Element element, String attributeName)
IllegalArgumentException
is thrown in case the attribute is not available on the element.element
- the elementattributeName
- the name of the required attributeIllegalArgumentException
- thrown if the attribute is not available on the elementpublic static String getAttributeValue(Element element, String attributeName)
element
- the elementattributeName
- the name of the optional attributepublic static String getAttributeValue(Element element, String attributeName, String defaultValue)
element
- the elementattributeName
- the name of the optional attributedefaultValue
- the default value to return in case the optional attribute is either not defined on the element or its value is emptypublic static Element getChildElement(Element parentElement, String childElementName)
parentElement
- the parent elementchildElementName
- the name of the child elementpublic static com.google.common.collect.ImmutableList<Element> getChildElements(Element parentElement, String... childElementNames)
parentElement
- the parent elementchildElementNames
- the names of the child elementspublic static Document parseAndValidate(org.springframework.core.io.Resource xmlResource, EntityResolver entityResolver, ErrorHandler errorHandler) throws Exception
xmlResource
- the XML resourceentityResolver
- the entity resolvererrorHandler
- the error handlerException
- thrown in case something goes wrong during the XML parsing processpublic static Document parseAndValidate(String xml, EntityResolver entityResolver, ErrorHandler errorHandler) throws Exception
xml
- the XML string to parseentityResolver
- the entity resolvererrorHandler
- the error handlerException
- thrown if the parsing failspublic static Document parseWithoutValidate(String xml, ErrorHandler errorHandler) throws Exception
xml
- the XML string to parseerrorHandler
- the error handlerException
- thrown if the parsing failsCopyright © 2010 - 2018 edorasware ag. All Rights Reserved.