From: Gary Pennington (Gary.Pennington@uk.sun.com)
Date: Tue Feb 27 2001 - 11:20:50 EST
Hi,
I've done some more digging around and the problem that I have is that the
various data structures which are required from the DTD structure (e.g.
elements, attributes) are only created when the DTD is parsed. That occurs
when xmlValidateDocument is called, however I want to know what the valid
elements are without validating the document.
A hack which appears to work is to do the following :-
1. Create a new document.
2. Create a new internal subset with appropriate directions to my dtds.
3. Explicitly set ->extSubset of the document to the return of
xmlParseDTD(doc->intSubset->ExternalID, doc->intSubset->SystemID)
This causes the DTD to be parsed and all values required in the external
subset are created and loaded. After this I can use xmlGetDtdElementDesc (and
related functions) to look up definitions from the DTD.
Should the xmlNewDTD function do this for you? I tried using this first since
it explicitly manipulates the external subset, however it doesn't call
xmlParseDTD so it's currently useless for my purposes.
Here's a full code snippet in case my rambling is confusing
doc = xmlNewDoc(BAD_CAST "1.0");
xmlCreateIntSubset(doc, BAD_CAST "host_rm",
BAD_CAST "-//XXX//YYY//EN",
BAD_CAST "file:///tmp/rm_all.dtd");
doc->extSubset = xmlParseDTD(doc->intSubset->ExternalID,
doc->intSubset->SystemID);
Gary
Daniel Veillard wrote:
> On Mon, Feb 26, 2001 at 11:40:42AM +0000, Gary Pennington wrote:
> >
> > Hi,
> >
> > I have a problem which I'm not sure about how to solve most efficiently
> > using libxml, so any ideas/pointers would be appreciated.
> >
> > I am writing a library which will create xml elements for insertion into
> > a document (which is also created at runtime) which will then be
> > validated. A lot of my elements carry default or fixed attributes and
> > I'd like to make the API for creating these elements as simple as
> > possible. Thus, when a user calls a function to create an element, I'd
> > like that element to be populated with all the fixed and default
> > attribute values (which may be retrieved from the DTD).
> >
> > The problem I have is how to extract all this information from the
> > DTD and use it when new elements are created? I've tried to create a doc
> > and associate a DTD with the doc (using xmlCreateIntSubset) which works
> > fine from a validation point of view. However, any elements that are
> > created are not populated with values from the DTD, which defeats the
> > purpose of what I'm trying to achieve.
> >
> > Anybody got any suggestions?
> >
> > Gary
> >
> > PS I tried investigating the xmlGetDtdElementDesc function but could
> > never get a definition for my elements (only a NULL pointer).
>
> Hum, that's strange because that's what the validation process uses
> Basically this is the function you need to call, you will get the
> XML Element declaration element associated to the name, then there
> is an attribute declaration list that you need to follow to find
> all the associated attribute as defined in the DTD, then add the ones
> which are defaulted or fixed.
>
> Daniel
>
> --
> Daniel Veillard | Red Hat Network http://redhat.com/products/network/
> veillard@redhat.com | libxml Gnome XML toolkit http://xmlsoft.org/
> http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/
> ----
> Message from the list xml@rpmfind.net
> Archived at : http://xmlsoft.org/messages/
> to unsubscribe: echo "unsubscribe xml" | mail majordomo@rpmfind.net
---- Message from the list xml@rpmfind.net Archived at : http://xmlsoft.org/messages/ to unsubscribe: echo "unsubscribe xml" | mail majordomo@rpmfind.net
This archive was generated by hypermail 2b29 : Tue Feb 27 2001 - 12:43:32 EST