W3C home > Mailing lists > Public > www-dom@w3.org > July to September 2001

setting document root element

From: Garret Wilson <garret@globalmentor.com>
Date: Wed, 19 Sep 2001 09:46:31 -0700
Message-ID: <00c701c1412a$b1768150$7245a640@odysseus2001>
To: "www-dom list" <www-dom@w3.org>
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
Received on Wednesday, 19 September 2001 12:49:08 GMT

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