I’m trying to merge several files with libxml2 SAX. Original files look like this:
<xml>
<section1>
<data />
<data />
</section1>
<section2>
<data />
<data />
</section2>
<section3>
<data />
<data />
</section3>
</xml>
What I want to do is to make data from same sections in different files to be placed in one big file in appropriate section. What I’ve done is reading first file section1 and writing right away into merged file section1. Then I do same with other files I do. After that I move to section2.
It works fine except I have to read all files as many times as I have sections. What I was wondering is whether I could pause reading of file1 after going through section1 and continue it once section1 was read in all other files.
I don’t think this would be possible. You could start a secondary parsing at an arbitrary time in the original file’s callback, but I don’t think you can stop the secondary parsing (to go back to the original parsing) without fully finishing or aborting the 2nd one.
I’d strongly recommend looking into the
xmlReaderinterface. It’s not driven by callbacks, you callxmlTextReaderReadrepeatedly to advance it, and at any time you can swap between readers. You will definitely be able to get the behavior you’re looking for.Examples are available at
http://xmlsoft.org/examples/index.html#xmlReader