public final class ElementSupport extends Object
| Modifier | Constructor and Description |
|---|---|
private |
ElementSupport()
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
static void |
adoptElement(Document adopter,
Element adoptee)
Adopts an element into a document if the child is not already in the document.
|
static void |
appendChildElement(Element parentElement,
Element childElement)
Appends the child Element to the parent Element, adopting the child Element into the parent's Document if needed.
|
static void |
appendTextContent(Element element,
String textContent)
Creates a text node with the given content and appends it as child to the given element.
|
static Element |
constructElement(Document document,
QName elementName)
Constructs an element, rooted in the given document, with the given name.
|
static Element |
constructElement(Document document,
String namespaceURI,
String localName,
String prefix)
Constructs an element, rooted in the given document, with the given information.
|
static List<Element> |
getChildElements(Node root)
Gets the child elements of the given element.
|
static List<Element> |
getChildElements(Node root,
QName name)
Gets the child nodes with the given local tag name.
|
static List<Element> |
getChildElementsByTagName(Node root,
String localName)
Gets the child nodes with the given local tag name.
|
static List<Element> |
getChildElementsByTagNameNS(Node root,
String namespaceURI,
String localName)
Gets the child nodes with the given namespace qualified tag name.
|
static Element |
getElementAncestor(Node currentNode)
Gets the ancestor element node to the given node.
|
static List<String> |
getElementContentAsList(Element element)
Gets the value of a list-type element as a list.
|
static QName |
getElementContentAsQName(Element element)
Constructs a QName from an element's adjacent Text child nodes.
|
static String |
getElementContentAsString(Element element)
Gets the text content for this Element only.
|
static Element |
getFirstChildElement(Node n)
Gets the first child Element of the node, skipping any Text nodes such as whitespace.
|
static Element |
getFirstChildElement(Node root,
QName name)
Returns the first child element of the supplied element with the supplied name if it exists.
|
static Map<QName,List<Element>> |
getIndexedChildElements(Element root)
Gets the child elements of the given element in a single iteration.
|
static Element |
getNextSiblingElement(Node n)
Gets the next sibling Element of the node, skipping any Text nodes such as whitespace.
|
static boolean |
isElementNamed(Element e,
QName name)
Check if the given Element has the given name.
|
static boolean |
isElementNamed(Element e,
String ns,
String localName)
Shortcut for checking a DOM element node's namespace and local name.
|
static void |
setDocumentElement(Document document,
Element element)
Sets a given Element as the root element of a given document.
|
public static void adoptElement(@Nonnull Document adopter, @Nonnull Element adoptee)
adoptee - the element to be adoptedadopter - the document into which the element is adoptedpublic static void appendChildElement(@Nonnull Element parentElement, @Nullable Element childElement)
parentElement - the parent ElementchildElement - the child Elementpublic static void appendTextContent(@Nonnull Element element, @Nullable String textContent)
element - the element to receive the text nodetextContent - the content for the text nodepublic static Element constructElement(@Nonnull Document document, @Nonnull 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 Element constructElement(@Nonnull Document document, @Nullable String namespaceURI, @Nonnull String localName, @Nullable 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 List<Element> getChildElements(@Nullable Node root)
root - element to get the child elements of@Nonnull public static List<Element> getChildElements(@Nullable Node root, @Nullable QName name)
getChildElements(Node).root - element to retrieve the children fromname - name of the child elements to be retrieved@Nullable public static Element getFirstChildElement(@Nullable Node root, @Nullable QName name)
getChildElements(Node, QName).root - element to parse child elementsname - name of the child elements to parse@Nonnull public static List<Element> getChildElementsByTagName(@Nullable Node root, @Nullable String localName)
getChildElements(Node).root - element to retrieve the children fromlocalName - local, tag, name of the child element@Nonnull public static List<Element> getChildElementsByTagNameNS(@Nullable Node root, @Nullable String namespaceURI, @Nullable 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 Element getElementAncestor(@Nullable Node currentNode)
currentNode - the node to retrieve the ancestor for@Nonnull public static String getElementContentAsString(@Nullable 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 List<String> getElementContentAsList(@Nullable Element element)
element - element whose value will be turned into a list@Nullable public static QName getElementContentAsQName(@Nullable Element element)
element - the element with a QName value@Nullable public static Element getFirstChildElement(@Nullable Node n)
n - The parent in which to search for children@Nonnull public static Map<QName,List<Element>> getIndexedChildElements(@Nullable Element root)
root - element to get the child elements of@Nullable public static Element getNextSiblingElement(@Nullable Node n)
n - The sibling to start withpublic static boolean isElementNamed(@Nullable Element e, @Nullable QName name)
e - element to checkname - name to check forpublic static boolean isElementNamed(@Nullable Element e, @Nullable String ns, @Nullable String localName)
e - An element to compare againstns - An XML namespace to comparelocalName - A local name to comparepublic static void setDocumentElement(@Nonnull Document document, @Nonnull Element element)
document - document whose root element will be setelement - element that will be the new root elementCopyright © 1999–2016 Shibboleth Consortium. All rights reserved.