public abstract class

DomUtils

extends Object
java.lang.Object
   ↳ org.springframework.util.xml.DomUtils

Class Overview

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

See Also

Summary

Public Constructors
DomUtils()
Public Methods
static ContentHandler createContentHandler(Node node)
Returns a SAX ContentHandler that transforms callback calls to DOM Nodes.
static Element getChildElementByTagName(Element ele, String childEleName)
Utility method that returns the first child element identified by its name.
static String getChildElementValueByTagName(Element ele, String childEleName)
Utility method that returns the first child element value identified by its name.
static List<Element> getChildElements(Element ele)
Retrieve all child elements of the given DOM element
static List<Element> getChildElementsByTagName(Element ele, String childEleName)
Retrieve all child elements of the given DOM element that match the given element name.
static List<Element> getChildElementsByTagName(Element ele, String[] childEleNames)
Retrieve all child elements of the given DOM element that match any of the given element names.
static String getTextValue(Element valueEle)
Extract the text value from the given DOM element, ignoring XML comments.
static boolean nodeNameEquals(Node node, String desiredName)
Namespace-aware equals comparison.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public DomUtils ()

Also: SpringCore

Public Methods

public static ContentHandler createContentHandler (Node node)

Also: SpringCore

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

Parameters
node the node to publish events to
Returns
  • the content handler

public static Element getChildElementByTagName (Element ele, String childEleName)

Also: SpringCore

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

Parameters
ele the DOM element to analyze
childEleName the child element name to look for
Returns
  • the org.w3c.dom.Element instance, or null if none found

public static String getChildElementValueByTagName (Element ele, String childEleName)

Also: SpringCore

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

Parameters
ele the DOM element to analyze
childEleName the child element name to look for
Returns
  • the extracted text value, or null if no child element found

public static List<Element> getChildElements (Element ele)

Also: SpringCore

Retrieve all child elements of the given DOM element

Parameters
ele the DOM element to analyze
Returns
  • a List of child org.w3c.dom.Element instances

public static List<Element> getChildElementsByTagName (Element ele, String childEleName)

Also: SpringCore

Retrieve 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).

Parameters
ele the DOM element to analyze
childEleName the child element name to look for
Returns
  • a List of child org.w3c.dom.Element instances

public static List<Element> getChildElementsByTagName (Element ele, String[] childEleNames)

Also: SpringCore

Retrieve all child elements of the given DOM element that match any of the given element names. 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).

Parameters
ele the DOM element to analyze
childEleNames the child element names to look for
Returns
  • a List of child org.w3c.dom.Element instances

public static String getTextValue (Element valueEle)

Also: SpringCore

Extract 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.

See Also
  • CharacterData
  • EntityReference
  • Comment

public static boolean nodeNameEquals (Node node, String desiredName)

Also: SpringCore

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