[jdom-interest] Code examples

Heise, Robert Robert.Heise at Peopleclick.com
Mon Jul 24 07:21:48 PDT 2006

Thanks for the examples. 
Using the flow of the below xml masterDoc.... Id like add xml (Document)
to the foo element instead of appending it to the end of fooDoc.  
Is it possible to merge Document's ? 
The reason Im trying to do it this way is my xml client has non-standard
xml and certain blocks use setExpandEmptyElements and other do not.
  <LOGIN USER_LOGIN="adminname" PASSWORD="password">
This is one Object of type Document.
Then I have other utilitary class's that return xml like the following:
I need to take this Document with its special formatting and insert into
the above xml after the LOGIN element.

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

	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"?>
	<?xml version="1.0"?>
	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");
	Element foo = fooDoc.getRootElement();
	foo.detach(); // VERY IMPORTANT
	Element bar = barDoc.getRootElement();
	bar.detach(); // AGAIN, VERY IMPORTANT
	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:
	  <LOGIN USER_LOGIN="adminname" PASSWORD="password">
	 ********** OTHER STUFF Will go here ********************
	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?


		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 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.jdom.org/pipermail/jdom-interest/attachments/20060724/9b0d44b9/attachment.htm

More information about the jdom-interest mailing list