public final class DOMHelper extends Object
Constructor and Description |
---|
DOMHelper() |
Modifier and Type | Method and Description |
---|---|
static Node |
appendClone(Element parentElement,
Node o) |
static <T> List<T> |
asList(T node) |
static String |
directTextContent(Node item) |
static void |
ensureOwnership(Document ownerDocument,
Node node) |
static Map<String,String> |
getNamespaceMapping(Document document)
Parse namespace prefixes defined anywhere in the document.
|
static Document |
getOwnerDocumentFor(Node documentOrElement) |
static int |
nodeHashCode(Node node)
hashCode() implementation that is compatible with equals().
|
static boolean |
nodesAreEqual(Node a,
Node b)
Implementation independent version of the Node.isEqualNode() method.
|
static void |
removeAllChildren(Node node)
Simply removes all child nodes.
|
static void |
removeAttribute(Attr attributeNode) |
static void |
removeNodes(Iterable<? extends Node> existingNodes) |
static <T extends Node> |
renameNode(T node,
String newName) |
static void |
replaceElement(Element previous,
Element newNode) |
static void |
setDirectTextContent(Node elementToChange,
String asString)
Set text content of given element without removing existing child nodes.
|
static void |
setDocumentElement(Document document,
Element element)
Replace the current root element.
|
static void |
setOrRemoveAttribute(Element element,
String attributeName,
String value) |
static String |
toXMLString(XBProjector projector,
Node domNode) |
static void |
trim(Node domNode) |
public static Map<String,String> getNamespaceMapping(Document document)
document
- source document.public static void setDocumentElement(Document document, Element element)
document
- element
- public static boolean nodesAreEqual(Node a, Node b)
nodeName
, localName
,
namespaceURI
, prefix
, nodeValue
. This is: they are
both null
, or they have the same length and are character for character
identical.attributes
NamedNodeMaps
are equal. This is: they are both
null
, or they have the same length and for each node that exists in one map
there is a node that exists in the other map and is equal, although not necessarily at the
same index.childNodes
NodeLists
are equal. This is: they are both
null
, or they have the same length and contain equal nodes at the same index.
Note that normalization can affect equality; to avoid this, nodes should be normalized before
being compared.DocumentType
nodes to be equal, the following conditions must also be
satisfied:
publicId
, systemId
,
internalSubset
.entities
NamedNodeMaps
are equal.notations
NamedNodeMaps
are equal.a
- b
- public static int nodeHashCode(Node node)
node
- public static void setOrRemoveAttribute(Element element, String attributeName, String value)
element
- attributeName
- value
- public static <T extends Node> T renameNode(T node, String newName)
node
- newName
- public static void ensureOwnership(Document ownerDocument, Node node)
ownerDocument
- node
- public static Document getOwnerDocumentFor(Node documentOrElement)
documentOrElement
- public static void trim(Node domNode)
domNode
- public static <T> List<T> asList(T node)
node
- public static void replaceElement(Element previous, Element newNode)
previous
- newNode
- public static void removeAllChildren(Node node)
node
- public static void removeAttribute(Attr attributeNode)
attributeNode
- public static Node appendClone(Element parentElement, Node o)
parentElement
- o
- public static void removeNodes(Iterable<? extends Node> existingNodes)
existingNodes
- public static String toXMLString(XBProjector projector, Node domNode)
projector
- domNode
- public static String directTextContent(Node item)
item
- Copyright © 2012-12-21-2022. All Rights Reserved.