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 forparent
which is
an Element
and has the tagname name
,
or null
if none matchpublic static Element[] getChildElementsByName(Node parent, String name)
parent
- the node whose children are to be searchedname
- the name of the element being searched forparent
with tagname
name
;
if name
is null, all child elements are returnedpublic 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 null
node
which is an Element.
If node
itself is an element, that is returned.
If node
has no subsequent siblings which are
elements, or if it is null
,
then null
is returned.public 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()
Document
instance.
This method just does all the tedious business of mucking about
with factories for you.Copyright © 2024 Central Laboratory of the Research Councils. All Rights Reserved.