[jdom-interest] Reading XML with JDOM problem

Ian Lea ian.lea at blackwell.co.uk
Mon Jan 14 01:56:13 PST 2002


Sounds like you need to read up on Element.getChildren() and
then perhaps use something along the lines of:

        Element jroot = jdoc.getRootElement();
	List l = jroot.getChildren("sub_report");
	for (Iterator i = l.iterator(); i.hasNext();) {
	    Element subrep = (Element) i.next();
	    // Do whatever it is you need to do
	}


--
Ian.
ian.lea at blackwell.co.uk


> Patrick Hogarty wrote:
> 
> Hello,
> 
> I have an xml doc eg:
> - <report>
> - <sub_report>
>   <date required="Yes">Friday, January 11, 2002(0830)</date>
>   <heading>Report BLAH</heading>
> - <sub_heading>
>   <sub_heading_name>Customer</sub_heading_name>
>   </sub_heading>
> - <sub_heading>
>   <sub_heading_name>Number</sub_heading_name>
>   </sub_heading>
> - <sub_heading>
>   <sub_heading_name>Counterparty</sub_heading_name>
>   </sub_heading>
> - <data_row>
>   <data>BLAH</data>
>   <data>100</data>
>   <data>AAA Ltd.</data>
>   </data_row>
> - <data_row>
> ...
>   </data_row>
> </sub_report>
> <sub_report>
> ...
> </sub_report>
> ...
> </report>
> 
> So each report has a sub_report. The problem I am getting is that when I use
> Jdom to extract the data from the xml doc, it looks at the first sub_report it
> meets and proceeds to parse though it. Once finished it comes out, sees
> "sub_report" again and parses the same sub_report it just came from again, and
> not going on to the next one!
> 
> I realise I could make matters easier by labeling the sub_report like such,
> sub_report1, sub_report2, sub_report3... but for other reasons (XSLT hic-cups)
> I would rather keep it the way it is.
> 
> If anyone has used Jdom extensively and perhaps has an answer to making it
> skip over roots it has done before with the same name then please let me know.
> 
> Thanks in advance!
> 
> Regards
> 
> Patrick



More information about the jdom-interest mailing list