|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object th.co.edge.jseq.util.XMLUtil
public class XMLUtil
A utility class to work with org.w3c.dom.Node
objects.
Nested Class Summary | |
---|---|
static class |
XMLUtil.NodePrinter
An implementation of Visitor that creates a string
representation of a Node and its children, or in other
words, to a (part of) an XML document. |
static interface |
XMLUtil.Visitor
The Visitor interface is used when traversing XML
documents. |
Method Summary | |
---|---|
static org.w3c.dom.Node |
find(org.w3c.dom.Node node,
XMLUtil.Visitor visitor)
Searches the given Node and its children depth-first,
looking for the first Node that satisfies the given
Visitor . |
static org.w3c.dom.Node[] |
findAllTags(org.w3c.dom.Node node,
java.lang.String tag)
Searches a Node and its children depth-first, returning an
array with all element nodes with a given name. |
static org.w3c.dom.Node[] |
findAllTags(org.w3c.dom.Node node,
java.lang.String tag,
java.lang.String text)
Searches a Node and its children depth-first, returning an
array with all element nodes with a given name, and also containing a
text sub-node with a given text. |
static org.w3c.dom.Node |
findTag(org.w3c.dom.Node node,
java.lang.String tag)
Searches a Node and its children depth-first for an
element node with a given name. |
static org.w3c.dom.Node |
findTag(org.w3c.dom.Node node,
java.lang.String tag,
java.lang.String text)
Searches a Node and its children depth-first for an
element node with a given name, and also containing a text sub-node with
a given text. |
static org.w3c.dom.Node |
getAttribute(org.w3c.dom.Node node,
java.lang.String attributeName)
Returns the named attribute in a Node . |
static java.lang.String |
getAttributeText(org.w3c.dom.Node node,
java.lang.String attributeName)
Returns the string value of a named attribute in a Node . |
static java.lang.String |
getText(org.w3c.dom.Node node)
Returns the first text sub-node of the given Node . |
static java.lang.String |
getText(org.w3c.dom.Node node,
int nth)
Returns the nth text sub-node of the given Node . |
static java.lang.String |
makeXMLSafe(java.lang.String original)
Returns a copy of a string where all special XML characters have been replaced by the corresponding character entity reference, for example, "<" is replaced by "<". |
static java.lang.String |
toString(org.w3c.dom.Node node)
Returns a string representation of a Node and its
children, pretty-printed so as to include new-lines and with each
sub-node indented. |
static java.lang.String |
toString(org.w3c.dom.Node node,
boolean prettyPrint)
Returns a string representation of a Node and its
children. |
static void |
traverse(org.w3c.dom.Node node,
XMLUtil.Visitor visitor)
Traverses the given Node and its children depth-first,
calling the given Visitor for each node. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static void traverse(org.w3c.dom.Node node, XMLUtil.Visitor visitor)
Node
and its children depth-first,
calling the given Visitor
for each node.
If the traversal should be stopped at a certain node, the
Visitor
should return true
from the
visit
method for that node. Obviously, if the entire tree
should be traversed, the visit
method should always return
false
.
node
- the root Node
at which to start the traversalvisitor
- the Visitor
XMLUtil.Visitor.visit(Node)
public static org.w3c.dom.Node find(org.w3c.dom.Node node, XMLUtil.Visitor visitor)
Node
and its children depth-first,
looking for the first Node
that satisfies the given
Visitor
.
node
- the root Node
at which to start the searchvisitor
- the Visitor
that is called for every node, and
determines if the right node has been found by returning
true
from the visit
method
Node
in a depth-first search that
satisfies visitor
, or null
if
there is none.XMLUtil.Visitor.visit(Node)
public static org.w3c.dom.Node findTag(org.w3c.dom.Node node, java.lang.String tag)
Node
and its children depth-first for an
element node with a given name.
node
- the root Node
at which to start the searchtag
- the name of the tag to search for
Node
found, or null
public static org.w3c.dom.Node findTag(org.w3c.dom.Node node, java.lang.String tag, java.lang.String text)
Node
and its children depth-first for an
element node with a given name, and also containing a text sub-node with
a given text.
node
- the root Node
at which to start the searchtag
- the name of the tag to search fortext
- a string that must be included in the first text sub-node of
the found node, or null
if only the tag name
should be used to determine if a node matches
Node
found, or null
public static org.w3c.dom.Node[] findAllTags(org.w3c.dom.Node node, java.lang.String tag)
Node
and its children depth-first, returning an
array with all element nodes with a given name.
node
- the root Node
at which to start the searchtag
- the name of the tags to search for
Node
array with all element nodes with the given
name
starting from node
. If no
such nodes exist, an empty array is returnedpublic static org.w3c.dom.Node[] findAllTags(org.w3c.dom.Node node, java.lang.String tag, java.lang.String text)
Node
and its children depth-first, returning an
array with all element nodes with a given name, and also containing a
text sub-node with a given text.
node
- the root Node
at which to start the searchtag
- the name of the tags to search fortext
- a string that must be included in the first text sub-node of
the found node, or null
if only the tag name
should be used to determine if a node matches
Node
array with all element nodes with the given
name
and containing a text node with
text
, starting from node
. If no
such nodes exist, an empty array is returnedpublic static java.lang.String getText(org.w3c.dom.Node node)
Node
.
node
- the Node
whose children to search for the first
text node
node
, or
null
if there is nonepublic static java.lang.String getText(org.w3c.dom.Node node, int nth)
Node
.
node
- the Node
whose children to search for the
nth
text nodenth
- the index of the text childe node to return
nth
text sub-node of node
, or
null
if node
has fewer than
nth
text nodes as childrenpublic static org.w3c.dom.Node getAttribute(org.w3c.dom.Node node, java.lang.String attributeName)
Node
.
node
- the Node
in which to look for attributesattributeName
- the name of the attribute to look up
attributeName
in Node
, or
null
if there is no attribute with that namepublic static java.lang.String getAttributeText(org.w3c.dom.Node node, java.lang.String attributeName)
Node
.
node
- the Node
in which to look for attributesattributeName
- the name of the attribute to look up
attributeName
in Node
, or
null
if there is no attribute with that namepublic static java.lang.String toString(org.w3c.dom.Node node)
Node
and its
children, pretty-printed so as to include new-lines and with each
sub-node indented.
node
- the Node
to represent as a string
Node
public static java.lang.String toString(org.w3c.dom.Node node, boolean prettyPrint)
Node
and its
children.
node
- the Node
to represent as a stringprettyPrint
- if true
, the string representation of
Node
will be pretty-printed, so as to include
new-lines and with each sub-node indented
Node
public static java.lang.String makeXMLSafe(java.lang.String original)
original
- the string to make safe to use in an XML document
original
with all special XML characters
replaced by the corresponding character entity reference
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |