类 DomUtils
- java.lang.Object
- org.springframework.util.xml.DomUtils
构造器概要
构造器 构造器 说明 DomUtils()
方法概要
所有方法 静态方法 具体方法 修饰符和类型 方法 说明 static ContentHandler
createContentHandler(Node node)
Returns a SAXContentHandler
that transforms callback calls to DOMNode
s.static Element
getChildElementByTagName(Element ele, String childEleName)
Utility method that returns the first child element identified by its name.static List<Element>
getChildElements(Element ele)
Retrieves all child elements of the given DOM elementstatic List<Element>
getChildElementsByTagName(Element ele, String childEleName)
Retrieves all child elements of the given DOM element that match the given element name.static List<Element>
getChildElementsByTagName(Element ele, String... childEleNames)
Retrieves all child elements of the given DOM element that match any of the given element names.static String
getChildElementValueByTagName(Element ele, String childEleName)
Utility method that returns the first child element value identified by its name.static String
getTextValue(Element valueEle)
Extracts the text value from the given DOM element, ignoring XML comments.static boolean
nodeNameEquals(Node node, String desiredName)
Namespace-aware equals comparison.
构造器详细资料
DomUtils
public DomUtils()
方法详细资料
getChildElementsByTagName
public static List<Element> getChildElementsByTagName(Element ele, String... childEleNames)
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'sgetElementsByTagName
method).- 参数:
ele
- the DOM element to analyzechildEleNames
- the child element names to look for- 返回:
- a List of child
org.w3c.dom.Element
instances - 另请参阅:
Element
,Element.getElementsByTagName(java.lang.String)
getChildElementsByTagName
public static List<Element> getChildElementsByTagName(Element ele, String childEleName)
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'sgetElementsByTagName
method).- 参数:
ele
- the DOM element to analyzechildEleName
- the child element name to look for- 返回:
- a List of child
org.w3c.dom.Element
instances - 另请参阅:
Element
,Element.getElementsByTagName(java.lang.String)
getChildElementByTagName
public static Element getChildElementByTagName(Element ele, String childEleName)
Utility method that returns the first child element identified by its name.- 参数:
ele
- the DOM element to analyzechildEleName
- the child element name to look for- 返回:
- the
org.w3c.dom.Element
instance, ornull
if none found
getChildElementValueByTagName
public static String getChildElementValueByTagName(Element ele, String childEleName)
Utility method that returns the first child element value identified by its name.- 参数:
ele
- the DOM element to analyzechildEleName
- the child element name to look for- 返回:
- the extracted text value, or
null
if no child element found
getChildElements
public static List<Element> getChildElements(Element ele)
Retrieves all child elements of the given DOM element- 参数:
ele
- the DOM element to analyze- 返回:
- a List of child
org.w3c.dom.Element
instances
getTextValue
public static String getTextValue(Element valueEle)
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.
- 另请参阅:
CharacterData
,EntityReference
,Comment
nodeNameEquals
public static boolean nodeNameEquals(Node node, String desiredName)
Namespace-aware equals comparison. Returnstrue
if eitherNode.getLocalName()
orNode.getNodeName()
equalsdesiredName
, otherwise returnsfalse
.
createContentHandler
public static ContentHandler createContentHandler(Node node)
Returns a SAXContentHandler
that transforms callback calls to DOMNode
s.- 参数:
node
- the node to publish events to- 返回:
- the content handler