Re: setting document root element

I think the approach taken so far is correct. The root node belongs only to 
the document object and this one has to manage it.
Even if any node cannot live outside the Document node, i don't think that 
an element should be allowed to modify the structure of the document in 
which resides. I think this is a good separation, even if the coding gets 
somehow ugly following this approach (i agree to that).
A compromise approach would be to introduce a special node object in the 
DOM, called RootElement, or something like that, but i don't think it is 
worthing to go that way.

--Razvan

At 09:46 AM 9/19/01 -0700, Garret Wilson wrote:
>DOM 2 allowed the creation of a document root element only at the time the
>element it created. However, there are *many* instances when one wants to
>construct the root element in the same manner as the other elements. (After
>all, the root element is only different from the other elements in its
>location in the tree.)
>
>Take, for instance, serializing a Java object to some XML representation by
>using the DOM:
>
>main
>{
>   Object object; //object to serialize
>   Document doc=DOMImplementation.createDocument();
>   Element root=createElement(object);
>   doc.setRoot(root);
>}
>
>Element createElement(Document doc, Object object)
>{
>   Element element=doc.createElement(object.name);
>   for each element attribute
>   {
>     Element child=createElement(object.property[i]);
>     element.appendChild(child);
>   }
>   return element;
>}
>
>Without the ability to set the document root, the elegant code above is
>forced to special-case creation of the root element.
>
>What's the status of this capability, and where can I go to find out more?
>
>Thanks,
>
>Garret

__________________________________________________________________
Razvan Costea-Barlutiu
Department of Radiology,
The University of Chicago
5841 South Maryland Avenue
Chicago, Illinois 60637
Phone: (773)834-5106
E-Mail: cbrazvan@baltan.bsd.uchicago.edu

Received on Wednesday, 19 September 2001 13:10:46 UTC