|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.springframework.shell.support.util.DomUtils
public final class DomUtils
Convenience methods for working with the DOM API, in particular for working with DOM Nodes and DOM Elements.
Node
,
Element
Method Summary | |
---|---|
static Element |
createChildElement(String tagName,
Node parent,
Document document)
Creates a child element with the given name and parent. |
static Element |
createChildIfNotExists(String tagName,
Node parent,
Document document)
Returns the child node with the given tag name, creating it if it does not exist. |
static Element |
findFirstElementByName(String name,
Element root)
Checks in under a given root element whether it can find a child element which matches the name supplied. |
static Element |
getChildElementByTagName(Element element,
String childElementName)
Returns the first child element identified by its name. |
static List<Element> |
getChildElementsByTagName(Element element,
String childEleName)
Retrieve all child elements of the given DOM element that match the given element name. |
static List<Element> |
getChildElementsByTagName(Element element,
String[] childElementNames)
Retrieve all child elements of the given DOM element that match any of the given element names. |
static String |
getChildElementValueByTagName(Element element,
String childElementName)
Returns the first child element value identified by its name. |
static String |
getChildTextContent(Element parent,
String child)
Returns the text content of the first child of the given parent that has the given tag name, if any. |
static String |
getTextContent(Node node,
String defaultValue)
Returns the text content of the given Node , null safe. |
static String |
getTextValue(Element valueElement)
Extract the text value from the given DOM element, ignoring XML comments. |
static boolean |
nodeNameEquals(Node node,
String desiredName)
Namespace-aware equals comparison. |
static void |
removeElements(String xPath,
Element searchBase)
Removes any elements matching the given XPath expression, relative to the given Element |
static void |
removeTextNodes(Node node)
Removes empty text nodes from the specified node. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static List<Element> getChildElementsByTagName(Element element, String[] childElementNames)
getElementsByTagName
method).
element
- the DOM element to analyzechildElementNames
- the child element names to look for
org.w3c.dom.Element
instancesElement
,
Element.getElementsByTagName(java.lang.String)
public static List<Element> getChildElementsByTagName(Element element, String childEleName)
getElementsByTagName
method).
element
- the DOM element to analyzechildEleName
- the child element name to look for
org.w3c.dom.Element
instancesElement
,
Element.getElementsByTagName(java.lang.String)
public static Element getChildElementByTagName(Element element, String childElementName)
element
- the DOM element to analyzechildElementName
- the child element name to look for
org.w3c.dom.Element
instance,
or null
if none foundpublic static String getChildElementValueByTagName(Element element, String childElementName)
element
- the DOM element to analyzechildElementName
- the child element name to look for
null
if no child element foundpublic static String getTextValue(Element valueElement)
Appends all CharacterData nodes and EntityReference nodes into a single String value, excluding Comment nodes.
CharacterData
,
EntityReference
,
Comment
public static boolean nodeNameEquals(Node node, String desiredName)
true
if either
Node.getLocalName()
or Node.getNodeName()
equals desiredName
,
otherwise returns false
.
node
- (required)desiredName
- (required)
public static void removeTextNodes(Node node)
node
- the element where empty text nodes will be removedpublic static String getTextContent(Node node, String defaultValue)
Node
, null safe.
node
- can be null
defaultValue
- the value to return if the node is null
null
Node.getTextContent()
public static Element createChildElement(String tagName, Node parent, Document document)
Document.createElement(String)
but forgets to append it to the relevant parent.
tagName
- the name of the new child (required)parent
- the parent node (required)document
- the document to which the parent and child belong (required)
public static Element createChildIfNotExists(String tagName, Node parent, Document document)
tagName
- the child tag to look for and possibly create (required)parent
- the parent in which to look for the child (required)document
- the document containing the parent (required)
null
)public static String getChildTextContent(Element parent, String child)
parent
- the parent in which to search (required)child
- the child name for which to search (required)
null
if there is no such child, otherwise the first
such child's text contentpublic static Element findFirstElementByName(String name, Element root)
Element
if exists.
name
- the Element name (required)root
- the parent DOM element (required)
public static void removeElements(String xPath, Element searchBase)
xPath
- the XPath of the element(s) to remove (can be blank)searchBase
- the element to which the XPath expression is relative
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |