public final class DOMUtils extends Object
Modifier and Type | Method and Description |
---|---|
static void |
appendChild(Node parent,
Node child)
Checks if child element has same owner document before
appending to the parent, and imports it to the parent's document
if necessary.
|
static Element |
createElement(Document doc,
String tag,
String nsURI,
String prefix)
Creates an element in the specified namespace, with the specified tag
and namespace prefix.
|
static String |
getAttributeValue(Element elem,
String name)
Returns the attribute value for the attribute with the specified name.
|
static Element |
getFirstChildElement(Node node)
Returns the first child element of the specified node, or null if there
is no such element.
|
static Element |
getFirstChildElement(Node node,
String localName,
String namespaceURI)
Returns the first child element of the specified node and checks that
the local name is equal to
localName and the namespace is equal to
namespaceURI |
static <N> String |
getIdAttributeValue(Element elem,
String name)
Returns the attribute value for the attribute with the specified name.
|
static Element |
getLastChildElement(Node node)
Returns the last child element of the specified node, or null if there
is no such element.
|
static Element |
getNextSiblingElement(Node node)
Returns the next sibling element of the specified node, or null if there
is no such element.
|
static Element |
getNextSiblingElement(Node node,
String localName,
String namespaceURI)
Returns the next sibling element of the specified node and checks that
the local name is equal to
localName and the namespace is equal to
namespaceURI |
static String |
getNSPrefix(XMLCryptoContext context,
String nsURI)
Returns the prefix associated with the specified namespace URI
|
static Document |
getOwnerDocument(Node node)
Returns the owner document of the specified node.
|
static String |
getQNameString(String prefix,
String localName)
Create a QName string from a prefix and local name.
|
static String |
getSignaturePrefix(XMLCryptoContext context)
Returns the prefix associated with the XML Signature namespace URI
|
static boolean |
isNamespace(Node node) |
static boolean |
nodesEqual(Node thisNode,
Node otherNode)
Compares 2 nodes for equality.
|
static boolean |
paramsEqual(AlgorithmParameterSpec spec1,
AlgorithmParameterSpec spec2) |
static void |
removeAllChildren(Node node)
Removes all children nodes from the specified node.
|
static void |
setAttribute(Element elem,
String name,
String value)
Sets an element's attribute (using DOM level 2) with the
specified value and namespace prefix.
|
static void |
setAttributeID(Element elem,
String name,
String value)
Sets an element's attribute (using DOM level 2) with the
specified value and namespace prefix AND registers the ID value with
the specified element.
|
public static Document getOwnerDocument(Node node)
node
- the nodepublic static String getQNameString(String prefix, String localName)
prefix
- The prefix, if any. Can be either null or empty.localName
- The local name.public static Element createElement(Document doc, String tag, String nsURI, String prefix)
doc
- the owner documenttag
- the tagnsURI
- the namespace URIprefix
- the namespace prefixpublic static void setAttribute(Element elem, String name, String value)
elem
- the element to set the attribute onname
- the name of the attributevalue
- the attribute value. If null, no attribute is set.public static void setAttributeID(Element elem, String name, String value)
elem
- the element to set the attribute onname
- the name of the attributevalue
- the attribute value. If null, no attribute is set.public static Element getFirstChildElement(Node node)
node
- the nodeNullPointerException
- if node == null
public static Element getFirstChildElement(Node node, String localName, String namespaceURI) throws MarshalException
localName
and the namespace is equal to
namespaceURI
node
- the nodeNullPointerException
- if node == null
MarshalException
- if no such element or the local name is not
equal to localName
public static Element getLastChildElement(Node node)
node
- the nodeNullPointerException
- if node == null
public static Element getNextSiblingElement(Node node)
node
- the nodeNullPointerException
- if node == null
public static Element getNextSiblingElement(Node node, String localName, String namespaceURI) throws MarshalException
localName
and the namespace is equal to
namespaceURI
node
- the nodeNullPointerException
- if node == null
MarshalException
- if no such element or the local name is not
equal to localName
public static String getAttributeValue(Element elem, String name)
This works around a limitation of the DOM
Element.getAttributeNode
method, which does not distinguish
between an unspecified attribute and an attribute with a value of
"" (it returns "" for both cases).
elem
- the element containing the attributename
- the name of the attributepublic static <N> String getIdAttributeValue(Element elem, String name)
This works around a limitation of the DOM
Element.getAttributeNode
method, which does not distinguish
between an unspecified attribute and an attribute with a value of
"" (it returns "" for both cases).
elem
- the element containing the attributename
- the name of the attributepublic static String getNSPrefix(XMLCryptoContext context, String nsURI)
context
- contains the namespace mapnsURI
- the namespace URIpublic static String getSignaturePrefix(XMLCryptoContext context)
context
- contains the namespace mappublic static void removeAllChildren(Node node)
node
- the parent node whose children are to be removedpublic static boolean nodesEqual(Node thisNode, Node otherNode)
public static void appendChild(Node parent, Node child)
public static boolean paramsEqual(AlgorithmParameterSpec spec1, AlgorithmParameterSpec spec2)
public static boolean isNamespace(Node node)
Copyright © 2000–2020 The Apache Software Foundation. All rights reserved.