W3C home > Mailing lists > Public > www-dom@w3.org > October to December 2000

Re: error on appendChild

From: Christophe Jolif <cjolif@ilog.fr>
Date: Wed, 22 Nov 2000 11:01:56 +0100
Message-ID: <3A1B9994.B0E679B6@ilog.fr>
To: CLECH Armelle FTRD/DMI/LAN <armelle.clech@rd.francetelecom.fr>
CC: www-dom@w3.org
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 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Friday, 22 June 2012 06:13:48 GMT