|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--jcs.xml.DomTree
A uninstantiable class with miscellaneous utility methods to access a DOM tree from parsed XML.
Method Summary | |
static org.w3c.dom.Element |
appendChild(org.w3c.dom.Document doc,
org.w3c.dom.Node parent,
java.lang.String childName)
Append a node with a given name as a child of a given parent node. |
static org.w3c.dom.Element |
appendChild(org.w3c.dom.Document doc,
org.w3c.dom.Node parent,
java.lang.String childName,
java.lang.String childText,
boolean cData)
Append a node with a given name and text as a child of a given parent node. |
static org.w3c.dom.Document |
checker(org.w3c.dom.Document doc,
java.lang.String rootName)
Checks that the name of the root node of an XML document is a given name. |
static java.lang.String |
doc2String(org.w3c.dom.Document doc)
Return a String XML document from a Document . |
static org.w3c.dom.Node |
findNode(org.w3c.dom.Node node,
java.lang.String nodeName)
A convenience shorthand for findNode(N, NN, 0) |
static org.w3c.dom.Node |
findNode(org.w3c.dom.Node node,
java.lang.String nodeName,
int nodeNumber)
Returns a subnode of a given XML node, given the sub-node name. |
static java.lang.String |
getAttribute(org.w3c.dom.Node node,
java.lang.String attributeName)
Returns the value of an attribute for a given XML node and attributeName. |
static java.lang.String |
getText(org.w3c.dom.Node node)
Returns the text of a given XML node. |
static org.w3c.dom.Node |
getTextNode(org.w3c.dom.Node node)
Returns the child node containing text, for a given XML node. |
static org.w3c.dom.Document |
newDocument(boolean validate)
Return a new empty Document object. |
static int |
nextGivenChild(org.w3c.dom.NodeList nl,
int from,
java.lang.String given)
Returns the index (if any) of the next Node in Nodelist nl
at or after the from index, whose node name is
in the given string. |
static int |
nextNonWhiteSpace(org.w3c.dom.NodeList nl,
int from)
Returns the index (if any) of the next Node in Nodelist nl ,
at or after the from index, that is not whitespace. |
static void |
setAttribute(org.w3c.dom.Element node,
java.lang.String attributeName,
java.lang.String attributeValue)
Sets the value of an attribute for a given XML node and attributeName. |
static org.w3c.dom.Node |
setText(org.w3c.dom.Document doc,
org.w3c.dom.Node targetNode,
java.lang.String newValue)
Sets the text of a given XML node. |
static org.w3c.dom.Node |
topNode(org.w3c.dom.Document doc,
java.lang.String rootName)
Checks that the root node of an XML document has a given name, and returns that root node. |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Method Detail |
public static java.lang.String getAttribute(org.w3c.dom.Node node, java.lang.String attributeName)
node
is positioned
on <column null=true>
,
a call of getAttribute(node, "null")
returns
the string "true".node
- a Node that is positioned on a node of a DOM treeattributename
- a string that is the name of an attribute
of the node
public static void setAttribute(org.w3c.dom.Element node, java.lang.String attributeName, java.lang.String attributeValue)
node
is positioned
on <column null=true>
,
a call of setAttribute(node, "null" "false")
sets the
the "null" attribute to "true" (or inserts a new "null" attribute).node
- a Node that is positioned on a node of a DOM treeattributename
- a string that is the name of an attribute
of the node
attributeValue
- a string that is the value of the attributepublic static org.w3c.dom.Node findNode(org.w3c.dom.Node node, java.lang.String nodeName, int nodeNumber)
For example
node
is positioned
on a <ResultSet>
node,
and that node has a child node <ResultSetMetaData>
,
then the call findNamedNode(node, "ResultSetMetadata", 0)
returns the (first or only) <ResultSetMetaData>
node,
or null.
<ResultSetData>
node that has multiple child nodes
<Row
, then the call
findNamedNode(node, "ResultSetMetadata", 3)
<Row
,
if there is one, and otherwise will return null
.
node
- a Node that is positioned on a node of a DOM treenodeName
- a string that is the name of a child of the nodenodeNumber
- a string that is the number of a child of the nodepublic static org.w3c.dom.Node findNode(org.w3c.dom.Node node, java.lang.String nodeName)
findNode(N, NN, 0)
node
- a Node that is positioned on a node of a DOM treenodeName
- a string that is the name of a child of the nodenodeNumber
- a string that is the number of a child of the nodepublic static java.lang.String getText(org.w3c.dom.Node node)
<Column>123</column>
,
then getText(node)
returns "123".node
- a Node that is positioned on a node of a DOM treepublic static org.w3c.dom.Node setText(org.w3c.dom.Document doc, org.w3c.dom.Node targetNode, java.lang.String newValue)
node
is positioned on
<Column>123</column>
,
and doc
is the Document containing node
,
then setText(doc, node, "987")
sets the value to 987
and returns the updated node.node
- a Node that is positioned on a node of a DOM treepublic static org.w3c.dom.Node getTextNode(org.w3c.dom.Node node)
<Column>123</column>
,
then getText(node)
will return the node with "123".
Use this method when you want to update the text node.node
- a Node that is positioned on a node of a DOM tree#text
or #cdatasection
node
that is a child of the nodepublic static int nextGivenChild(org.w3c.dom.NodeList nl, int from, java.lang.String given)
nl
at or after the from
index, whose node name is
in the given
string.
Otherwise, returns -1.
This is mainly handy for skipping over #text
nodes
with whitespace.nl
- a NodeList that is the child nodes of a DOM tree nodefrom
- an int that is the index of the first child node in the
NodeList to consider. For example, if you use this
method to step through the child nodes, then the
from
value will be one more
than the index of the last child node that you processed.given
- a string that is the name of the child node
that is soughtpublic static int nextNonWhiteSpace(org.w3c.dom.NodeList nl, int from)
nl
,
at or after the from
index, that is not whitespace.
This is mainly handy for skipping over #text
nodes
with whitespace.nl
- a NodeList that is the child nodes of a DOM tree nodefrom
- an int that is the index of the first child node in the
NodeList to consider. For example, if you use this
method to step through the child nodes, then the
from
value will be one more than
the index of the last child node that you processed.public static org.w3c.dom.Document checker(org.w3c.dom.Document doc, java.lang.String rootName) throws java.lang.Exception
Document
- a parsed XML documentrootName
- a string that is the expected name of the root node
of the documentrootName
public static org.w3c.dom.Node topNode(org.w3c.dom.Document doc, java.lang.String rootName) throws java.lang.Exception
doc
- a parsed XML documentrootName
- a string that is the expected name of the root node
of the documentrootName
public static org.w3c.dom.Element appendChild(org.w3c.dom.Document doc, org.w3c.dom.Node parent, java.lang.String childName)
doc
contains a node
<ResultSetData> node, then the call
appendChild(doc, node, "Row")
will append a new
<Row>
node and return it.doc
- a parsed XML documentparent
- a node of doc that will be the parent of the new nodechildName
- a string that will be the name of the new child nodepublic static org.w3c.dom.Element appendChild(org.w3c.dom.Document doc, org.w3c.dom.Node parent, java.lang.String childName, java.lang.String childText, boolean cData)
doc
contains a node
<Row> node, then the call
appendChild(doc, node, "Column", "Apples", false)
will append
a new <Column>Apples</Column>
node and return it.doc
- a parsed XML documentparent
- a node of doc that will be the parent of the new nodechildName
- a string that will be the name of the new child nodechildText
- the text of the new child nodecData
- a boolean true iff the text should be a CDATA sectionpublic static org.w3c.dom.Document newDocument(boolean validate) throws java.lang.Exception
Document
object.validate
- a boolean indication of whether (true) or not (false)
the new Document
should validate.Document
object.public static java.lang.String doc2String(org.w3c.dom.Document doc) throws java.lang.Exception
Document
.doc
- a Document
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |