Re: [xml] Allocating entities dynamically, without pre-existing DTD while using SAX



On Wed, Feb 19, 2003 at 12:58:13AM +0100, Marek Habersack wrote:
I need to make it possible for the document parser to dynamically define
entities based on the user's input (in shape of an RXML - a Caudium's
extendable markup language). I cannot pre-define a DTD because most of the
entities defined by the webserver have values assigned on a per-request
basis and they can change at any time the document is parsed/reparsed. I'm

  Hum, this is a bad start. Basically an XML document without a DOCTYPE
and using unknown entities is not well-formed. So it seems the basic
choice of using entities for "variables" is not a a really good one :-\

using the SAX interface since a) the server must be able to parse an
arbitrary number of documents of unknown size, b) the xmlreader doesn't seem
to be able to handle dynamic allocation/definition of entities at all. So
far, I see three ways of doing what I want, they are:

 1. use the getEntity() handler in the handler struct and allocate the
    entities there by calling xmlAddDocEntity or xmlAddDtdEntity. 

  it looks like the solution which will "make it work" the most easilly
BUT you must be aware that the markup templates won't be XML then !

 2. inject the entity DTD definitions into the document's preamble just
    before parsing it.

   Ugly, really ... worse of both worlds.

 3. add an external reference to the DTD that points back to the site
    handled by our server and read the DTD from there. The DTD would be
    generated dynamically by the server.

  this is actually the cleanest solution because your templates are
well formed XML now ! But this may cost a bit more at run-time I agree.

  Those are the three scenarios I came up with, not knowing XML2 good enough
to find any other way out of the problem. My favorite scenario is, of
course, #1 -- but the question is whether it's possible to define the
entities in such way as described? Is it safe for me to muck with xmlEntity
directly and allocate and populate the structure by hand without calling
down to the XML2 API? I would love to get rid of our current XML parser we
are using since XML2 is so much faster, so much more featured that it is,
IMO, the only viable alternative to what we have now. Any help will be
greately appreciated.

  You can bypass the APIs and use the structures directly. Since I expose
them it's possible, but this will require some work to make sure it's
stable and doesn't leak. This sounds possble, but this will probably
require a bit of debugging.

Daniel

-- 
Daniel Veillard      | Red Hat Network https://rhn.redhat.com/
veillard redhat com  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]