W3C home > Mailing lists > Public > www-dom@w3.org > January to March 2001

Ad Hoc Element Creation

From: Jeff Winter <Jwinter@zefer.com>
Date: Mon, 5 Feb 2001 11:54:51 -0500
Message-ID: <D858C92D51ACD311AB3C009027CC87E00265BAA5@zbosexchange.boston.zefer.com>
To: "'www-dom@w3.org'" <www-dom@w3.org>

I've been removing the dependency on the Oracle XML parser from some
server-side code and have run into an issue.  The current version of the
Oracle parser allows an Element to be created without reference to any

	Element e = new XMLElement("foo");

(This functionality will be deprecated in the next release of the parser
according to the Beta code.)  This is primarily being used when serializing
elements to XML, e.g.:

class foo {
   public Node toXml() {
      Element e = new XMLElement("foo");
      // add attributes and child elements, etc.
      return e;

The resulting Node can be added to any document without having to do a
cloneNode() since it isn't owned by any other document.

My question is:  what is the best way to provide for this type of behavior
in a parser-neutral way?  I can think of a couple of solutions:

1.  Create a global document and use that as an element factory.

This would seem to have a couple of problems: one, the resultant element
tree would have to be "cloneNode"-d before adding it to the new document;
and two, in a server-side environment, there would be an awful lot of
Elements being created that are owned by the factory document.

2.  Refactor the code so that the parent document that the element tree
would be added to is always around:

	Document doc = new XMLDocument();
	Element e = foo.toXml(doc);

This could be done, but it seems awkward to me.

What would be the best approach?  What was the reason behind Elements always
being created in the context of a specific document?

Received on Monday, 5 February 2001 11:54:49 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 20 October 2015 10:46:08 UTC