Hi,everyone
I am now making a progressive parsing application based on
xerces. The difference of my app from the common progressive parsing is
I feed the part subsequently by calling a method parser_buffer. I keep
the information needed by progressive parser in struct named parserNode,
Now I only put a SAX2XMLReader and XMLPScanToken varible in it. when
BinMemInputSource has eaten all bytes in memory(Readbyte():Available is 0),
throw out an self-defined exception and pause the parser temporarily until
next part comes in. When a new part comes in , I check in readBytes to update
the context varibles:fCapacity = strlen(srcBuffer); fCurIndex = 0;
I can successfully parse first part but when I input the second part
of xml, it reports error. Who can tell me how to perform such parsing,I need
maintain which kind of context information to support continue parsing
Following is my app skelecton:
============================start=================================
typedef struct parserNode{
SAX2XMLReader* parser; //SAX2XMLReader
XMLPScanToken pToken; //keep token info of parser
};
MyMemBufIS * memBufIS;//BinMemoryInputSource instance
struct parserNode parser1;
char srcBuf[200];
int parse_buffer(char *buf,int len);
main(){
XMLPlatformUtils::Initialize();
//Init parserNode
parser1.parser = XMLReaderFactory::createXMLReader();
for(i=1;i< M;i++){
memset(srcBuf,0,200);
srcBuf = ReadBufferFrom_File();
parse_buffer(srcBuf,strlen(srcBuf));
}
XMLPlatformUtils::Terminate();
}
int parse_buffer(char *srcBuf,int len)
{
int gotMore = 1;
if(/*first part of XML file*/)
{
try{
SpHandlers handler(encodingName, unRepFlags,
expandNamespaces);
parser.setContentHandler(&handler);
parser.setErrorHandler(&handler);
Buflen = strlen(srcBuf);
memBufIS = new MyMemBufIS
(
(const XMLByte*)srcBuf
, Buflen
, gMemBufId
, false
);
gotMore = parser1.parser->parseFirst(*memBufIS,paser1.pToken);
while(gotMore)
{
usleep(100);
gotMore = parser1.parser-> parseNext(paser1.pToken);
}
}
catch(struct MyException &e)
{
//This exception is throw out by myself in readBytes() when available
bytes is 0
//to stop parser popout when available buffer is over
//when this exception is trapped, the main will wait and get next part
of buffer,
//and feed it in by calling parse_buffer();
}
}
else(/*The subsequent 2,3,4,5 part of XML file handling*/)
{
try{
SpHandlers handler(encodingName, unRepFlags,
expandNamespaces);
parser.setContentHandler(&handler);
parser.setErrorHandler(&handler);
Buflen = strlen(srcBuf);
memBufIS = new MyMemBufIS
(
(const XMLByte*)srcBuf
, Buflen
, gMemBufId
, false
);
gotMore = parser1.parser->parseFirst(*memBufIS,paser1.pToken);
while(gotMore)
{
usleep(100);
gotMore = parser1.parser->parseNext(paser1.pToken);
}
}
catch(struct MyException &e)
{
//This exception is throw out by myself in readBytes() when available
bytes is 0
//to stop parser popout when available buffer is over when this
exception is trapped,
// the main will wait and get next part of buffer,and feed it in by calling
// parse_buffer();
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]