[jdom-interest] Exception when creating a document from arraylist
X.P.Pratibha :-)
xp_pratibha at HotPOP.com
Sat Jun 11 05:21:33 PDT 2005
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);
}
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);
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.jdom.org/pipermail/jdom-interest/attachments/20050611/72ac9a1a/attachment.htm
More information about the jdom-interest
mailing list