[jdom-interest] Is it possible in JDOM...?

Benjamin Kopic benjamin.kopic at pancontext.com
Tue Oct 1 02:05:46 PDT 2002


You need to detach the element from its original parent.
 
//apply being the root element of our original tree
 
List children = apply.getChildren();
ListIterator iterator = children.listIterator(1);

Element root = new Element("root");
Element newElem = new Element("eq");
root = root.addContent(newElem);
for(int i=0; i<2; i++) {
  Element nextElement = (Element) iterator.next();
  root = root.addContent(nextElement.detach());
}


> -----Original Message-----
> From: jdom-interest-admin at jdom.org
> [mailto:jdom-interest-admin at jdom.org]On Behalf Of Meghasyam Bokam
> Sent: 01 October 2002 09:53
> To: jdom-interest at jdom.org
> Subject: [jdom-interest] Is it possible in JDOM...?
> 
> 
> Dear all,
> 
>   I am trying to construct a new subtree from the original xml tree.
> 
> I have :
> 
> <apply>
>   <eq />
>   <ci> a </ci>
>   <ci> b </ci>
>   <ci> c </ci>
> </apply>
> 
> I need :
> 
> <root>
>   <eq />
>   <ci> a </ci>
>   <ci> b </ci>
> </root>
> 
> The code is :
> 
> //apply being the root element of our original tree
> 
> 	List children = apply.getChildren();
> 	ListIterator iterator = children.listIterator(1);
> 
> 	Element root = new Element("root");
> 	Element newElem = new Element("eq");
> 	root = root.addContent(newElem);
> 	for(int i=0; i<2; i++)
> 	{
> 		Element nextElement = (Element) iterator.next();
> 		root = root.addContent(nextElement);
> 	}
> 
> 
> I am getting the error as :
>     IllegalAddException : The ci already has an existing parent "apply"
> 
> 
> Can anybody help me how to do get the subtree?
> 
> Thank You.
> 
> Meghasyam.
> 
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@y
ourhost.com



More information about the jdom-interest mailing list