Re: [xml] Embedding DTD into document

Date view Thread view Subject view Author view

From: Daniel Veillard (Daniel.Veillard@w3.org)
Date: Fri Jun 16 2000 - 04:39:27 EDT


On Thu, Jun 15, 2000 at 12:48:51PM -0600, Greg Sjaardema wrote:
> 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....

  This looks correct. I suggest you upgrade to libxml-2.x.x since I fixed
*a lot* of XML problems. Even better use the CVS base version,

Daniel

-- 
Daniel.Veillard@w3.org | W3C, INRIA Rhone-Alpes  | Today's Bookmarks :
Tel : +33 476 615 257  | 655, avenue de l'Europe | Linux XML libxml WWW
Fax : +33 476 615 207  | 38330 Montbonnot FRANCE | Gnome rpm2html rpmfind
 http://www.w3.org/People/all#veillard%40w3.org  | RPM badminton Kaffe
----
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