public class DOMUtils extends Object
Modifier and Type | Method and Description |
---|---|
static Element |
getChildElementByName(Node parent,
String name)
Returns the first child element of a node which has a given name.
|
static Element[] |
getChildElementsByName(Node parent,
String name)
Returns all child elements of a node with a given name.
|
static Element |
getFirstElementSibling(Node node)
Returns the first subsequent sibling of a given node which is an Element.
|
static String |
getTextContent(Element el)
Returns a string representing the plain text content of an element.
|
static String |
mapNodeType(short nodeType)
Maps a node type, as returned by to a name.
|
static Document |
newDocument()
Returns a new Document instance.
|
static Node |
relativizeDOM(Node n,
URI baseURI,
String attname)
Traverses the given DOM, relativising all the URIs in the
uri attributes of each Element . |
public static Element getChildElementByName(Node parent, String name)
parent
- the node whose children are to be searchedname
- the name of the element being searched forpublic static Element[] getChildElementsByName(Node parent, String name)
parent
- the node whose children are to be searchedname
- the name of the element being searched forpublic static String getTextContent(Element el)
el
- the element whose text content is wantedpublic static Element getFirstElementSibling(Node node)
node
- the node whose siblings (including itself) you are
interested in. May be nullpublic static Node relativizeDOM(Node n, URI baseURI, 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 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 Document newDocument()
Copyright © 2023 Central Laboratory of the Research Councils. All Rights Reserved.