[xml] Still trying to handle entities using the SAX interface


I'm writing here this message to talk again about what's in the subject.
(for Daniel Veillard : I wrote you a mail about this at your direct address - 
I'm sorry, maybe I should have written it before here). 

For what concerns the subject of the message, I tried by following this 
approach :

- I passed my own SAX handler to xmlSAXUserParseMemory with the following 
callbacks set :

- I wrote the two callbacks this way :

void EntityDeclElement(void *userData, const CHAR *name, int type, const CHAR 
*pubID, const CHAR *sysID, CHAR *content)
    UserData    *userdata = userData;
D(PRN)  fprintf(stdout, "EntityDeclElement : name [%s] type [%d] public ID 
system ID [%s] content [%s]\n",
                name, type, pubID, sysID, content);
    if (AddEntityToTable(userdata->tbl, name, type, pubID, sysID, content) == 
        fprintf(stderr, "Warning: could not add declared entity to entities 

xmlEntityPtr EntityElement(void *userData, const CHAR *s)
    UserData    *userdata = userData;
    xmlEntityPtr    currentEntity;
D(PRN)  fprintf(stdout, "EntityElement (userdata: [%p] - %s): path: %s\n", 
userdata, s, userdata->path);
    if ((currentEntity = xmlGetPredefinedEntity(s)) != NULL)
        return((xmlEntityPtr) xmlHashLookup(userdata->tbl, s));

- I also added an helper function to add an entity to a table, which is 
called by the EntityDeclElement callback 

On the execution of the program, after the entity reference into the element 
is reached (the one into the attributes does not cause any harm), it dies 
with a segmentation fault, and I have discovered that this happens because my 
characters() callback is being called with a wrong user_data parameter, which 
does not point to the user_data I initially passed to xmlSAXUserParseMemory. 

I discovered that line 4931 in parser.c is triggering the error :

ret = xmlParseBalancedChunkMemory(ctxt->myDoc,
        ctxt->sax, NULL, ctxt->depth,
        value, &list);

The problem is that the third parameter should be a pointer to my initial 
user_data, instead it is passed as NULL, so from within the called function 
the original value is lost, and eventually my characters() callback function 
is called with the wrong user_data.

I modified the line in this way :

ret = xmlParseBalancedChunkMemory(ctxt->myDoc,
        ctxt->sax, ctxt->userData, ctxt->depth,
        value, &list);

My program works as I expected, but I reran the "make check" and I have 
discovered that MANY tests, mainly those related to entities but also others 
that contain entities, don't work anymore as they should.

For what I have so far understood about how the library works, it is certain 
that the change I have made impacts also on the normal DOM building behaviour.
What I think is that ctxt->userData should be passed instead of NULL only if 
the parsing was initially called from the SAX API functions, but apparently 
there is nothing which indicates this. :-(
Before going further, do you think this is the right approach to follow 
(except using the DOM API) ?


        Fabrizio Ammollo

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