spring-framework / org.springframework.util.xml / DomUtils

DomUtils

abstract class DomUtils

Convenience methods for working with the DOM API, in particular for working with DOM Nodes and DOM Elements.

Author
Juergen Hoeller

Author
Rob Harrop

Author
Costin Leau

Author
Arjen Poutsma

Author
Luke Taylor

Since
1.2

See Also
org.w3c.dom.Nodeorg.w3c.dom.Element

Constructors

<init>

DomUtils()

Convenience methods for working with the DOM API, in particular for working with DOM Nodes and DOM Elements.

Functions

createContentHandler

open static fun createContentHandler(node: Node): ContentHandler

Returns a SAX ContentHandler that transforms callback calls to DOM Nodes.

getChildElementByTagName

open static fun getChildElementByTagName(ele: Element, childEleName: String): Element

Utility method that returns the first child element identified by its name.

getChildElementValueByTagName

open static fun getChildElementValueByTagName(ele: Element, childEleName: String): String

Utility method that returns the first child element value identified by its name.

getChildElements

open static fun getChildElements(ele: Element): MutableList<Element>

Retrieves all child elements of the given DOM element

getChildElementsByTagName

open static fun getChildElementsByTagName(ele: Element, vararg childEleNames: String): MutableList<Element>

Retrieves all child elements of the given DOM element that match any of the given element names. Only looks at the direct child level of the given element; do not go into further depth (in contrast to the DOM API's getElementsByTagName method).

open static fun getChildElementsByTagName(ele: Element, childEleName: String): MutableList<Element>

Retrieves all child elements of the given DOM element that match the given element name. Only look at the direct child level of the given element; do not go into further depth (in contrast to the DOM API's getElementsByTagName method).

getTextValue

open static fun getTextValue(valueEle: Element): String

Extracts the text value from the given DOM element, ignoring XML comments.

Appends all CharacterData nodes and EntityReference nodes into a single String value, excluding Comment nodes. Only exposes actual user-specified text, no default values of any kind.

nodeNameEquals

open static fun nodeNameEquals(node: Node, desiredName: String): Boolean

Namespace-aware equals comparison. Returns true if either Node#getLocalName or Node#getNodeName equals desiredName, otherwise returns false.