How to interrupt the TSAXParser?

Hello all,

I work on a large project using ROOT and I am optimizing the code a little.

I need to parse an XML file but not the whole file, just the “first part”. The second part which could be long is just data that I don’t need.

I use a SaxParser because my xml file could be heavy. I am looking for interrupting it after the first part but I don’t find how to do it.

There is a link between the TSAXParser and my user-defined handler but i didn’t manage to link the “StopParser()” method inherited from TXMLParser. I also failed raising an exception and catching because it seems to be first caught by the TSAXParser.

Have I forgotten something simple? May somebody help?

Thank you in advance,

In your SAXHandler, can you not just call parser->StopParser(), where parser is a pointer to the TSAXParser, when you’ve parsed what you want to parse?

Cheers, Fons.

I just tried this. I pass the saxParser object to my saxHandler constructor and store it as a field.

The Problem is that I cannot call stopParser() which is a protected method. I could delcare my class saxHandler as a children of TSAXParser to have access to this method but it’s quite ugly and it’s not conceptually correct.

Ok, I can make StopParser() public. Could you try that yourself, just put it in public in the header and recompile. If that works as expected I’ll make the change in the ROOT source.

Cheers, Fons.

The compilation was OK but when I run my program I have a segfault. Here is gdb output :

Apparently everything is ok until I launch the parsing itself. Afterwards a buffer seemed to be created and memory is moved/allocated which seems to disturb the pointer to the saxParser I have in my SaxHandler class.
I commented the StopParser line, the problem was still there.
I tried to pass a reference to the saxParser pointer, same problem.

Bt this has nothing to do with the StopParser() function. Did you manage to run the SAXParser on your document before making any changes.

Cheers, Fons.

Forget my previous post. After several “make clean” it worked well.

I only moved the stopParser method from private to public in the header include/TXMLParser.h .

Thank you for your help.

EDIT : It worked well but needed more cleaning than I thought, now everything’s fine.

Ok, I’ve make StopParser() public in the ROOT svn trunk.

Cheers, Fons.