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

making Elements from strings

From: David Pickles <david.pickles@knowhowsystems.com>
Date: Tue, 22 Aug 2000 16:08:31 +0100
Message-ID: <20DFB68CA563D311A62B00E0293B591F06653C@EXCHANGE_SERVER>
To: www-dom@w3.org
Hi, 

Is there a way of taking a string which is an XML element (perhaps with many
other elements nested within it), and directly creating from it an Element
belonging to an already existing Document?

At present, to create an Element belonging to Document, doc, from such a
string, I  go through the following steps (I'm using XML4J):

- append "<?xml version=\"1.0\"?>" to the front of the string
- call org.apache.xerces.parsers.DOMParser to create a temporary document
from the string (wrapped in an InputSource)
- cast doc to DocumentImpl
- call importNode on the DocumentImpl, passing it the document element of
the temporary document,
     thus creating an equivalent Element which is owned by doc.

The creation of the temporary document seems to be a a waste of time and
space. Instead, what I'd like to be able to do is parse  the string straight
into an Element belonging to doc.  Are there any XML parsers which do this?
Is there any way of getting DOMPaser to do this? Is there any reason in
principle why this is not possible?

Thanks for any advice on this, 

David Pickles
Received on Tuesday, 22 August 2000 11:11:41 GMT

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