[jdom-interest] creating & parsing files

Goswami, Raj Purnendu_Goswami at csx.com
Wed Jun 11 06:24:38 PDT 2003


 
Use doc.getRootElement.getChildren() and then iterate through the returned
List.

Thanks, 

Raj Goswami 
(410)613-6288 

 

-----Original Message-----
From: salil khanwalkar [mailto:k_salil at yahoo.com]
Sent: Wednesday, June 11, 2003 3:02 AM
To: jdom-interest at jdom.org
Subject: [jdom-interest] creating & parsing files


Hi
I have 2 questions-
1.
I want to generate a dataset which will contain First name,Middle name And
Last name
I want to group them accordingly.
My file should like this-
<DataSet>
                <First>
                         "First names should come here"
                </First>
 
                <Middle>
                         "<Middle names should come here"
                </Middle>
 
                <Last>
                         "Last names should come here"
                </Last>
 
</DataSet
 
Here is my code for the same-- (not getting expected results)
 
 Element DSElement = new Element("DataSet");
    Document doc = new Document(DSElement);
    DocType type = new DocType("html", "-//W3C//DTD XHTML 1.0
Transitional//EN", 
                       "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd
<http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd> ");
    
    Element FElement = new Element("First");
    FElement.addContent(new Element("F1").addContent("aaa"));
    FElement.addContent(new Element("F2").addContent("sss"));
    Element MElement = new Element("Middle");
    FElement.addContent(new Element("P1").addContent("ddd"));
    FElement.addContent(new Element("P2").addContent("qqq"));
    
    XMLOutputter outputter = new XMLOutputter("  ", true);        
    FileWriter writer = new FileWriter("dataset.xml");
    outputter.output(doc, writer);
    writer.close();

2-
 
To read a file i copy its contents in a List object.
Then i use an Iterator object to iterate through the list.
 
while(iterator.hasNext()){
   doc.getRootElement.getChildText("First");///here instead of specifying
the "First" string i want to iterate through the list and retreive their
values
I tried get(i) in a for loop but no results
}
 
This returns me the value of the child. The problem is that i keep on
getting the same value for all child nodes, instead of the value of the next

child node.
 
Somebody please help me out.
 
Thank you,
Salil.
 
 



  _____  

Do you Yahoo!?
Free online  <http://us.rd.yahoo.com/mail_us/tag/*http://calendar.yahoo.com>
calendar with sync to Outlook(TM).




More information about the jdom-interest mailing list