<!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 &quot;root.getChildText(&quot;Username&quot;)&quot;, and that will always return only the *first* element named &quot;Username&quot; 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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=2 FACE="Courier New">obj = itr.next();</FONT>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <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 &quot;login&quot;</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">&gt; Hi,</FONT>

<BR><FONT SIZE=2 FACE="Courier New">&gt; My xml file&nbsp; looks like this --</FONT>

<BR><FONT SIZE=2 FACE="Courier New">&gt; &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;</FONT>

<BR><FONT SIZE=2 FACE="Courier New">&gt; &lt;DataSet&gt;</FONT>

<BR><FONT SIZE=2 FACE="Courier New">&gt;&nbsp; &lt;Username&gt;qqlil&lt;/Username&gt;</FONT>

<BR><FONT SIZE=2 FACE="Courier New">&gt;&nbsp; &lt;Password&gt;welil1980&lt;/Password&gt;</FONT>

<BR><FONT SIZE=2 FACE="Courier New">&gt;&nbsp; &lt;Username&gt;iotin&lt;/Username&gt;</FONT>

<BR><FONT SIZE=2 FACE="Courier New">&gt;&nbsp; &lt;Password&gt;cvbtin1975&lt;/Password&gt;</FONT>

<BR><FONT SIZE=2 FACE="Courier New">&gt; &lt;/DataSet &gt;</FONT>

<BR><FONT SIZE=2 FACE="Courier New">&gt; i copy the contents in a list and then iterate through it using a iterator. T</FONT>

<BR><FONT SIZE=2 FACE="Courier New">&gt; he while(),</FONT>

<BR><FONT SIZE=2 FACE="Courier New">&gt;&nbsp; loops infinitely and prints only the first element qqlil welil1980. I am not</FONT>

<BR><FONT SIZE=2 FACE="Courier New">&gt;&nbsp; able to get the </FONT>

<BR><FONT SIZE=2 FACE="Courier New">&gt; second username and password.&nbsp; Is my xml file structure wrong or the code for</FONT>

<BR><FONT SIZE=2 FACE="Courier New">&gt;&nbsp; reading</FONT>

<BR><FONT SIZE=2 FACE="Courier New">&gt; it is wrong?</FONT>

<BR><FONT SIZE=2 FACE="Courier New">&gt; // part&nbsp; of the code</FONT>

<BR><FONT SIZE=2 FACE="Courier New">&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SAXBuilder builder = new SAXBuilder();</FONT>

<BR><FONT SIZE=2 FACE="Courier New">&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Document doc = builder.build(input);</FONT>

<BR><FONT SIZE=2 FACE="Courier New">&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Element root = doc.getRootElement();</FONT>

<BR><FONT SIZE=2 FACE="Courier New">&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; List dataset = doc.getContent();</FONT>

<BR><FONT SIZE=2 FACE="Courier New">&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // System.out.println(dataset);</FONT>

<BR><FONT SIZE=2 FACE="Courier New">&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </FONT>

<BR><FONT SIZE=2 FACE="Courier New">&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Iterator itr = dataset.iterator();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </FONT>

<BR><FONT SIZE=2 FACE="Courier New">&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; StringBuffer full = new StringBuffer();</FONT>

<BR><FONT SIZE=2 FACE="Courier New">&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while(itr.hasNext()) {</FONT>

<BR><FONT SIZE=2 FACE="Courier New">&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; full.append(root.getChildText(&quot;Username&quot;) + &quot; &quot;);</FONT>

<BR><FONT SIZE=2 FACE="Courier New">&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; full.append(root.getChildText(&quot;Password&quot;) + &quot; &quot;);</FONT>

<BR><FONT SIZE=2 FACE="Courier New">&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(full.toString());&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </FONT>

<BR><FONT SIZE=2 FACE="Courier New">&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</FONT>

<BR><FONT SIZE=2 FACE="Courier New">&gt; Thank You,</FONT>

<BR><FONT SIZE=2 FACE="Courier New">&gt; Salil.</FONT>

<BR><FONT SIZE=2 FACE="Courier New">_______________________________________________</FONT>
</P>

</BODY>
</HTML>