[jdom-interest] Exception when creating a document from arraylist
X.P.Pratibha :-)
xp_pratibha at HotPOP.com
Sun Jun 12 21:05:42 PDT 2005
Hi all ,
Thanks for all your suggestion. The problem got solved after
detaching the elments from the parent .I have highlighted the changes I
made .
Thanks Brad ,Phil and Mark.
Regards,
Pratibha
X.P.Pratibha :-) wrote:
> Hi all,
> My problem is to edit an xml document to remove the duplicate
> entries it has before giving it to the XSL for display....
> Here goes my logic:
> 1)Get the document.
> 2) traverse it for duplicate entries and put all the unique entries
> into an array list
> 3) Then create the new document with elements in arraylist.
> 4)I am creating the root element and subroot element and adding the
> each element in my array list...Here I am getting the exception
> "*element* *already* *has* an existing *parent FWRules"
> --IllegalADDException.*
> <http://www.jdom.org/pipermail/jdom-interest/2001-October/007851.html>
>
> P.S :The elements in the list has elements which in turn has so many
> sub-elements...
>
> Can u please help me what I am doing wrong ???How to convert a list
> to Document again...I am using JDK1.3.1
>
> Element Oldelem =
> doc.getRootElement().getChild("Success").getChild("Rules");
>
> ListIterator OldIter =
> Oldelem.getChild("FWRules").getChildren("ConRule").listIterator();
> Vector ID_ref = new Vector();
> ArrayList new_list = new ArrayList();
> int count=0;
> while(OldIter.hasNext())
> {
> Element OldChildElem=((Element)
> OldIter.next());
> Element Attri =
> OldChildElem.getChild("FWRule");
> String
> ID=Attri.getAttributeValue("id");
_*Element detached =(Element)
OldChildElem.clone();*_
>
> count++;
> if(count<=1)
> {
> ID_ref.addElement(ID);
>
> new_list.add(*_detached_*);
>
>
> }
> else if(!ID.equals(ID_ref.elementAt(0)))
> {
> ID_ref.remove(0);
> ID_ref.addElement(ID);
> new_list.add(*_detached_*);
>
>
> }
> }
>
> Document Doc_New = new Document(new
> Element("Rules"));
> Element sub-elem =new Element("FWRules");
>
> for(int l=0;l<new_list.size();l++)
> {
> Element element_In_list =
> ((Element)new_list.get(l));
> XMLOutputter output =new XMLOutputter();
>
> System.out.println("XMLOutputter:"+output.outputString(output));
> *sub-elem.addContent(elment_In_list);
> //HERE IS where I get the exception*
> }
> Doc_New.getRootElement().addContent(subroot);
>
> }
>
>------------------------------------------------------------------------
>
>_______________________________________________
>To control your jdom-interest membership:
>http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.jdom.org/pipermail/jdom-interest/attachments/20050613/3be19a0e/attachment.htm
More information about the jdom-interest
mailing list