public final class ElementSupport
extends java.lang.Object
| Modifier | Constructor and Description |
|---|---|
private |
ElementSupport()
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
static void |
adoptElement(org.w3c.dom.Document adopter,
org.w3c.dom.Element adoptee)
Adopts an element into a document if the child is not already in the document.
|
static void |
appendChildElement(org.w3c.dom.Element parentElement,
org.w3c.dom.Element childElement)
Appends the child Element to the parent Element, adopting the child Element into the parent's Document if needed.
|
static void |
appendTextContent(org.w3c.dom.Element element,
java.lang.String textContent)
Creates a text node with the given content and appends it as child to the given element.
|
static org.w3c.dom.Element |
constructElement(org.w3c.dom.Document document,
javax.xml.namespace.QName elementName)
Constructs an element, rooted in the given document, with the given name.
|
static org.w3c.dom.Element |
constructElement(org.w3c.dom.Document document,
java.lang.String namespaceURI,
java.lang.String localName,
java.lang.String prefix)
Constructs an element, rooted in the given document, with the given information.
|
static java.util.List<org.w3c.dom.Element> |
getChildElements(org.w3c.dom.Node root)
Gets the child elements of the given element.
|
static java.util.List<org.w3c.dom.Element> |
getChildElements(org.w3c.dom.Node root,
javax.xml.namespace.QName name)
Gets the child nodes with the given local tag name.
|
static java.util.List<org.w3c.dom.Element> |
getChildElementsByTagName(org.w3c.dom.Node root,
java.lang.String localName)
Gets the child nodes with the given local tag name.
|
static java.util.List<org.w3c.dom.Element> |
getChildElementsByTagNameNS(org.w3c.dom.Node root,
java.lang.String namespaceURI,
java.lang.String localName)
Gets the child nodes with the given namespace qualified tag name.
|
static org.w3c.dom.Element |
getElementAncestor(org.w3c.dom.Node currentNode)
Gets the ancestor element node to the given node.
|
static java.util.List<java.lang.String> |
getElementContentAsList(org.w3c.dom.Element element)
Gets the value of a list-type element as a list.
|
static javax.xml.namespace.QName |
getElementContentAsQName(org.w3c.dom.Element element)
Constructs a QName from an element's adjacent Text child nodes.
|
static java.lang.String |
getElementContentAsString(org.w3c.dom.Element element)
Gets the text content for this Element only.
|
static org.w3c.dom.Element |
getFirstChildElement(org.w3c.dom.Node n)
Gets the first child Element of the node, skipping any Text nodes such as whitespace.
|
static org.w3c.dom.Element |
getFirstChildElement(org.w3c.dom.Node root,
javax.xml.namespace.QName name)
Returns the first child element of the supplied element with the supplied name if it exists.
|
static java.util.Map<javax.xml.namespace.QName,java.util.List<org.w3c.dom.Element>> |
getIndexedChildElements(org.w3c.dom.Element root)
Gets the child elements of the given element in a single iteration.
|
static org.w3c.dom.Element |
getNextSiblingElement(org.w3c.dom.Node n)
Gets the next sibling Element of the node, skipping any Text nodes such as whitespace.
|
static boolean |
isElementNamed(org.w3c.dom.Element e,
javax.xml.namespace.QName name)
Check if the given Element has the given name.
|
static boolean |
isElementNamed(org.w3c.dom.Element e,
java.lang.String ns,
java.lang.String localName)
Shortcut for checking a DOM element node's namespace and local name.
|
static void |
setDocumentElement(org.w3c.dom.Document document,
org.w3c.dom.Element element)
Sets a given Element as the root element of a given document.
|
public static void adoptElement(@Nonnull
org.w3c.dom.Document adopter,
@Nonnull
org.w3c.dom.Element adoptee)
adoptee - the element to be adoptedadopter - the document into which the element is adoptedpublic static void appendChildElement(@Nonnull
org.w3c.dom.Element parentElement,
@Nullable
org.w3c.dom.Element childElement)
parentElement - the parent ElementchildElement - the child Elementpublic static void appendTextContent(@Nonnull
org.w3c.dom.Element element,
@Nullable
java.lang.String textContent)
element - the element to receive the text nodetextContent - the content for the text nodepublic static org.w3c.dom.Element constructElement(@Nonnull
org.w3c.dom.Document document,
@Nonnull
javax.xml.namespace.QName elementName)
document - the document containing the elementelementName - the name of the element, must contain a local name, may contain a namespace URI and prefixpublic static org.w3c.dom.Element constructElement(@Nonnull
org.w3c.dom.Document document,
@Nullable
java.lang.String namespaceURI,
@Nonnull
java.lang.String localName,
@Nullable
java.lang.String prefix)
document - the document containing the elementnamespaceURI - the URI of the namespace the element is inlocalName - the element's local nameprefix - the prefix of the namespace the element is in@Nonnull
public static java.util.List<org.w3c.dom.Element> getChildElements(@Nullable
org.w3c.dom.Node root)
root - element to get the child elements of@Nonnull
public static java.util.List<org.w3c.dom.Element> getChildElements(@Nullable
org.w3c.dom.Node root,
@Nullable
javax.xml.namespace.QName name)
getChildElements(Node).root - element to retrieve the children fromname - name of the child elements to be retrieved@Nullable
public static org.w3c.dom.Element getFirstChildElement(@Nullable
org.w3c.dom.Node root,
@Nullable
javax.xml.namespace.QName name)
getChildElements(Node, QName).root - element to parse child elementsname - name of the child elements to parse@Nonnull
public static java.util.List<org.w3c.dom.Element> getChildElementsByTagName(@Nullable
org.w3c.dom.Node root,
@Nullable
java.lang.String localName)
getChildElements(Node).root - element to retrieve the children fromlocalName - local, tag, name of the child element@Nonnull
public static java.util.List<org.w3c.dom.Element> getChildElementsByTagNameNS(@Nullable
org.w3c.dom.Node root,
@Nullable
java.lang.String namespaceURI,
@Nullable
java.lang.String localName)
getChildElements(Node).root - element to retrieve the children fromnamespaceURI - namespace URI of the child elementlocalName - local, tag, name of the child element@Nullable
public static org.w3c.dom.Element getElementAncestor(@Nullable
org.w3c.dom.Node currentNode)
currentNode - the node to retrieve the ancestor for@Nonnull
public static java.lang.String getElementContentAsString(@Nullable
org.w3c.dom.Element element)
Node.getTextContent() will return all text for this
element and all children, this just grabs the text for this element (which may be spread over multiple lines).element - The element to look at.@Nonnull
public static java.util.List<java.lang.String> getElementContentAsList(@Nullable
org.w3c.dom.Element element)
element - element whose value will be turned into a list@Nullable
public static javax.xml.namespace.QName getElementContentAsQName(@Nullable
org.w3c.dom.Element element)
element - the element with a QName value@Nullable
public static org.w3c.dom.Element getFirstChildElement(@Nullable
org.w3c.dom.Node n)
n - The parent in which to search for children@Nonnull
public static java.util.Map<javax.xml.namespace.QName,java.util.List<org.w3c.dom.Element>> getIndexedChildElements(@Nullable
org.w3c.dom.Element root)
root - element to get the child elements of@Nullable
public static org.w3c.dom.Element getNextSiblingElement(@Nullable
org.w3c.dom.Node n)
n - The sibling to start withpublic static boolean isElementNamed(@Nullable
org.w3c.dom.Element e,
@Nullable
javax.xml.namespace.QName name)
e - element to checkname - name to check forpublic static boolean isElementNamed(@Nullable
org.w3c.dom.Element e,
@Nullable
java.lang.String ns,
@Nullable
java.lang.String localName)
e - An element to compare againstns - An XML namespace to comparelocalName - A local name to comparepublic static void setDocumentElement(@Nonnull
org.w3c.dom.Document document,
@Nonnull
org.w3c.dom.Element element)
document - document whose root element will be setelement - element that will be the new root element