Re: [xml] Entity with elements inside it?



Hi Daniel and libxml hackers,

    After some more dig into both my code and libxml2 source code, I
finally find the root of my problem. But I think this problem is more
a libxml2 bug than my code's bug. Maybe my conclusion is wrong because
I am not very familiar with libxml2, but I think it is better to post
what I find here to help libxml2 be better.

    The game start at xmlParserCtxt, the context leave client a
userData which is used to hold the client private data. And when any
SAX callback is invoked in the process of parsing, the parser pass the
userData as the first param to the callback. Meanwhile, libxml2
provide a SAX2.c which contain a set of default callbacks. In my app,
I use the most of the default callbacks, but with some exception of
callback like startElementNs and startDocument. Because I have some
special work to do in my code, I must provide a userData, and also I
need to call some default SAX handlers, so, I should hold the
parserCtxt in my userData, so the struct like:

struct my_user_data {
     xmlParserCtxtPtr xml_ctx;
     some my private data;
};

Like above, when I should call the default SAX handlers, I just pass
the my_user_data->xml_ctx as its first param, and everything works
until now.

Now, the problem is coming. When parsing Entity_Ref, the parser will
try to parse the entity content to compose a sub-dom-tree. For parsing
the content, the parser create a new xmlParserCtxt, and assign the
current context's sax handler, userData to the new one and then use
the new one parse the content. It is just the problem. When the new
context use the same userData with the old one, so the same handler is
called, and my handler pass the OLD CONTEXT to the default SAX
callback, this make all things wrong. And this make the result that
"my entity content is not parsed at all" . :)  The code is mainly at
parser.c xmlParseReference and xmlParseBalancedChunkMemoryInternal.

I think the way I use libxml is rationale, because I just try to use
as more default functions as possible.  So, I think maybe it is better
to pass the whole ParserCtxt to the callback and let the client get
its private data if he need it.

I just post what I find and my simple idea here, any comment is
welcomed. And please help on my problems, thanks!

Regards!
Bo



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]