[jdom-interest] creating and parsing files

Denise Aboim Sande e Oliveira denise.oliveira at bcb.gov.br
Mon Jul 14 09:02:37 PDT 2003


Hi Salil,

not only your code is missing an itr.next() call, but when you get the text you do a "root.getChildText("Username")", and that will always return only the *first* element named "Username" under root, not the next in the list. Your code should be something like:
while(itr.hasNext()){
	obj = itr.next();
	full.append(obj.getText());
}
It'd also be clearer if each username/password pair was nested under another element like "login"

Denise.

salil khanwalkar writes:

> Hi,
> My xml file  looks like this --
> <?xml version="1.0" encoding="UTF-8"?>
> <DataSet>
>  <Username>qqlil</Username>
>  <Password>welil1980</Password>
>  <Username>iotin</Username>
>  <Password>cvbtin1975</Password>
> </DataSet >
> i copy the contents in a list and then iterate through it using a iterator. T
> he while(),
>  loops infinitely and prints only the first element qqlil welil1980. I am not
>  able to get the 
> second username and password.  Is my xml file structure wrong or the code for
>  reading
> it is wrong?
> // part  of the code
>       SAXBuilder builder = new SAXBuilder();
>       Document doc = builder.build(input);
>       Element root = doc.getRootElement();
>       List dataset = doc.getContent();
>      // System.out.println(dataset);
>       
>       Iterator itr = dataset.iterator();      
>       StringBuffer full = new StringBuffer();
>       while(itr.hasNext()) {
>           full.append(root.getChildText("Username") + " ");
>           full.append(root.getChildText("Password") + " ");
>           System.out.println(full.toString());          
>       }
> Thank You,
> Salil.
_______________________________________________

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://jdom.org/pipermail/jdom-interest/attachments/20030714/c4f27d0e/attachment.htm


More information about the jdom-interest mailing list