libxml2 Reference Manual |
---|
xmlschemas - incomplete XML Schemas structure implementation
interface to the XML Schemas handling and schema validity checking, it is incomplete right now.
Author(s): Daniel Veillard
typedef xmlSchema * xmlSchemaPtr; typedef struct _xmlSchemaParserCtxt xmlSchemaParserCtxt; typedef enum xmlSchemaValidOption; typedef xmlSchemaSAXPlugStruct * xmlSchemaSAXPlugPtr; typedef struct _xmlSchemaSAXPlug xmlSchemaSAXPlugStruct; typedef xmlSchemaValidCtxt * xmlSchemaValidCtxtPtr; typedef xmlSchemaParserCtxt * xmlSchemaParserCtxtPtr; typedef struct _xmlSchema xmlSchema; typedef enum xmlSchemaValidError; typedef struct _xmlSchemaValidCtxt xmlSchemaValidCtxt; xmlSchemaParserCtxtPtr xmlSchemaNewDocParserCtxt (xmlDocPtr doc); int xmlSchemaSAXUnplug (xmlSchemaSAXPlugPtr plug); xmlSchemaPtr xmlSchemaParse (xmlSchemaParserCtxtPtr ctxt); void xmlSchemaFreeParserCtxt (xmlSchemaParserCtxtPtr ctxt); xmlSchemaParserCtxtPtr xmlSchemaNewParserCtxt (const char * URL); int xmlSchemaIsValid (xmlSchemaValidCtxtPtr ctxt); typedef void xmlSchemaValidityErrorFunc (void * ctx,
const char * msg,
... ...); xmlSchemaSAXPlugPtr xmlSchemaSAXPlug (xmlSchemaValidCtxtPtr ctxt,
xmlSAXHandlerPtr * sax,
void ** user_data); int xmlSchemaValidateStream (xmlSchemaValidCtxtPtr ctxt,
xmlParserInputBufferPtr input,
xmlCharEncoding enc,
xmlSAXHandlerPtr sax,
void * user_data); int xmlSchemaGetParserErrors (xmlSchemaParserCtxtPtr ctxt,
xmlSchemaValidityErrorFunc * err,
xmlSchemaValidityWarningFunc * warn,
void ** ctx); int xmlSchemaValidateOneElement (xmlSchemaValidCtxtPtr ctxt,
xmlNodePtr elem); void xmlSchemaSetValidStructuredErrors (xmlSchemaValidCtxtPtr ctxt,
xmlStructuredErrorFunc serror,
void * ctx); void xmlSchemaSetValidErrors (xmlSchemaValidCtxtPtr ctxt,
xmlSchemaValidityErrorFunc err,
xmlSchemaValidityWarningFunc warn,
void * ctx); int xmlSchemaValidCtxtGetOptions (xmlSchemaValidCtxtPtr ctxt); int xmlSchemaValidateFile (xmlSchemaValidCtxtPtr ctxt,
const char * filename,
int options); int xmlSchemaValidateDoc (xmlSchemaValidCtxtPtr ctxt,
xmlDocPtr doc); void xmlSchemaFree (xmlSchemaPtr schema); xmlSchemaParserCtxtPtr xmlSchemaNewMemParserCtxt (const char * buffer,
int size); int xmlSchemaGetValidErrors (xmlSchemaValidCtxtPtr ctxt,
xmlSchemaValidityErrorFunc * err,
xmlSchemaValidityWarningFunc * warn,
void ** ctx); int xmlSchemaSetValidOptions (xmlSchemaValidCtxtPtr ctxt,
int options); void xmlSchemaSetParserErrors (xmlSchemaParserCtxtPtr ctxt,
xmlSchemaValidityErrorFunc err,
xmlSchemaValidityWarningFunc warn,
void * ctx); typedef void xmlSchemaValidityWarningFunc (void * ctx,
const char * msg,
... ...); void xmlSchemaDump (FILE * output,
xmlSchemaPtr schema); void xmlSchemaFreeValidCtxt (xmlSchemaValidCtxtPtr ctxt); xmlParserCtxtPtr xmlSchemaValidCtxtGetParserCtxt (xmlSchemaValidCtxtPtr ctxt); void xmlSchemaSetParserStructuredErrors (xmlSchemaParserCtxtPtr ctxt,
xmlStructuredErrorFunc serror,
void * ctx); xmlSchemaValidCtxtPtr xmlSchemaNewValidCtxt (xmlSchemaPtr schema);
struct _xmlSchema { const xmlChar * name : schema name const xmlChar * targetNamespace : the target namespace const xmlChar * version const xmlChar * id : Obsolete xmlDocPtr doc xmlSchemaAnnotPtr annot int flags xmlHashTablePtr typeDecl xmlHashTablePtr attrDecl xmlHashTablePtr attrgrpDecl xmlHashTablePtr elemDecl xmlHashTablePtr notaDecl xmlHashTablePtr schemasImports void * _private : unused by the library for users or bindings xmlHashTablePtr groupDecl xmlDictPtr dict void * includes : the includes, this is opaque for now int preserve : whether to free the document int counter : used to give ononymous components unique names xmlHashTablePtr idcDef : All identity-constraint defs. void * volatiles : Obsolete } xmlSchema;
struct _xmlSchemaParserCtxt { The content of this structure is not made public by the API. } xmlSchemaParserCtxt;
xmlSchemaParserCtxt * xmlSchemaParserCtxtPtr;
xmlSchemaSAXPlugStruct * xmlSchemaSAXPlugPtr;
struct _xmlSchemaSAXPlug { The content of this structure is not made public by the API. } xmlSchemaSAXPlugStruct;
struct _xmlSchemaValidCtxt { The content of this structure is not made public by the API. } xmlSchemaValidCtxt;
xmlSchemaValidCtxt * xmlSchemaValidCtxtPtr;
enum xmlSchemaValidError { XML_SCHEMAS_ERR_OK = 0 XML_SCHEMAS_ERR_NOROOT = 1 XML_SCHEMAS_ERR_UNDECLAREDELEM = 2 XML_SCHEMAS_ERR_NOTTOPLEVEL = 3 XML_SCHEMAS_ERR_MISSING = 4 XML_SCHEMAS_ERR_WRONGELEM = 5 XML_SCHEMAS_ERR_NOTYPE = 6 XML_SCHEMAS_ERR_NOROLLBACK = 7 XML_SCHEMAS_ERR_ISABSTRACT = 8 XML_SCHEMAS_ERR_NOTEMPTY = 9 XML_SCHEMAS_ERR_ELEMCONT = 10 XML_SCHEMAS_ERR_HAVEDEFAULT = 11 XML_SCHEMAS_ERR_NOTNILLABLE = 12 XML_SCHEMAS_ERR_EXTRACONTENT = 13 XML_SCHEMAS_ERR_INVALIDATTR = 14 XML_SCHEMAS_ERR_INVALIDELEM = 15 XML_SCHEMAS_ERR_NOTDETERMINIST = 16 XML_SCHEMAS_ERR_CONSTRUCT = 17 XML_SCHEMAS_ERR_INTERNAL = 18 XML_SCHEMAS_ERR_NOTSIMPLE = 19 XML_SCHEMAS_ERR_ATTRUNKNOWN = 20 XML_SCHEMAS_ERR_ATTRINVALID = 21 XML_SCHEMAS_ERR_VALUE = 22 XML_SCHEMAS_ERR_FACET = 23 XML_SCHEMAS_ERR_ = 24 XML_SCHEMAS_ERR_XXX = 25 };
enum xmlSchemaValidOption { XML_SCHEMA_VAL_VC_I_CREATE = 1 /* Default/fixed: create an attribute node * or an element's text node on the instance. * */ };
void xmlSchemaValidityErrorFunc (void * ctx,
const char * msg,
... ...)
Signature of an error callback from an XSD validation
ctx: | the validation context |
msg: | the message |
...: | extra arguments |
void xmlSchemaValidityWarningFunc (void * ctx,
const char * msg,
... ...)
Signature of a warning callback from an XSD validation
ctx: | the validation context |
msg: | the message |
...: | extra arguments |
void xmlSchemaDump (FILE * output,
xmlSchemaPtr schema)
Dump a Schema structure.
output: | the file output |
schema: | a schema structure |
void xmlSchemaFree (xmlSchemaPtr schema)
Deallocate a Schema structure.
schema: | a schema structure |
void xmlSchemaFreeParserCtxt (xmlSchemaParserCtxtPtr ctxt)
Free the resources associated to the schema parser context
ctxt: | the schema parser context |
void xmlSchemaFreeValidCtxt (xmlSchemaValidCtxtPtr ctxt)
Free the resources associated to the schema validation context
ctxt: | the schema validation context |
int xmlSchemaGetParserErrors (xmlSchemaParserCtxtPtr ctxt,
xmlSchemaValidityErrorFunc * err,
xmlSchemaValidityWarningFunc * warn,
void ** ctx)
Get the callback information used to handle errors for a parser context
ctxt: | a XMl-Schema parser context |
err: | the error callback result |
warn: | the warning callback result |
ctx: | contextual data for the callbacks result |
Returns: | -1 in case of failure, 0 otherwise |
int xmlSchemaGetValidErrors (xmlSchemaValidCtxtPtr ctxt,
xmlSchemaValidityErrorFunc * err,
xmlSchemaValidityWarningFunc * warn,
void ** ctx)
Get the error and warning callback informations
ctxt: | a XML-Schema validation context |
err: | the error function result |
warn: | the warning function result |
ctx: | the functions context result |
Returns: | -1 in case of error and 0 otherwise |
int xmlSchemaIsValid (xmlSchemaValidCtxtPtr ctxt)
Check if any error was detected during validation.
ctxt: | the schema validation context |
Returns: | 1 if valid so far, 0 if errors were detected, and -1 in case of internal error. |
xmlSchemaParserCtxtPtr xmlSchemaNewDocParserCtxt (xmlDocPtr doc)
Create an XML Schemas parse context for that document. NB. The document may be modified during the parsing process.
doc: | a preparsed document tree |
Returns: | the parser context or NULL in case of error |
xmlSchemaParserCtxtPtr xmlSchemaNewMemParserCtxt (const char * buffer,
int size)
Create an XML Schemas parse context for that memory buffer expected to contain an XML Schemas file.
buffer: | a pointer to a char array containing the schemas |
size: | the size of the array |
Returns: | the parser context or NULL in case of error |
xmlSchemaParserCtxtPtr xmlSchemaNewParserCtxt (const char * URL)
Create an XML Schemas parse context for that file/resource expected to contain an XML Schemas file.
URL: | the location of the schema |
Returns: | the parser context or NULL in case of error |
xmlSchemaValidCtxtPtr xmlSchemaNewValidCtxt (xmlSchemaPtr schema)
Create an XML Schemas validation context based on the given schema.
schema: | a precompiled XML Schemas |
Returns: | the validation context or NULL in case of error |
xmlSchemaPtr xmlSchemaParse (xmlSchemaParserCtxtPtr ctxt)
parse a schema definition resource and build an internal XML Shema struture which can be used to validate instances.
ctxt: | a schema validation context |
Returns: | the internal XML Schema structure built from the resource or NULL in case of error |
xmlSchemaSAXPlugPtr xmlSchemaSAXPlug (xmlSchemaValidCtxtPtr ctxt,
xmlSAXHandlerPtr * sax,
void ** user_data)
Plug a SAX based validation layer in a SAX parsing event flow. The original @saxptr and @dataptr data are replaced by new pointers but the calls to the original will be maintained.
ctxt: | a schema validation context |
sax: | a pointer to the original xmlSAXHandlerPtr |
user_data: | a pointer to the original SAX user data pointer |
Returns: | a pointer to a data structure needed to unplug the validation layer or NULL in case of errors. |
int xmlSchemaSAXUnplug (xmlSchemaSAXPlugPtr plug)
Unplug a SAX based validation layer in a SAX parsing event flow. The original pointers used in the call are restored.
plug: | a data structure returned by xmlSchemaSAXPlug |
Returns: | 0 in case of success and -1 in case of failure. |
void xmlSchemaSetParserErrors (xmlSchemaParserCtxtPtr ctxt,
xmlSchemaValidityErrorFunc err,
xmlSchemaValidityWarningFunc warn,
void * ctx)
Set the callback functions used to handle errors for a validation context
ctxt: | a schema validation context |
err: | the error callback |
warn: | the warning callback |
ctx: | contextual data for the callbacks |
void xmlSchemaSetParserStructuredErrors (xmlSchemaParserCtxtPtr ctxt,
xmlStructuredErrorFunc serror,
void * ctx)
Set the structured error callback
ctxt: | a schema parser context |
serror: | the structured error function |
ctx: | the functions context |
void xmlSchemaSetValidErrors (xmlSchemaValidCtxtPtr ctxt,
xmlSchemaValidityErrorFunc err,
xmlSchemaValidityWarningFunc warn,
void * ctx)
Set the error and warning callback informations
ctxt: | a schema validation context |
err: | the error function |
warn: | the warning function |
ctx: | the functions context |
int xmlSchemaSetValidOptions (xmlSchemaValidCtxtPtr ctxt,
int options)
Sets the options to be used during the validation.
ctxt: | a schema validation context |
options: | a combination of xmlSchemaValidOption |
Returns: | 0 in case of success, -1 in case of an API error. |
void xmlSchemaSetValidStructuredErrors (xmlSchemaValidCtxtPtr ctxt,
xmlStructuredErrorFunc serror,
void * ctx)
Set the structured error callback
ctxt: | a schema validation context |
serror: | the structured error function |
ctx: | the functions context |
int xmlSchemaValidCtxtGetOptions (xmlSchemaValidCtxtPtr ctxt)
Get the validation context options.
ctxt: | a schema validation context |
Returns: | the option combination or -1 on error. |
xmlParserCtxtPtr xmlSchemaValidCtxtGetParserCtxt (xmlSchemaValidCtxtPtr ctxt)
allow access to the parser context of the schema validation context
ctxt: | a schema validation context |
Returns: | the parser context of the schema validation context or NULL in case of error. |
int xmlSchemaValidateDoc (xmlSchemaValidCtxtPtr ctxt,
xmlDocPtr doc)
Validate a document tree in memory.
ctxt: | a schema validation context |
doc: | a parsed document tree |
Returns: | 0 if the document is schemas valid, a positive error code number otherwise and -1 in case of internal or API error. |
int xmlSchemaValidateFile (xmlSchemaValidCtxtPtr ctxt,
const char * filename,
int options)
Do a schemas validation of the given resource, it will use the SAX streamable validation internally.
ctxt: | a schema validation context |
filename: | the URI of the instance |
options: | a future set of options, currently unused |
Returns: | 0 if the document is valid, a positive error code number otherwise and -1 in case of an internal or API error. |
int xmlSchemaValidateOneElement (xmlSchemaValidCtxtPtr ctxt,
xmlNodePtr elem)
Validate a branch of a tree, starting with the given @elem.
ctxt: | a schema validation context |
elem: | an element node |
Returns: | 0 if the element and its subtree is valid, a positive error code number otherwise and -1 in case of an internal or API error. |
int xmlSchemaValidateStream (xmlSchemaValidCtxtPtr ctxt,
xmlParserInputBufferPtr input,
xmlCharEncoding enc,
xmlSAXHandlerPtr sax,
void * user_data)
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.
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. |
Returns: | 0 if the document is schemas valid, a positive error code number otherwise and -1 in case of internal or API error. |