<!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>
<br>
Thanks for all your suggestion. The problem got solved after
detaching the elments from the parent .I have highlighted the changes I
made .<br>
Thanks Brad ,Phil and Mark.<br>
<br>
Regards,<br>
Pratibha<br>
<br>
X.P.Pratibha :-) wrote:
<blockquote cite="mid42AAD74D.1020507@HotPOP.com" type="cite">
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
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>
ListIterator OldIter =
Oldelem.getChild("FWRules").getChildren("ConRule").listIterator();<br>
Vector ID_ref = new Vector();<br>
ArrayList new_list = new ArrayList();<br>
int count=0;<br>
while(OldIter.hasNext())<br>
{<br>
Element OldChildElem=((Element)
OldIter.next());<br>
Element Attri =
OldChildElem.getChild("FWRule");<br>
String ID=Attri.getAttributeValue("id");
</blockquote>
<u><b>Element detached =(Element)
OldChildElem.clone();</b></u><br>
<blockquote cite="mid42AAD74D.1020507@HotPOP.com" type="cite">
<br>
count++;<br>
if(count<=1)<br>
{ <br>
ID_ref.addElement(ID);
<br>
new_list.add(<b><u>detached</u></b>);
<br>
<br>
}<br>
else if(!ID.equals(ID_ref.elementAt(0)))<br>
{ <br>
ID_ref.remove(0);<br>
ID_ref.addElement(ID);<br>
new_list.add(<b><u>detached</u></b>);
<br>
<br>
}<br>
}<br>
<br>
Document Doc_New = new Document(new
Element("Rules")); <br>
Element sub-elem =new Element("FWRules");
<br>
for(int l=0;l<new_list.size();l++)<br>
{ <br>
Element element_In_list =
((Element)new_list.get(l));<br>
XMLOutputter output =new XMLOutputter();<br>
System.out.println("XMLOutputter:"+output.outputString(output));<br>
<font color="#cc0000"> <big><b>sub-elem.addContent(elment_In_list);
//HERE IS where I get the exception</b></big></font><br>
}<br>
Doc_New.getRootElement().addContent(subroot);<br>
<br>
}
<pre wrap="">
<hr size="4" width="90%">
_______________________________________________
To control your jdom-interest membership:
<a class="moz-txt-link-freetext" href="http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com">http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com</a></pre>
</blockquote>
</body>
</html>