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 - 09:38:35 EST


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


Date view Thread view Subject view Author view

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