<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.0.6389.0">
<TITLE>Re: [jdom-interest] creating and parsing files </TITLE>
</HEAD>
<BODY>
<!-- Converted from text/rtf format -->
<BR>
<P><FONT SIZE=2 FACE="Courier New">Hi Salil,</FONT>
</P>
<P><FONT SIZE=2 FACE="Courier New">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:</FONT></P>
<P><FONT SIZE=2 FACE="Courier New">while(itr.hasNext()){</FONT>
<BR> <FONT SIZE=2 FACE="Courier New">obj = itr.next();</FONT>
<BR> <FONT SIZE=2 FACE="Courier New">full.append(obj.getText());</FONT>
<BR><FONT SIZE=2 FACE="Courier New">}</FONT>
<BR><FONT SIZE=2 FACE="Courier New">It'd also be clearer if each username/password pair was nested under another element like "login"</FONT>
</P>
<P><FONT SIZE=2 FACE="Courier New">Denise.</FONT>
</P>
<P><FONT SIZE=2 FACE="Courier New">salil khanwalkar writes:</FONT>
</P>
<P><FONT SIZE=2 FACE="Courier New">> Hi,</FONT>
<BR><FONT SIZE=2 FACE="Courier New">> My xml file looks like this --</FONT>
<BR><FONT SIZE=2 FACE="Courier New">> <?xml version="1.0" encoding="UTF-8"?></FONT>
<BR><FONT SIZE=2 FACE="Courier New">> <DataSet></FONT>
<BR><FONT SIZE=2 FACE="Courier New">> <Username>qqlil</Username></FONT>
<BR><FONT SIZE=2 FACE="Courier New">> <Password>welil1980</Password></FONT>
<BR><FONT SIZE=2 FACE="Courier New">> <Username>iotin</Username></FONT>
<BR><FONT SIZE=2 FACE="Courier New">> <Password>cvbtin1975</Password></FONT>
<BR><FONT SIZE=2 FACE="Courier New">> </DataSet ></FONT>
<BR><FONT SIZE=2 FACE="Courier New">> i copy the contents in a list and then iterate through it using a iterator. T</FONT>
<BR><FONT SIZE=2 FACE="Courier New">> he while(),</FONT>
<BR><FONT SIZE=2 FACE="Courier New">> loops infinitely and prints only the first element qqlil welil1980. I am not</FONT>
<BR><FONT SIZE=2 FACE="Courier New">> able to get the </FONT>
<BR><FONT SIZE=2 FACE="Courier New">> second username and password. Is my xml file structure wrong or the code for</FONT>
<BR><FONT SIZE=2 FACE="Courier New">> reading</FONT>
<BR><FONT SIZE=2 FACE="Courier New">> it is wrong?</FONT>
<BR><FONT SIZE=2 FACE="Courier New">> // part of the code</FONT>
<BR><FONT SIZE=2 FACE="Courier New">> SAXBuilder builder = new SAXBuilder();</FONT>
<BR><FONT SIZE=2 FACE="Courier New">> Document doc = builder.build(input);</FONT>
<BR><FONT SIZE=2 FACE="Courier New">> Element root = doc.getRootElement();</FONT>
<BR><FONT SIZE=2 FACE="Courier New">> List dataset = doc.getContent();</FONT>
<BR><FONT SIZE=2 FACE="Courier New">> // System.out.println(dataset);</FONT>
<BR><FONT SIZE=2 FACE="Courier New">> </FONT>
<BR><FONT SIZE=2 FACE="Courier New">> Iterator itr = dataset.iterator(); </FONT>
<BR><FONT SIZE=2 FACE="Courier New">> StringBuffer full = new StringBuffer();</FONT>
<BR><FONT SIZE=2 FACE="Courier New">> while(itr.hasNext()) {</FONT>
<BR><FONT SIZE=2 FACE="Courier New">> full.append(root.getChildText("Username") + " ");</FONT>
<BR><FONT SIZE=2 FACE="Courier New">> full.append(root.getChildText("Password") + " ");</FONT>
<BR><FONT SIZE=2 FACE="Courier New">> System.out.println(full.toString()); </FONT>
<BR><FONT SIZE=2 FACE="Courier New">> }</FONT>
<BR><FONT SIZE=2 FACE="Courier New">> Thank You,</FONT>
<BR><FONT SIZE=2 FACE="Courier New">> Salil.</FONT>
<BR><FONT SIZE=2 FACE="Courier New">_______________________________________________</FONT>
</P>
</BODY>
</HTML>