[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.
 
ie:
 
<RIBCL VERSION="2.0">
  <LOGIN USER_LOGIN="adminname" PASSWORD="password">
</LOGIN>
</RIBCL>
 
This is one Object of type Document.
 
Then I have other utilitary class's that return xml like the following:
<RIB_INFO MODE="READ"><GET_FW_VERSION /></RIB_INFO>
 
I need to take this Document with its special formatting and insert into
the above xml after the LOGIN element.
 
Thanks
Rob
 
 
________________________________

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"?>
	<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/20060724/9b0d44b9/attachment.htm


More information about the jdom-interest mailing list