[xml] Ability to plug in schema validation on top libxml2 SAX parser



Hi,

I tried using xmlSchemaValidateStream() but i get error, the snippet of the
code i writing is:

xmlSAXHandler* saxHandler = new xmlSAXHandler();
saxHandler->initialized = XML_SAX2_MAGIC;
saxHandler->startElement = &ParseData::start_parse;
saxHandler->endElement = &ParseData::end_parse;
saxHandler->characters = &ParseData::value_parse;


ParseData pdata;
xmlParserInputBufferPtr buf = NULL;
buf = xmlParserInputBufferCreateMem(xmlstr.c_str(), int(xmlstr.length()),
                                                        XML_CHAR_ENCODING_NONE);
int ret = xmlSchemaValidateStream(ctxt, buf, XML_CHAR_ENCODING_NONE, saxHandler,
                                                    &pdata);
if (ret == 0)
   cout<<"validated "<<endl;
else if (ret > 0)
   cout<<"validation failed"<<endl;
else
   cout<<"Some internal error while validation"<<endl;


the return value from xmlSchemaValidateStream() is <0. Could you see why it would be so?

Thanks,
Sarmishtha

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