⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xmlschemas.c.svn-base

📁 这是一个用于解析xml文件的类库。使用这个类库
💻 SVN-BASE
📖 第 1 页 / 共 5 页
字号:
/* * schemas.c : implementation of the XML Schema handling and *             schema validity checking * * See Copyright for the status of this software. * * Daniel Veillard <veillard@redhat.com> *//* * TODO: *   - when types are redefined in includes, check that all *     types in the redef list are equal *     -> need a type equality operation. */#define IN_LIBXML#include "libxml.h"#ifdef LIBXML_SCHEMAS_ENABLED#include <string.h>#include <libxml/xmlmemory.h>#include <libxml/parser.h>#include <libxml/parserInternals.h>#include <libxml/hash.h>#include <libxml/uri.h>#include <libxml/xmlschemas.h>#include <libxml/schemasInternals.h>#include <libxml/xmlschemastypes.h>#include <libxml/xmlautomata.h>#include <libxml/xmlregexp.h>#include <libxml/dict.h>/* #define DEBUG 1 *//* #define DEBUG_CONTENT 1 *//* #define DEBUG_TYPE 1 *//* #define DEBUG_CONTENT_REGEXP 1 *//* #define DEBUG_AUTOMATA 1 */#define UNBOUNDED (1 << 30)#define TODO 								\    xmlGenericError(xmlGenericErrorContext,				\	    "Unimplemented block at %s:%d\n",				\            __FILE__, __LINE__);#define XML_SCHEMAS_DEFAULT_NAMESPACE (const xmlChar *)"the default namespace"/* * The XML Schemas namespaces */static const xmlChar *xmlSchemaNs = (const xmlChar *)    "http://www.w3.org/2001/XMLSchema";static const xmlChar *xmlSchemaInstanceNs = (const xmlChar *)    "http://www.w3.org/2001/XMLSchema-instance";#define IS_SCHEMA(node, type)						\   ((node != NULL) && (node->ns != NULL) &&				\    (xmlStrEqual(node->name, (const xmlChar *) type)) &&		\    (xmlStrEqual(node->ns->href, xmlSchemaNs)))#define XML_SCHEMAS_PARSE_ERROR		1#define SCHEMAS_PARSE_OPTIONS XML_PARSE_NOENTstruct _xmlSchemaParserCtxt {    void *userData;             /* user specific data block */    xmlSchemaValidityErrorFunc error;   /* the callback in case of errors */    xmlSchemaValidityWarningFunc warning;       /* the callback in case of warning */    xmlSchemaValidError err;    int nberrors;    xmlStructuredErrorFunc serror;    xmlSchemaPtr topschema;	/* The main schema */    xmlHashTablePtr namespaces;	/* Hash table of namespaces to schemas */    xmlSchemaPtr schema;        /* The schema in use */    const xmlChar *container;   /* the current element, group, ... */    int counter;    const xmlChar *URL;    xmlDocPtr doc;    int preserve;		/* Whether the doc should be freed  */    const char *buffer;    int size;    /*     * Used to build complex element content models     */    xmlAutomataPtr am;    xmlAutomataStatePtr start;    xmlAutomataStatePtr end;    xmlAutomataStatePtr state;    xmlDictPtr dict;		/* dictionnary for interned string names */    int        includes;	/* the inclusion level, 0 for root or imports */};#define XML_SCHEMAS_ATTR_UNKNOWN 1#define XML_SCHEMAS_ATTR_CHECKED 2typedef struct _xmlSchemaAttrState xmlSchemaAttrState;typedef xmlSchemaAttrState *xmlSchemaAttrStatePtr;struct _xmlSchemaAttrState {    xmlAttrPtr attr;    int state;};/** * xmlSchemaValidCtxt: * * A Schemas validation context */struct _xmlSchemaValidCtxt {    void *userData;             /* user specific data block */    xmlSchemaValidityErrorFunc error;   /* the callback in case of errors */    xmlSchemaValidityWarningFunc warning;       /* the callback in case of warning */    xmlStructuredErrorFunc serror;    xmlSchemaPtr schema;        /* The schema in use */    xmlDocPtr doc;    xmlParserInputBufferPtr input;    xmlCharEncoding enc;    xmlSAXHandlerPtr sax;    void *user_data;    xmlDocPtr myDoc;    int err;    int nberrors;    xmlNodePtr node;    xmlNodePtr cur;    xmlSchemaTypePtr type;    xmlRegExecCtxtPtr regexp;    xmlSchemaValPtr value;    int attrNr;    int attrBase;    int attrMax;    xmlSchemaAttrStatePtr attr;};/* * These are the entries in the schemas importSchemas hash table */typedef struct _xmlSchemaImport xmlSchemaImport;typedef xmlSchemaImport *xmlSchemaImportPtr;struct _xmlSchemaImport {    const xmlChar *schemaLocation;    xmlSchemaPtr schema;};/* * These are the entries associated to includes in a schemas */typedef struct _xmlSchemaInclude xmlSchemaInclude;typedef xmlSchemaInclude *xmlSchemaIncludePtr;struct _xmlSchemaInclude {    xmlSchemaIncludePtr next;    const xmlChar *schemaLocation;    xmlDocPtr doc;};/************************************************************************ * 									* * 			Some predeclarations				* * 									* ************************************************************************/static int xmlSchemaValidateSimpleValue(xmlSchemaValidCtxtPtr ctxt,                                        xmlSchemaTypePtr type,                                        const xmlChar * value);static int xmlSchemaParseInclude(xmlSchemaParserCtxtPtr ctxt,                                 xmlSchemaPtr schema,                                 xmlNodePtr node);static intxmlSchemaValidateSimpleValueInternal(xmlSchemaValidCtxtPtr ctxt,                             xmlSchemaTypePtr type,			     const xmlChar * value,			     int fireErrors);/************************************************************************ *									* * 			Datatype error handlers				* *									* ************************************************************************//** * xmlSchemaPErrMemory: * @node: a context node * @extra:  extra informations * * Handle an out of memory condition */static voidxmlSchemaPErrMemory(xmlSchemaParserCtxtPtr ctxt,                    const char *extra, xmlNodePtr node){    if (ctxt != NULL)        ctxt->nberrors++;    __xmlSimpleError(XML_FROM_SCHEMASP, XML_ERR_NO_MEMORY, node, NULL,                     extra);}/** * xmlSchemaPErr: * @ctxt: the parsing context * @node: the context node * @error: the error code * @msg: the error message * @str1: extra data * @str2: extra data *  * Handle a parser error */static voidxmlSchemaPErr(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node, int error,              const char *msg, const xmlChar * str1, const xmlChar * str2){    xmlGenericErrorFunc channel = NULL;    xmlStructuredErrorFunc schannel = NULL;    void *data = NULL;    if (ctxt != NULL) {        ctxt->nberrors++;        channel = ctxt->error;        data = ctxt->userData;	schannel = ctxt->serror;    }    __xmlRaiseError(schannel, channel, data, ctxt, node, XML_FROM_SCHEMASP,                    error, XML_ERR_ERROR, NULL, 0,                    (const char *) str1, (const char *) str2, NULL, 0, 0,                    msg, str1, str2);}/** * xmlSchemaPErr2: * @ctxt: the parsing context * @node: the context node * @node: the current child * @error: the error code * @msg: the error message * @str1: extra data * @str2: extra data *  * Handle a parser error */static voidxmlSchemaPErr2(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node,               xmlNodePtr child, int error,               const char *msg, const xmlChar * str1, const xmlChar * str2){    if (child != NULL)        xmlSchemaPErr(ctxt, child, error, msg, str1, str2);    else        xmlSchemaPErr(ctxt, node, error, msg, str1, str2);}/** * xmlSchemaVTypeErrMemory: * @node: a context node * @extra:  extra informations * * Handle an out of memory condition */static voidxmlSchemaVErrMemory(xmlSchemaValidCtxtPtr ctxt,                    const char *extra, xmlNodePtr node){    if (ctxt != NULL) {        ctxt->nberrors++;        ctxt->err = XML_SCHEMAS_ERR_INTERNAL;    }    __xmlSimpleError(XML_FROM_SCHEMASV, XML_ERR_NO_MEMORY, node, NULL,                     extra);}/** * xmlSchemaVErr3: * @ctxt: the validation context * @node: the context node * @error: the error code * @msg: the error message * @str1: extra data * @str2: extra data * @str3: extra data *  * Handle a validation error */static voidxmlSchemaVErr3(xmlSchemaValidCtxtPtr ctxt, xmlNodePtr node, int error,               const char *msg, const xmlChar *str1, const xmlChar *str2,	       const xmlChar *str3){    xmlStructuredErrorFunc schannel = NULL;    xmlGenericErrorFunc channel = NULL;    void *data = NULL;    if (ctxt != NULL) {        ctxt->nberrors++;	ctxt->err = error;        channel = ctxt->error;        schannel = ctxt->serror;        data = ctxt->userData;    }    /* reajust to global error numbers */    error += XML_SCHEMAV_NOROOT - XML_SCHEMAS_ERR_NOROOT;    __xmlRaiseError(schannel, channel, data, ctxt, node, XML_FROM_SCHEMASV,                    error, XML_ERR_ERROR, NULL, 0,                    (const char *) str1, (const char *) str2,		    (const char *) str3, 0, 0,                    msg, str1, str2, str3);}/** * xmlSchemaVErr: * @ctxt: the validation context * @node: the context node * @error: the error code * @msg: the error message * @str1: extra data * @str2: extra data *  * Handle a validation error */static voidxmlSchemaVErr(xmlSchemaValidCtxtPtr ctxt, xmlNodePtr node, int error,              const char *msg, const xmlChar * str1, const xmlChar * str2){    xmlStructuredErrorFunc schannel = NULL;    xmlGenericErrorFunc channel = NULL;    void *data = NULL;    if (ctxt != NULL) {        ctxt->nberrors++;	ctxt->err = error;        channel = ctxt->error;        data = ctxt->userData;        schannel = ctxt->serror;    }    /* reajust to global error numbers */    error += XML_SCHEMAV_NOROOT - XML_SCHEMAS_ERR_NOROOT;    __xmlRaiseError(schannel, channel, data, ctxt, node, XML_FROM_SCHEMASV,                    error, XML_ERR_ERROR, NULL, 0,                    (const char *) str1, (const char *) str2, NULL, 0, 0,                    msg, str1, str2);}/************************************************************************ * 									* * 			Allocation functions				* * 									* ************************************************************************//** * xmlSchemaNewSchema: * @ctxt:  a schema validation context * * Allocate a new Schema structure. * * Returns the newly allocated structure or NULL in case or error */static xmlSchemaPtrxmlSchemaNewSchema(xmlSchemaParserCtxtPtr ctxt){    xmlSchemaPtr ret;    ret = (xmlSchemaPtr) xmlMalloc(sizeof(xmlSchema));    if (ret == NULL) {        xmlSchemaPErrMemory(ctxt, "allocating schema", NULL);        return (NULL);    }    memset(ret, 0, sizeof(xmlSchema));    ret->dict = ctxt->dict;    xmlDictReference(ret->dict);    return (ret);}/** * xmlSchemaNewFacet: * * Allocate a new Facet structure. * * Returns the newly allocated structure or NULL in case or error */xmlSchemaFacetPtrxmlSchemaNewFacet(void){    xmlSchemaFacetPtr ret;    ret = (xmlSchemaFacetPtr) xmlMalloc(sizeof(xmlSchemaFacet));    if (ret == NULL) {        return (NULL);    }    memset(ret, 0, sizeof(xmlSchemaFacet));    return (ret);}/** * xmlSchemaNewAnnot: * @ctxt:  a schema validation context * @node:  a node * * Allocate a new annotation structure. * * Returns the newly allocated structure or NULL in case or error */static xmlSchemaAnnotPtrxmlSchemaNewAnnot(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node){    xmlSchemaAnnotPtr ret;    ret = (xmlSchemaAnnotPtr) xmlMalloc(sizeof(xmlSchemaAnnot));    if (ret == NULL) {        xmlSchemaPErrMemory(ctxt, "allocating annotation", node);        return (NULL);    }    memset(ret, 0, sizeof(xmlSchemaAnnot));    ret->content = node;    return (ret);}/** * xmlSchemaFreeAnnot: * @annot:  a schema type structure * * Deallocate a annotation structure */static voidxmlSchemaFreeAnnot(xmlSchemaAnnotPtr annot){    if (annot == NULL)        return;    xmlFree(annot);}/**

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -