Re: error on appendChild

Armelle,

A Document can have only ONE child of type ELEMENT_NODE (this is the
"document element"). 

see DOM spec :
http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-1590626202 

If you replace doc.appendChild(....) by element.appendChild(...) in
insertFragment this should solve your problem even if I'm not sure it
will give the result you are expecting...

CLECH Armelle FTRD/DMI/LAN wrote:
> 
> I am kind of lost here.
> my code is the following. I have a
> [test] org.apache.xerces.dom.DOMExceptionImpl: DOM006 Hierarchy request
> error
> [test] org.apache.xerces.dom.DOMExceptionImpl: DOM006 Hierarchy request
> error
> on the appendChild call in insertFragment method. If I remove this two lines
> It works really fine.
> Can anyone help please .
> 
> main
> {
>         DocumentImpl docum = new DocumentImpl();
> 
>         DocumentFragment
> docC=requeteCollecte.cpgnCreation(array,dateModif,docum);
>         // I create the fragment with this method : DocumentFragment doc =
> docum.createDocumentFragment();
> 
>         Document doc = requeteCollecte.insertFragment(docC,docum);
> }
> 
>     public Document insertFragment(DocumentFragment fragment, Document doc)
>     {
>         if(doc!=null)
>             {
>                 Element element = doc.createElement("creation");
>                 doc.appendChild(element);
>                 NodeList list = fragment.getChildNodes();
>                 if(list!=null)
>                     {
>                         for(int i=0;i<list.getLength();i++)
>                             {
>                                 doc.appendChild(list.item(i));
>                             }
>                     }
>                 NamedNodeMap att = fragment.getAttributes();
>                 if(att!=null)
>                     {
>                         for(int j=0;j<att.getLength();j++)
>                             {
>                                 doc.appendChild(att.item(j));
>                             }
>                     }
>             }
>         return doc;
>     }
> 
> Armelle Clech

-- 
Christophe

Received on Wednesday, 22 November 2000 05:03:47 UTC