Re: [xml] userdata for SAX parsing with schema validation
- From: Nick Wellnhofer <wellnhofer aevum de>
- To: Lara Blatchford <lara blatchford nteligen com>, "xml gnome org" <xml gnome org>
- Subject: Re: [xml] userdata for SAX parsing with schema validation
- Date: Mon, 3 Jan 2022 11:42:05 +0100
On 23/12/2021 20:14, Lara Blatchford wrote:
Hi - I have a simple SAX handler set up, and schema validation errors are
being caught by my structured error handler. So far so good.
It appears that the userdata argument to xmlSAXUserParseMemory /must/ be the
xmlSchemaSAXPlugPtr returned by the call to xmlSchemaSAXPlug, and that this
pointer is passed as the ctx pointer to the SAX handler callbacks.
This is correct.
Is there any way for me to make a userdata pointer of my choosing available to
my SAX handler callbacks while still getting schema validation?
From a quick look at the code, it seems that you can simply pass your user
data pointer to xmlSchemaSAXPlug.
// userdata arg is set to the pointer to the original SAX user data pointer
xmlSchemaValidCtxtPtr oldXsdValidCtxt = NULL;;
void *ctxptr = &oldXsdValidCtxt;
xmlSchemaSAXPlugPtr saxPlug = xmlSchemaSAXPlug(xsdValidCtxt,
&schemaValHandler, &ctxptr );
You should pass your user data pointer here instead of a NULL
xmlSchemaValidCtxtPtr:
void *user_data = my_user_data;
xmlSchemaSAXPlugPtr saxPlug = xmlSchemaSAXPlug(xsdValidCtxt,
&schemaValHandler, &user_data);
xmlSchemaSAXPlug will then swap the user data pointer with its own one which
you have to use when calling xmlSAXUserParseMemory. The SAX callbacks,
however, should receive the original pointer.
Nick
[Date Prev][
Date Next] [Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]