Re: [xml] Embedding DTD into document

Date view Thread view Subject view Author view

From: Greg Sjaardema (gdsjaar@sandia.gov)
Date: Thu Jun 15 2000 - 14:48:51 EDT


Daniel Veillard wrote:

> On Thu, Jun 01, 2000 at 01:43:36PM -0600, Greg Sjaardema wrote:
> > I am using XML as the basis for describing the syntax of the commands
> > that a code parser understands. The syntax for each command or block of
> > commands is described in a single file. A separate application was
> > written that reads all of the individual files, verifies their
> > structure, verifies correct nesting of commands and that all referenced
> > commands are defined, strips out data and comments, and then writes an
> > XML file containing all of the commands in a single file. This is all
> > working great, but I would also like to output the DTD at the beginning
> > of this file so there is only a single file to move to different
> > platforms, and other considerations. I have been unable to find the
> > correct sequence of calls that would let me read in the external DTD and
> > then write it out as an 'internal' DTD in my concatenated XML file.
> >
> > Is this possible, if so, where should I look in the documentation.
>
> Something like the following:
>
> {
> xmlDocPtr doc = xmlParseFile(...);
> xmlDtdPtr dtd = xmlParseDTD(NULL, ...);
>
> doc->InternalSubset = dtd;
>
> xmlSaveFile(..., doc);
> xmlFreeDoc(doc); /* do not free the Dtd twice */
> }
>
> Doc is in:
> http://xmlsoft.org/gnome-xml-parser.html for xmlParseDTD ()
> and xmlParseFile()
> http://xmlsoft.org/gnome-xml-tree.html for xmlSaveFile ()
>
> Daniel

The above didn't seem to work (with version 1.8.6). I think I have it
working by doing the following:

xmlDocPtr doc = xmlNewDoc((xmlChar*)"1.0");
xmlDtdPtr dtd = xmlParseDTD(NULL, filename_of_dtd);
dtd->name = xmlStrDup((xmlChar*)"root_name");

doc->intSubset = dtd;
doc->children = (xmlNodePtr)dtd;
dtd->doc = doc;

xmlNodePtr root = dtd->next = xmlNewDocNode(doc, NULL, (xmlChar*)"root_name",
NULL);

... Fill in the rest of the nodes off of the root node.

Does this look correct, or am I doing something stupid....

Thanks, Greg

----
Message from the list xml@xmlsoft.org
Archived at : http://xmlsoft.org/messages/
to unsubscribe: echo "unsubscribe xml" | mail  majordomo@xmlsoft.org


Date view Thread view Subject view Author view

This archive was generated by hypermail 2b29 : Wed Aug 02 2000 - 12:30:15 EDT