On Mon, Apr 02, 2007 at 07:41:07PM +0200, Joachim Zobel
wrote:
> Hi.
>
> I set up a parser context rather straightforward
>
> memset(&fctx->handler, 0,
sizeof(xmlSAXHandler));
>
//xmlSAX2InitDefaultSAXHandler(&fctx->handler, 0);
> /*
> * Set handlers
> */
> #define CALLBACK(fn,hdl) fctx->handler.fn = hdl
> CALLBACK(startDocument,
xml2_bucket_create_xml_decl);
> CALLBACK(comment, xml2_bucket_create_comment);
> CALLBACK(startElementNs,
xml2_bucket_create_start);
> CALLBACK(endElementNs, xml2_bucket_create_end);
> CALLBACK(ignorableWhitespace,
xml2_bucket_create_white);
> CALLBACK(cdataBlock, xml2_bucket_create_cdata);
> CALLBACK(characters,
xml2_bucket_create_character);
> CALLBACK(processingInstruction,
xml2_bucket_create_proc_instr);
> CALLBACK(warning, xml2_sax_warning);
> CALLBACK(error, xml2_sax_error);
> // mark as SAX2
> fctx->handler.initialized = XML_SAX2_MAGIC;
>
> /* set up the parser */
> fctx->sz_parsed = 0;
>
> xmlParserCtxt *parser =
xmlCreatePushParserCtxt(&fctx->handler,
>
fctx,NULL,0,NULL);
>
> with fctx of type
>
> typedef struct
> {
> xmlParserCtxt parser;
> ....
>
> When I then do
>
> xmlParserErrors err =
xmlParseChunk(&fctx->parser, buf, len, 0);
>
> the first call succeeds and the sax events are
generated.
>
> The second call however gives me an error 4 - Document
is empty. I know
> from the trace log this is not true.
>
> Any hints what is going wrong (or shall I simply
continue searching for
> memory corruption)?
1/ do NOT use SAX unless you really know what you are
doing and/or
want to shave microseconds. Use the reader instead
http://xmlsoft.org/
xmlreader.html
2/ the code is incomplete, no way I can guess what's going
on
e.g. where is fctx->parser initialized ?
3/ I suggest to follow the guidelines
http://xmlsoft.org/bugs.
html
try with xmllint --push on your document , verify it
work, then
base you code on xmllint.c section where --push is
implemented.
that should show how to use the push section, for the
SAX block initialization see the section for --sax
option
Daniel
--
Red Hat Virtualization group http://redhat.com/v
irtualization/
Daniel Veillard | virtualization library http://libvirt.org/
veillard redhat.com | libxml GNOME XML XSLT toolkit http://xmlsoft.org/
http://veillard.com/ |
Rpmfind RPM search engine http://rpmfind.net/
_______________________________________________
xml mailing list, project page http://xmlsoft.org/
xml gnome.org
http://mai
l.gnome.org/mailman/listinfo/xml
|