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



Hi,

Thanks for you reply, but i have passed the xml and schema properly and
am able to get the validation and parsing done separately, only when i attempt
to use the xmlSchemaValidateStream() with the saxHandler it gives me this error.
After investigating i saw that if i comment 

saxHandler->startElement = &ParseData::start_parse;
saxHandler->endElement = &ParseData::end_parse;

the very same piece of code validates and parses properly.

Please do not think i haven't gone through your working code.
It has helped me a lot, but there these 2 callbacks have not be set there.

Anyways thanks a lot for taking time and effort to reply my
mail.

Thanks,
Sarmishtha


On Thu, Mar 3, 2011 at 6:07 PM, Daniel Veillard <veillard redhat com> wrote:
On Thu, Mar 03, 2011 at 02:05:54PM -0800, Sarmishtha Bhattacharya wrote:
> 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?

 Minimal engineer logic would obviously point out that for a schemas to
validate an XML you would need to pass both the schemas and the XML.
Nowhere in the code pasted there is information about a schemas to use. I
don't have a cristal ball, and I don't know how to program one either.
On the other hand you have complete working code reusable for this purpose
in the xmllint.c file part of the distriubution as I previously pointed
out.

Daniel

--
Daniel Veillard      | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
daniel veillard com  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/



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