Re: [xml] Creating a DTD from a plain text buffer?

Date view Thread view Subject view Author view

From: Harry Blundell (harry@halcyoninc.com)
Date: Mon Oct 30 2000 - 11:26:48 EST


Okay, I've found the reason that I wasn't getting the <!DOCTYPE ... >
written to the file when I called xmlSaveFile - as well as setting
docPtr->intSubset = dtdPtr, I also needed to set

  docPtr->children = (xmlNodePtr) dtdPtr;
  docPtr->last = (xmlNodePtr) dtdPtr;

so that the DTD is a child of the document.

I haven't looked into why I'm getting the Bus Error, but I've found a new
problem (at least it is for me):

Daniel, in the new xmlIOParseDTD you provided, you call

  xmlNewDtd(ctxt->myDoc, BAD_CAST "none", BAD_CAST "none", BAD_CAST
            "none");

What's the purpose of the "none" for the ExternalID and SystemID?
When I attach the DTD to a document as an internal subset, and call
xmlValidateDocument on it, it fails because it can't resolve the external
entity "none". Similarly, when I call xmlSaveFile, I get the line

  <!DOCTYPE result PUBLIC "none" "none" [

I can work around it by setting

  dtdPtr->ExternalID = NULL;
  dtdPtr->SystemID = NULL;

after the call to xmlIOParseDTD, but is the "none" necessary for another
purpose?

Thanks,

Harry
----------------------------------------------------------------------
Harry Blundell Halcyon Inc. URL: http://www.HalcyonInc.com
2300 Yonge St., Suite 1801, Box 2419, Toronto ON M4P 1E4, Canada.
PHONE: 416-932-4631 FAX: 416-932-4711 EMAIL: harry@HalcyonInc.com

On Mon, 30 Oct 2000, Harry Blundell wrote:

>
> Thanks for the quick response!
>
> I have tried it and have two problems so far. One I think is yours,
> and one is mine.
>
> Yours (error handling not shown):
>
> char *dtdBuffer = ...;
> xmlParserInputBufferPtr dtdInputBufferPtr;
> xmlDtdPtr dtdPtr;
>
> dtdInputBufferPtr = xmlParserInputBufferCreateMem(dtdBuffer,
> strlen(dtdBuffer), XML_CHAR_ENCODING_UTF8);
> dtdPtr = xmlIOParseDTD(NULL, dtdInputBufferPtr,
> XML_CHAR_ENCODING_UTF8);
> xmlFreeParserInputBuffer(dtdInputBufferPtr);
>
> The call to xmlFreeParserInputBuffer caused a Bus Error, and the
> following stack trace:
>
> program terminated by signal BUS (Bus Error)
> Current function is xmlBufferFree
> 4223 if (buf->content != NULL) {
> (dbx) where
> =>[1] xmlBufferFree(buf = 0xbebebebe), line 4223 in "tree.c"
> [2] xmlFreeParserInputBuffer(in = 0xd50b8), line 806 in "xmlIO.c"
> ...
>
> I haven't looked into this further yet, because of my problem:
>
> If I comment out the call to xmlFreeParserInputBuffer, and continue on,
> when I eventually call xmlSaveFile, I don't get a <!DOCTYPE ... > written
> to the file. However, I also don't get a <!DOCTYPE ... > written when I
> replace the above stuff by a call to xmlParseDTD, and previous posts
> suggest that it should work.
>
> Here's what I do after the above:
>
> char *tagname = ...;
> char *filename = ...;
> xmlDocPtr docPtr;
> xmlNodePtr rootPtr;
>
> ...
>
> dtdPtr->name = xmlStrdup((xmlChar *) tagname);
>
> docPtr = xmlNewDoc((xmlChar *) "1.0");
>
> docPtr->intSubset = dtdPtr;
> dtdPtr->parent = docPtr;
> dtdPtr->doc = docPtr;
>
> rootPtr = xmlNewDocNode(docPtr, NULL, (xmlChar *) tagname, NULL)
> xmlDocSetRootElement(docPtr, rootPtr);
>
> ...
>
> xmlSaveFile(filename, docPtr)
>
> Any suggestions would be welcome.
>
> Thanks,
>
> Harry
> ----------------------------------------------------------------------
> Harry Blundell Halcyon Inc. URL: http://www.HalcyonInc.com
> 2300 Yonge St., Suite 1801, Box 2419, Toronto ON M4P 1E4, Canada.
> PHONE: 416-932-4631 FAX: 416-932-4711 EMAIL: harry@HalcyonInc.com
>
>
> On Sun, 29 Oct 2000, Daniel Veillard wrote:
>
> > On Sun, Oct 29, 2000 at 03:15:15PM -0500, Harry Blundell wrote:
> > >
> > > Hi,
> > >
> > > The only way that I could find to create a DTD as an internal subset was
> > > to call xmlParseDTD to read it from a file or URL (I haven't tried it
> > > yet, but I've seen some discussion on it, so I assume it works), and then
> > > attach the resulting node tree to my XML DOM.
> > >
> > > Is it possible (and convenient ;-) to have the DTD in a plain text buffer
> > > and parse that?
> >
> > Try the following patch, it provides:
> > xmlDtdPtr xmlIOParseDTD (xmlSAXHandlerPtr sax,
> > xmlParserInputBufferPtr input,
> > xmlCharEncoding enc);
> >
> > you can generate an xmlParserInputBufferPtr from memory using
> >
> > xmlParserInputBufferPtr
> > xmlParserInputBufferCreateMem (const char *mem, int size,
> > xmlCharEncoding enc);
> >
> > exported from xmlIO.h .
> > Warning I didn't tested the routine, tell me if this works :-)
> >
> > Daniel
> >
> > --
> > Daniel.Veillard@w3.org | W3C, INRIA Rhone-Alpes | libxml Gnome XML toolkit
> > Tel : +33 476 615 257 | 655, avenue de l'Europe | http://xmlsoft.org/
> > Fax : +33 476 615 207 | 38330 Montbonnot FRANCE | Rpmfind search site
> > http://www.w3.org/People/all#veillard%40w3.org | 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


Date view Thread view Subject view Author view

This archive was generated by hypermail 2b29 : Mon Oct 30 2000 - 11:43:42 EST