[xml] accessing Parser-Ctxt in SAX based schema validation
- From: Holger Kaelberer <hkaelber math uni-bielefeld de>
- To: xml gnome org
- Subject: [xml] accessing Parser-Ctxt in SAX based schema validation
- Date: Wed, 09 Apr 2008 09:49:30 +0200
Hi,
I've got problems using SAX based validation against a xml schema.
I followed the procedure shown in xmllint.c which works fine.
The user-data passed to the sax-handlers must contain the parser-context
(for accessing line-numbers). Without validation I did something like this:
/---
xmlParserCtxtPtr ctxt;
struct XMLparserState *state;
...
ctxt->sax = &parser_handler;
state->ctxt = ctxt;
ctxt->userData = state;
...
xmlParseDocument(ctxt);
---/
Is there an equiv. when using xmlSchemaValidateStream or any other way
to access the parser ctxt of the parsed file?:
/---
...
state->ctxt = ...;
...
ret = xmlSchemaValidateStream(vctxt, buf, XML_CHAR_ENCODING_NONE,
(xmlSAXHandlerPtr) parser_handler, state);
---/
Can someone help me with that?
One more thing concerning the SAX-Version: I was not able to do a
validation with a SAX1-handler.
According to xmlschemas.c xmlSchemaValidateStream presupposes a SAX2-handler:
/---
/**
* xmlSchemaValidateStream:
* @ctxt: a schema validation context
* @input: the input to use for reading the data
* @enc: an optional encoding information
* @sax: a SAX handler for the resulting events
* @user_data: the context to provide to the SAX handler.
*
* Validate an input based on a flow of SAX event from the parser
* and forward the events to the @sax handler with the provided @user_data
* the user provided @sax handler must be a SAX2 one.
*
* Returns 0 if the document is schemas valid, a positive error code
* number otherwise and -1 in case of internal or API error.
*/
int
xmlSchemaValidateStream(xmlSchemaValidCtxtPtr ctxt,
xmlParserInputBufferPtr input, xmlCharEncoding enc,
xmlSAXHandlerPtr sax, void *user_data)
---/
But xmllint.c seems to work with a SAX1-handler too:
/----
if (noout) {
handler = emptySAXHandler;
#ifdef LIBXML_SAX1_ENABLED
} else if (sax1) {
handler = debugSAXHandler;
#endif
} else {
handler = debugSAX2Handler;
}
...
---/
What's the state here?
Thanks in advance,
Holger
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]