[jdom-interest] Code examples

Edelson, Justin Justin.Edelson at mtvn.com
Fri Jul 21 07:30:51 PDT 2006


Please try to keep replies to the list.
 
I'm not sure I'm following you completely, but if you have two XML
documents:
<?xml version="1.0"?>
<foo>
    <text>hello</text>
</foo>
 
<?xml version="1.0"?>
<bar>
    <text>goodbye</text>
</bar>
 
And wanted to combine them into some master document, the code would
look something like:
 
SAXBuilder builder = new SAXBuilder();
Document fooDoc = builder.build("foo.xml");
Document barDoc = builder.build("bar.xml");
 
Document masterDoc = new Document();
Element master = new Element("master");
masterDoc.setRootElement(master);
 
Element foo = fooDoc.getRootElement();
foo.detach(); // VERY IMPORTANT
master.addContent(foo);
 
Element bar = barDoc.getRootElement();
bar.detach(); // AGAIN, VERY IMPORTANT
master.addContent(bar);
 
The call to detach() is necessary because an Element can have only one
parent.
 
Hope this helps.
 
 

________________________________

From: Heise, Robert [mailto:Robert.Heise at Peopleclick.com] 
Sent: Friday, July 21, 2006 10:13 AM
To: Edelson, Justin
Subject: RE: [jdom-interest] Code examples


Thanks for the reply.
 
Bare with me on this one:
 
The problem im trying to solve is I have a bunch of class's that return
a JDOM Document.  I have a parent (root) class that also is a Document.
This parent looks like this:
 
<RIBCL VERSION="2.0">
  <LOGIN USER_LOGIN="adminname" PASSWORD="password">
 ********** OTHER STUFF Will go here ********************
   </LOGIN>
</RIBCL>
 
I need to find a way to insert and remove Documents and their
corresponding XML in the above section.  Do i get the LOGIN element then
modify that element or start with root element?
 
Thanks
Rob


________________________________

	From: Edelson, Justin [mailto:Justin.Edelson at mtvn.com] 
	Sent: Friday, July 21, 2006 9:48 AM
	To: Heise, Robert; jdom-interest at jdom.org
	Subject: RE: [jdom-interest] Code examples
	
	
	A Document can contain only one child Element. You should use
the setRootElement()/getRootElement() methods to change the document's
root element.

________________________________

	From: jdom-interest-bounces at jdom.org
[mailto:jdom-interest-bounces at jdom.org] On Behalf Of Heise, Robert
	Sent: Friday, July 21, 2006 9:20 AM
	To: jdom-interest at jdom.org
	Subject: [jdom-interest] Code examples
	
	

	Does anybody have any code examples for adding and removing
Elements in a JDOM Document using addContent/removeContent? 

	When using the addContent method Im receiving the following
trace: 
	org.jdom.IllegalAddException: Cannot add a second root element,
only one is allowed 

	Im struggling with adding using the index option as well, so any
examples would help me figure out what Im doing wrong. 

	Thanks in advance 
	Rob 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.jdom.org/pipermail/jdom-interest/attachments/20060721/05c1b94b/attachment.htm


More information about the jdom-interest mailing list