public class DOMUtils
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static org.w3c.dom.Element |
getChildElementByName(org.w3c.dom.Node parent,
java.lang.String name)
Returns the first child element of a node which has a given name.
|
static org.w3c.dom.Element[] |
getChildElementsByName(org.w3c.dom.Node parent,
java.lang.String name)
Returns all child elements of a node with a given name.
|
static org.w3c.dom.Element |
getFirstElementSibling(org.w3c.dom.Node node)
Returns the first subsequent sibling of a given node which is an Element.
|
static java.lang.String |
getTextContent(org.w3c.dom.Element el)
Returns a string representing the plain text content of an element.
|
static java.lang.String |
mapNodeType(short nodeType)
Maps a node type, as returned by to a name.
|
static org.w3c.dom.Document |
newDocument()
Returns a new Document instance.
|
static org.w3c.dom.Node |
relativizeDOM(org.w3c.dom.Node n,
java.net.URI baseURI,
java.lang.String attname)
Traverses the given DOM, relativising all the URIs in the
uri attributes of each Element . |
public static org.w3c.dom.Element getChildElementByName(org.w3c.dom.Node parent, java.lang.String name)
parent
- the node whose children are to be searchedname
- the name of the element being searched forpublic static org.w3c.dom.Element[] getChildElementsByName(org.w3c.dom.Node parent, java.lang.String name)
parent
- the node whose children are to be searchedname
- the name of the element being searched forpublic static java.lang.String getTextContent(org.w3c.dom.Element el)
el
- the element whose text content is wantedpublic static org.w3c.dom.Element getFirstElementSibling(org.w3c.dom.Node node)
node
- the node whose siblings (including itself) you are
interested in. May be nullpublic static org.w3c.dom.Node relativizeDOM(org.w3c.dom.Node n, java.net.URI baseURI, java.lang.String attname)
uri
attributes of each Element
.
The (uri-attribute) nodes in the input DOM are modified by this
method; if this is a problem, use Node.cloneNode(boolean)
first.
n
- a node containing the DOM whose URIs are to be
relativized. If this is null, the method immediately returns nullbaseURI
- the URI relative to which the DOM is to be
relativised. If this is null, then the input node is
immediately returned unchanged.attname
- the attribute name to be used. If null, this
defaults to uri
URI.relativize(java.net.URI)
public static java.lang.String mapNodeType(short nodeType)
Node.getNodeType()
are
numeric and are therefore inconveniently opaque.nodeType
- a numeric Node type, one of the node type
constants defined in Node
public static org.w3c.dom.Document newDocument()