[jdom-interest] JDOM Help (Sorry about the first e-mail HTML)
Mark Hortman
mark.hortman at jcafeinc.com
Thu Dec 19 13:56:47 PST 2002
Document rrd = new SAXBuilder().build(input);
List rate = rrd.getRootElement().getChild( "data" ).getChild( "row"
).getChildren("v");
Iterator itr1 = ( rate ).iterator();
while( itr1.hasNext() ) {
Element v1 = ( Element )itr1.next();
System.out.println(v1.getText());
}
or use the xpath
XPath xp = new XPath("/xport/data/row/v");
List vElementsList = xp.selectNodes(rrd);
then iterate through vElementsList
calling getText() on each element.
-----Original Message-----
Hi, I am using JDOM for a project I am working on and I have come across a
problem I am using a product called RRDTool to "xport" XML data to me the
problem I am having is that the data looks like the following.
<xport>
<data>
<row><t>some time</t><v>Input value</v><v>Output value</v></row>
......
</data>
</xport>
I have no problems if there is only 1 "v" tag but if there is 2 I can't
access the text. I need to evaluate each "row" the code I use for one "v"
is below but how do I access the second "v" //v1.getChild( "v"
).getChildText( "v" ) doesn't work. Any thoughts? I need to test each "v"
(can I use xpath below // v1.getChildText( "t/v/v" ) ??
Document rrd = new SAXBuilder().build(input);
List rate = rrd.getRootElement().getChild( "data" ).getChildren( "row"
);
Iterator itr1 = ( rate ).iterator();
while( itr1.hasNext() ) {
Element v1 = ( Element )itr1.next();
System.out.println(v1.getChildText( "v" ));
}
More information about the jdom-interest
mailing list