Package org.springframework.util.xml
Class DomUtils
java.lang.Object
org.springframework.util.xml.DomUtils
Convenience methods for working with the DOM API,
in particular for working with DOM Nodes and DOM Elements.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ContentHandlercreateContentHandler(Node node) Returns a SAXContentHandlerthat transforms callback calls to DOMNodes.static ElementgetChildElementByTagName(Element ele, String childEleName) Utility method that returns the first child element identified by its name.getChildElements(Element ele) Retrieves all child elements of the given DOM element.getChildElementsByTagName(Element ele, String childEleName) Retrieves all child elements of the given DOM element that match the given element name.getChildElementsByTagName(Element ele, String... childEleNames) Retrieves all child elements of the given DOM element that match any of the given element names.static StringgetChildElementValueByTagName(Element ele, String childEleName) Utility method that returns the first child element value identified by its name.static StringgetTextValue(Element valueEle) Extracts the text value from the given DOM element, ignoring XML comments.static booleannodeNameEquals(Node node, String desiredName) Namespace-aware equals comparison.
-
Constructor Details
-
DomUtils
public DomUtils()
-
-
Method Details
-
getChildElementsByTagName
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'sgetElementsByTagNamemethod).- Parameters:
ele- the DOM element to analyzechildEleNames- the child element names to look for- Returns:
- a List of child
org.w3c.dom.Elementinstances - See Also:
-
getChildElementsByTagName
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'sgetElementsByTagNamemethod).- Parameters:
ele- the DOM element to analyzechildEleName- the child element name to look for- Returns:
- a List of child
org.w3c.dom.Elementinstances - See Also:
-
getChildElementByTagName
Utility method that returns the first child element identified by its name.- Parameters:
ele- the DOM element to analyzechildEleName- the child element name to look for- Returns:
- the
org.w3c.dom.Elementinstance, ornullif none found
-
getChildElementValueByTagName
Utility method that returns the first child element value identified by its name.- Parameters:
ele- the DOM element to analyzechildEleName- the child element name to look for- Returns:
- the extracted text value, or
nullif no child element found
-
getChildElements
Retrieves all child elements of the given DOM element.- Parameters:
ele- the DOM element to analyze- Returns:
- a List of child
org.w3c.dom.Elementinstances
-
getTextValue
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.
- See Also:
-
nodeNameEquals
Namespace-aware equals comparison. Returnstrueif eitherNode.getLocalName()orNode.getNodeName()equalsdesiredName, otherwise returnsfalse. -
createContentHandler
Returns a SAXContentHandlerthat transforms callback calls to DOMNodes.- Parameters:
node- the node to publish events to- Returns:
- the content handler
-