public class XmlUtils extends Object
Provides utility methods related to XML.
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 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 |
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)
Gets the required attribute with the given name from the given element. An 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)
Gets the optional attribute with the given name from the given element. Null is returned in case the attribute is not available on the element.
element
- the elementattributeName
- the name of the optional attributepublic static String getAttributeValue(Element element, String attributeName, String defaultValue)
Gets the optional attribute with the given name from the given element. The given default value is returned in case the attribute is either not available on the element or its value is empty.
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 com.google.common.collect.ImmutableList<Element> getChildElements(Element parentElement, String... childElementNames)
Gets the child elements with the given names from the given parent element.
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
Parse the given XML resource into a document and applies schema validation during the parsing process.
xmlResource
- the XML resourceentityResolver
- the entity resolvererrorHandler
- the error handlerException
- thrown in case something goes wrong during the XML parsing processpublic static Document parseWithoutValidate(String xml, ErrorHandler errorHandler) throws Exception
Parses the given XML string into a document without applying any validation during the parsing process.
xml
- the XML string to parseerrorHandler
- the error handlerException
- thrown if the parsing failsCopyright © 2010 - 2019 edorasware ag. All Rights Reserved.