[jdom-interest] Exception when creating a document from arraylist
    Bradley S. Huffman 
    hip at a.cs.okstate.edu
       
    Sun Jun 12 10:25:18 PDT 2005
    
    
  
"X.P.Pratibha :-)" writes:
> This is a multi-part message in MIME format.
> --===============1125767959==
> Content-Type: multipart/alternative;
> 	boundary="------------000501060705090303010009"
> 
> This is a multi-part message in MIME format.
> --------------000501060705090303010009
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
> Content-Transfer-Encoding: 7bit
> 
> 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");   
>                                                     
>                              count++;
>                              if(count<=1)
>                              {                               
>                                  ID_ref.addElement(ID);                 
>               
>                                  new_list.add(OldChildElem);  
OldChildElem is still attached to it's orignal parent.
>                       
> 
>                              }
>                              else if(!ID.equals(ID_ref.elementAt(0)))
>                              {                               
>                                  ID_ref.remove(0);
>                                  ID_ref.addElement(ID);
>                                  new_list.add(OldChildElem);           
>                 
> 
>                              }
>                          }
> 
>                         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);
> 
>                      }
> 
> --------------000501060705090303010009
> Content-Type: text/html; charset=ISO-8859-1
> Content-Transfer-Encoding: 7bit
> 
> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
> <html>
> <head>
>   <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
> </head>
> <body bgcolor="#ffffff" text="#000099">
> Hi all,<br>
>        My problem is to edit an xml document to
>  remove the duplicate
> entries it has before giving it to the XSL for display....<br>
> Here goes my logic:<br>
>  1)Get the document.<br>
> 2) traverse it for duplicate entries and put all the unique entries
> into an array list<br>
> 3) Then create the new document with elements in arraylist.<br>
> 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 <br>
> "<a onmousedown="return clk(this,'res',1,'')"
>  href="http://www.jdom.org/pipermail/jdom-interest/2001-October/007851.html">
> <b>element</b>
> <b>already</b> <b>has</b> an existing <b>parent FWRules"
> --IllegalADDException.</b></a><br>
> <br>
> P.S :The elements in the list has elements which in turn has so many
> sub-elements...<br>
> <br>
> Can u please help me what I am doing wrong ???How to convert  a list to
> Document again...I am using JDK1.3.1<br>
>          <br>
>                     Element
>  Oldelem =
> doc.getRootElement().getChild("Success").getChild("Rules");    
> ;  
>              
> ;   <br>
>               &nb
> sp;          ListIterator OldIte
> r =
> Oldelem.getChild("FWRules").getChildren("ConRule").listIterator();<br>
>               &nb
> sp;          Vector ID_ref = new
>  Vector();<br>
>               &nb
> sp;          ArrayList new_list 
> = new ArrayList();<br>
>               &nb
> sp;          int count=0;<br>
>               &nb
> sp;          while(OldIter.hasNe
> xt())<br>
>               &nb
> sp;          {<br>
>                  
>             Element OldChildElem
> =((Element)
> OldIter.next());<br>
>                  
>             Element Attri =
> OldChildElem.getChild("FWRule");<br>
>                  
>             String ID=Attri.getA
> ttributeValue("id");  
>                 &
> nbsp;                 
>                 &
> nbsp;  <br>
>                  
>             count++;<br>
>                  
>             if(count<=1)<br>
>                  
>             {    
>                  
>            <br>
>                  
>                 I
> D_ref.addElement(ID);            
> ;    
>                <br>
>               &nb
> sp;            &n
> bsp;     new_list.add(OldChildElem); 
>              
> ;          <br>
> <br>
>                  
>             }<br>
>                  
>             else if(!ID.equals(I
> D_ref.elementAt(0)))<br>
>                  
>             {    
>                  
>            <br>
>                  
>                 I
> D_ref.remove(0);<br>
>                  
>                 I
> D_ref.addElement(ID);<br>
>                  
>                 n
> ew_list.add(OldChildElem);          
>                &n
> bsp; <br>
> <br>
>                  
>             }<br>
>                  
>         }<br>
> <br>
>                  
>        Document Doc_New = new Document(new
> Element("Rules"));          
> ;      <br>
>                  
>        Element sub-elem =new Element("FWRules");&nbs
> p;    
>                  
>                  
>                 &
> nbsp; <br>
>                  
>        for(int l=0;l<new_list.size();l++)<br>
>                  
>        {       &n
> bsp;            &
> nbsp;  <br>
>              
> ;            &nbs
> p; Element element_In_list =
> ((Element)new_list.get(l));<br>
>              
> ;            &nbs
> p; XMLOutputter output =new XMLOutputter();<br>
>                 &
> nbsp;         
> System.out.println("XMLOutputter:"+output.outputString(output));<br>
>              
> ;            &nbs
> p;<font color="#cc0000"> <big><b>sub-elem.addContent(elment_In_list);
> //HERE IS where I get the exception</b></big></font><br>
>                 &
> nbsp;      }<br>
>                  
>         Doc_New.getRootElement().addContent(sub
> root);<br>
> <br>
>                  
>     }
> </body>
> </html>
> 
> --------------000501060705090303010009--
> 
> --===============1125767959==
> Content-Type: text/plain; charset="us-ascii"
> MIME-Version: 1.0
> Content-Transfer-Encoding: 7bit
> Content-Disposition: inline
> 
> _______________________________________________
> To control your jdom-interest membership:
> http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com
> --===============1125767959==--
    
    
More information about the jdom-interest
mailing list