[jdom-interest] Jdom AddChild

Kesav Kumar kesavk at voquette.com
Fri Apr 6 10:39:02 PDT 2001


Try this

import org.jdom.output.*;
import org.jdom.*;

public class JDOMTest
{
	public static void main(String args[])
	{
		try
		{
			Element root = new Element("Unix");
			Document doc = new Document(root);
			Element hello = new Element("helloagain");
			hello.addContent("helloagain bye");
			root.addContent(hello);

			XMLOutputter outputter = new XMLOutputter("\t",
true);
			outputter.setTrimText(true);
			outputter.output(doc, System.out);
		} catch(Exception ex)
		{
			ex.printStackTrace(System.err);
		}
	}
}

Kesav Kumar
Software Engineer
Voquette, Inc.
650 356 3740
mailto:kesavk at voquette.com
http://www.voquette.com
Voquette...Delivering Sound Information


-----Original Message-----
From: Simphoukham, Southin [mailto:Southin.Simphoukham at westgroup.com]
Sent: Friday, April 06, 2001 10:16 AM
To: jdom-interest at jdom.org
Subject: FW: [jdom-interest] Jdom AddChild


Jason,

Thanks for the information.  I did check it out.  I am slowly moving through
the examples but still confused.

I would like to know how you would write the following using jdom

<Bears>
	<Northern>
		Grizzlie
	</Northern>
	<Southern>
		Black
	<Southern>
	<Western>
		Kodiak
	</Western>
</Bears>

The root.addContent(new Element(something, something));

 root.addContent(new Element("Unix", "unix"));
 root.addContent(new Element("Hello","helloagain","bye"));
 XMLOutputter fmt = new XMLOutputter();
 fmt.output(doc,out);

gives me this:

<Unix xmlns="unix" />
<helloagain:Hello xmlns:helloagain="bye" />

when I want this
	
<Unix>
	<helloagain>
		helloagain bye
	</helloagain>
</Unix>

Thanks,

Southin Simphoukham


-----Original Message-----
From: Jason Hunter [mailto:jhunter at collab.net] 
Sent: Friday, April 06, 2001 11:47 AM
To: Simphoukham, Southin
Cc: 'jdom-interest at jdom.org'
Subject: Re: [jdom-interest] Jdom AddChild


"Simphoukham, Southin" wrote:
> 
> Hi,
> 
> I am new to using Jdom so I am using the Java and XML by O'Reilly as a
> guide.   I am working on creating an XML file from scratch page 369.  

See the JDOM faq at jdom.org and look for discussion about the book
being out of date.

> What
> happened to the Element.addChild method?  I assume it is depreciated.  How
> can I add a child element?  Any examples would be great.

The method you want is addContent().

-jh-
_______________________________________________
To control your jdom-interest membership:
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhos
t.com



More information about the jdom-interest mailing list