[jdom-interest] creating & parsing files

salil khanwalkar k_salil at yahoo.com
Wed Jun 11 00:01:51 PDT 2003


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");
    
    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 calendar with sync to Outlook(TM).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://jdom.org/pipermail/jdom-interest/attachments/20030611/4d9b9f45/attachment.htm


More information about the jdom-interest mailing list