[jdom-interest] Having problem with adding data in to xml file
Ian Lea
ian.lea at gmail.com
Tue Oct 31 01:52:49 PST 2006
You need to add the text to the correct Element.
name.addContent(s1);
age.addContent(s2);
You might be better off with setText() instead - see the javadoc.
--
Ian.
On 10/31/06, Mukunda HolavanahalliSreenivasaMurthy <hsmukunda at walla.com> wrote:
>
>
> Hi
>
> I am new to JDOM below is the piece of code which I have written.
>
> Element ele= new Element("root");
> Element name=new Element(jLabel1.getText().trim());
> Element age= new Element(jLabel2.getText().trim());
> ele.addContent(name);
> ele.addContent(s1);
> ele.addContent(age);
> ele.addContent(s2);
> Document doc=new Document(ele);
> FileOutputStream fout = new FileOutputStream("nameage.xml", true);
> Format format = Format.getRawFormat();
> format.setOmitDeclaration(true);
>
>
> XMLOutputter xmlout = new XMLOutputter(format);
> xmlout.output(doc,fout);
> fout.flush();
> fout.close();
>
>
>
> and the output will be printed to a xml file is
>
> <root><name />aaaaaaaaa<age />74</root>
>
> you could see the tags are not properly printed, I tried but I could not set
> right, could you please let me know what mistake I am making and how to
> rectify it.
>
> thanks and Regards
>
> Mukunda
>
>
>
>
>
>
>
> ________________________________
>
> Walla! Mail - get your free 3G mail today
> _______________________________________________
> To control your jdom-interest membership:
> http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com
>
>
More information about the jdom-interest
mailing list