<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>Code examples</TITLE>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.2900.2912" name=GENERATOR></HEAD>
<BODY>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=728091414-21072006>Please try to keep replies to the
list.</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=728091414-21072006></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=728091414-21072006>I'm not sure I'm following you completely, but if you
have two XML documents:</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=728091414-21072006><?xml version="1.0"?></SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=728091414-21072006><foo></SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=728091414-21072006>
<text>hello</text></SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=728091414-21072006></foo></SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=728091414-21072006></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=728091414-21072006><?xml version="1.0"?></SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=728091414-21072006><bar></SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=728091414-21072006>
<text>goodbye</text></SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=728091414-21072006></bar></SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=728091414-21072006></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=728091414-21072006>And wanted to combine them into some master document,
the code would look something like:</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=728091414-21072006></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=728091414-21072006>SAXBuilder builder = new
SAXBuilder();</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=728091414-21072006>Document fooDoc =
builder.build("foo.xml");</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=728091414-21072006>Document barDoc =
builder.build("bar.xml");</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=728091414-21072006></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=728091414-21072006>Document masterDoc = new
Document();</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=728091414-21072006>Element master = new
Element("master");</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=728091414-21072006>masterDoc.setRootElement(master);</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=728091414-21072006></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=728091414-21072006>Element foo =
fooDoc.getRootElement();</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=728091414-21072006>foo.detach(); // VERY IMPORTANT</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=728091414-21072006>master.addContent(foo);</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=728091414-21072006></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=728091414-21072006>Element bar =
barDoc.getRootElement();</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=728091414-21072006>bar.detach(); // AGAIN, VERY
IMPORTANT</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=728091414-21072006>master.addContent(bar);</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=728091414-21072006></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=728091414-21072006>The call to detach() is necessary because an Element
can have only one parent.</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=728091414-21072006></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=728091414-21072006>Hope this helps.</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=728091414-21072006></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=728091414-21072006></SPAN></FONT> </DIV><BR>
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> Heise, Robert
[mailto:Robert.Heise@Peopleclick.com] <BR><B>Sent:</B> Friday, July 21, 2006
10:13 AM<BR><B>To:</B> Edelson, Justin<BR><B>Subject:</B> RE: [jdom-interest]
Code examples<BR></FONT><BR></DIV>
<DIV></DIV>
<DIV dir=ltr align=left><SPAN class=962150514-21072006><FONT face=Arial
color=#0000ff size=2>Thanks for the reply.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=962150514-21072006><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=962150514-21072006><FONT face=Arial
color=#0000ff size=2>Bare with me on this one:</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=962150514-21072006><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=962150514-21072006><FONT face=Arial
color=#0000ff size=2>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:</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=962150514-21072006><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=962150514-21072006><FONT face=Arial
color=#0000ff size=2><RIBCL VERSION="2.0"><BR> <LOGIN
USER_LOGIN="adminname" PASSWORD="password"></FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=962150514-21072006><FONT face=Arial
color=#0000ff size=2><FONT color=#ff0000> ********** OTHER STUFF
Will go here ********************</FONT><BR>
</LOGIN><BR></RIBCL></FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=962150514-21072006><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=962150514-21072006><FONT face=Arial
color=#0000ff size=2>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?</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=962150514-21072006><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=962150514-21072006><FONT face=Arial
color=#0000ff size=2>Thanks</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=962150514-21072006><FONT face=Arial
color=#0000ff size=2>Rob</FONT></SPAN></DIV><BR>
<BLOCKQUOTE dir=ltr
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px solid; MARGIN-RIGHT: 0px">
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> Edelson, Justin
[mailto:Justin.Edelson@mtvn.com] <BR><B>Sent:</B> Friday, July 21, 2006 9:48
AM<BR><B>To:</B> Heise, Robert; jdom-interest@jdom.org<BR><B>Subject:</B> RE:
[jdom-interest] Code examples<BR></FONT><BR></DIV>
<DIV></DIV>
<DIV dir=ltr align=left><SPAN class=025234513-21072006><FONT face=Arial
color=#0000ff size=2>A Document can contain only one child Element. You should
use the setRootElement()/getRootElement() methods to change the document's
root element.</FONT></SPAN></DIV><BR>
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> jdom-interest-bounces@jdom.org
[mailto:jdom-interest-bounces@jdom.org] <B>On Behalf Of </B>Heise,
Robert<BR><B>Sent:</B> Friday, July 21, 2006 9:20 AM<BR><B>To:</B>
jdom-interest@jdom.org<BR><B>Subject:</B> [jdom-interest] Code
examples<BR></FONT><BR></DIV>
<DIV></DIV><!-- Converted from text/rtf format -->
<P><FONT face=Arial size=2>Does anybody have any code examples for adding and
removing Elements in a JDOM Document using addContent/removeContent?
</FONT></P>
<P><FONT face=Arial size=2>When using the addContent method Im receiving the
following trace:</FONT> <BR><FONT face=Arial
size=2>org.jdom.IllegalAddException: Cannot add a second root element, only
one is allowed</FONT> </P>
<P><FONT face=Arial size=2>Im struggling with adding using the index option as
well, so any examples would help me figure out what Im doing wrong.</FONT>
</P>
<P><FONT face=Arial size=2>Thanks in advance</FONT> <BR><FONT face=Arial
size=2>Rob</FONT> </P></BLOCKQUOTE></BODY></HTML>