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

📄 xmlschemas.c

📁 xml开源解析代码.版本为libxml2-2.6.29,可支持GB3212.网络消息发送XML时很有用.
💻 C
📖 第 1 页 / 共 5 页
字号:
 * @type: the type holding the enumeration facets * * Builds a string consisting of all enumeration elements. * * Returns a string of all enumeration elements. */static const xmlChar *xmlSchemaFormatFacetEnumSet(xmlSchemaAbstractCtxtPtr actxt,			    xmlChar **buf, xmlSchemaTypePtr type){    xmlSchemaFacetPtr facet;    xmlSchemaWhitespaceValueType ws;    xmlChar *value = NULL;    int res, found = 0;    if (*buf != NULL)	xmlFree(*buf);        *buf = NULL;    do {	/*	* Use the whitespace type of the base type.	*/		ws = xmlSchemaGetWhiteSpaceFacetValue(type->baseType);	for (facet = type->facets; facet != NULL; facet = facet->next) {	    if (facet->type != XML_SCHEMA_FACET_ENUMERATION)		continue;	    found = 1;	    res = xmlSchemaGetCanonValueWhtspExt(facet->val,		ws, &value);	    if (res == -1) {		xmlSchemaInternalErr(actxt,		    "xmlSchemaFormatFacetEnumSet",		    "compute the canonical lexical representation");		if (*buf != NULL)		    xmlFree(*buf);		*buf = NULL;		return (NULL);	    }	    if (*buf == NULL)		*buf = xmlStrdup(BAD_CAST "'");	    else		*buf = xmlStrcat(*buf, BAD_CAST ", '");	    *buf = xmlStrcat(*buf, BAD_CAST value);	    *buf = xmlStrcat(*buf, BAD_CAST "'");	    if (value != NULL) {		xmlFree((xmlChar *)value);		value = NULL;	    }	}	/*	* The enumeration facet of a type restricts the enumeration	* facet of the ancestor type; i.e., such restricted enumerations	* do not belong to the set of the given type. Thus we break	* on the first found enumeration.	*/	if (found)	    break;	type = type->baseType;    } while ((type != NULL) && (type->type != XML_SCHEMA_TYPE_BASIC));    return ((const xmlChar *) *buf);}/************************************************************************ *									* * 			Error functions				        * *									* ************************************************************************/#if 0static voidxmlSchemaErrMemory(const char *msg){    __xmlSimpleError(XML_FROM_SCHEMASP, XML_ERR_NO_MEMORY, NULL, NULL,                     msg);}#endifstatic voidxmlSchemaPSimpleErr(const char *msg){    __xmlSimpleError(XML_FROM_SCHEMASP, XML_ERR_NO_MEMORY, NULL, NULL,                     msg);}/** * 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++;	ctxt->err = error;        channel = ctxt->error;        data = ctxt->errCtxt;	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);}/** * xmlSchemaPErrExt: * @ctxt: the parsing context * @node: the context node * @error: the error code  * @strData1: extra data * @strData2: extra data * @strData3: extra data * @msg: the message * @str1:  extra parameter for the message display * @str2:  extra parameter for the message display * @str3:  extra parameter for the message display * @str4:  extra parameter for the message display * @str5:  extra parameter for the message display *  * Handle a parser error */static voidxmlSchemaPErrExt(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node, int error,		const xmlChar * strData1, const xmlChar * strData2, 		const xmlChar * strData3, const char *msg, const xmlChar * str1, 		const xmlChar * str2, const xmlChar * str3, const xmlChar * str4,		const xmlChar * str5){    xmlGenericErrorFunc channel = NULL;    xmlStructuredErrorFunc schannel = NULL;    void *data = NULL;    if (ctxt != NULL) {        ctxt->nberrors++;	ctxt->err = error;        channel = ctxt->error;        data = ctxt->errCtxt;	schannel = ctxt->serror;    }    __xmlRaiseError(schannel, channel, data, ctxt, node, XML_FROM_SCHEMASP,                    error, XML_ERR_ERROR, NULL, 0,                    (const char *) strData1, (const char *) strData2, 		    (const char *) strData3, 0, 0, msg, str1, str2, 		    str3, str4, str5);}/************************************************************************ *									* * 			Allround error functions			* *									* ************************************************************************//** * 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_SCHEMAV_INTERNAL;    }    __xmlSimpleError(XML_FROM_SCHEMASV, XML_ERR_NO_MEMORY, node, NULL,                     extra);}static voidxmlSchemaPSimpleInternalErr(xmlNodePtr node,			    const char *msg, const xmlChar *str){     __xmlSimpleError(XML_FROM_SCHEMASP, XML_SCHEMAP_INTERNAL, node,	 msg, (const char *) str);}#define WXS_ERROR_TYPE_ERROR 1#define WXS_ERROR_TYPE_WARNING 2/** * xmlSchemaErr3: * @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 voidxmlSchemaErr4Line(xmlSchemaAbstractCtxtPtr ctxt,		  xmlErrorLevel errorLevel,		  int error, xmlNodePtr node, int line, const char *msg,		  const xmlChar *str1, const xmlChar *str2,		  const xmlChar *str3, const xmlChar *str4){    xmlStructuredErrorFunc schannel = NULL;    xmlGenericErrorFunc channel = NULL;    void *data = NULL;            if (ctxt != NULL) {	if (ctxt->type == XML_SCHEMA_CTXT_VALIDATOR) {	    xmlSchemaValidCtxtPtr vctxt = (xmlSchemaValidCtxtPtr) ctxt;	    const char *file = NULL;	    if (errorLevel != XML_ERR_WARNING) {		vctxt->nberrors++;		vctxt->err = error;		channel = vctxt->error;			    } else {		channel = vctxt->warning;	    }	    schannel = vctxt->serror;	    data = vctxt->errCtxt;	    /*	    * Error node. If we specify a line number, then	    * do not channel any node to the error function.	    */	    if (line == 0) {		if ((node == NULL) &&		    (vctxt->depth >= 0) &&		    (vctxt->inode != NULL)) {		    node = vctxt->inode->node;		}		/*		* Get filename and line if no node-tree.		*/		if ((node == NULL) &&		    (vctxt->parserCtxt != NULL) &&		    (vctxt->parserCtxt->input != NULL)) {		    file = vctxt->parserCtxt->input->filename;		    line = vctxt->parserCtxt->input->line;		}	    } else {		/*		* Override the given node's (if any) position		* and channel only the given line number.		*/		node = NULL;		/*		* Get filename.		*/		if (vctxt->doc != NULL)		    file = (const char *) vctxt->doc->URL;		else if ((vctxt->parserCtxt != NULL) &&		    (vctxt->parserCtxt->input != NULL))		    file = vctxt->parserCtxt->input->filename;	    }	       	    __xmlRaiseError(schannel, channel, data, ctxt,		node, XML_FROM_SCHEMASV,		error, errorLevel, file, line,		(const char *) str1, (const char *) str2,		(const char *) str3, 0, 0, msg, str1, str2, str3, str4);	} else if (ctxt->type == XML_SCHEMA_CTXT_PARSER) {	    xmlSchemaParserCtxtPtr pctxt = (xmlSchemaParserCtxtPtr) ctxt;	    if (errorLevel != XML_ERR_WARNING) {		pctxt->nberrors++;		pctxt->err = error;		channel = pctxt->error;			    } else {		channel = pctxt->warning;	    }	    schannel = pctxt->serror;	    data = pctxt->errCtxt;	    __xmlRaiseError(schannel, channel, data, ctxt,		node, XML_FROM_SCHEMASP, error,		errorLevel, NULL, 0,		(const char *) str1, (const char *) str2,		(const char *) str3, 0, 0, msg, str1, str2, str3, str4);	} else {	    TODO	}    }}/** * xmlSchemaErr3: * @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 voidxmlSchemaErr3(xmlSchemaAbstractCtxtPtr actxt,  	      int error, xmlNodePtr node, const char *msg,	      const xmlChar *str1, const xmlChar *str2, const xmlChar *str3){    xmlSchemaErr4Line(actxt, XML_ERR_ERROR, error, node, 0,	msg, str1, str2, str3, NULL);}static voidxmlSchemaErr4(xmlSchemaAbstractCtxtPtr actxt,  	      int error, xmlNodePtr node, const char *msg,	      const xmlChar *str1, const xmlChar *str2,	      const xmlChar *str3, const xmlChar *str4){    xmlSchemaErr4Line(actxt, XML_ERR_ERROR, error, node, 0,	msg, str1, str2, str3, str4);}static voidxmlSchemaErr(xmlSchemaAbstractCtxtPtr actxt,	     int error, xmlNodePtr node, const char *msg,	     const xmlChar *str1, const xmlChar *str2){    xmlSchemaErr4(actxt, error, node, msg, str1, str2, NULL, NULL);}static xmlChar *xmlSchemaFormatNodeForError(xmlChar ** msg,			    xmlSchemaAbstractCtxtPtr actxt,			    xmlNodePtr node){    xmlChar *str = NULL;    *msg = NULL;    if ((node != NULL) &&	(node->type != XML_ELEMENT_NODE) &&	(node->type != XML_ATTRIBUTE_NODE))    {	/* 	* Don't try to format other nodes than element and	* attribute nodes.	* Play save and return an empty string.	*/	*msg = xmlStrdup(BAD_CAST "");	return(*msg);    }    if (node != NULL) {	/*	* Work on tree nodes.	*/	if (node->type == XML_ATTRIBUTE_NODE) {	    xmlNodePtr elem = node->parent;	    	    *msg = xmlStrdup(BAD_CAST "Element '");	    if (elem->ns != NULL)		*msg = xmlStrcat(*msg, xmlSchemaFormatQName(&str,		    elem->ns->href, elem->name));	    else		*msg = xmlStrcat(*msg, xmlSchemaFormatQName(&str,		    NULL, elem->name));	    FREE_AND_NULL(str);	    *msg = xmlStrcat(*msg, BAD_CAST "', ");	    *msg = xmlStrcat(*msg, BAD_CAST "attribute '");	    	} else {	    *msg = xmlStrdup(BAD_CAST "Element '");	}	if (node->ns != NULL)	    *msg = xmlStrcat(*msg, xmlSchemaFormatQName(&str,	    node->ns->href, node->name));	else	    *msg = xmlStrcat(*msg, xmlSchemaFormatQName(&str,	    NULL, node->name));	FREE_AND_NULL(str);	*msg = xmlStrcat(*msg, BAD_CAST "': ");    } else if (actxt->type == XML_SCHEMA_CTXT_VALIDATOR) {	xmlSchemaValidCtxtPtr vctxt = (xmlSchemaValidCtxtPtr) actxt;	/*	* Work on node infos.	*/		if (vctxt->inode->nodeType == XML_ATTRIBUTE_NODE) {	    xmlSchemaNodeInfoPtr ielem =		vctxt->elemInfos[vctxt->depth];	    *msg = xmlStrdup(BAD_CAST "Element '");	    *msg = xmlStrcat(*msg, xmlSchemaFormatQName(&str,		ielem->nsName, ielem->localName));	    FREE_AND_NULL(str);	    *msg = xmlStrcat(*msg, BAD_CAST "', ");	    *msg = xmlStrcat(*msg, BAD_CAST "attribute '");	    	} else {	    *msg = xmlStrdup(BAD_CAST "Element '");	}	*msg = xmlStrcat(*msg, xmlSchemaFormatQName(&str,	

⌨️ 快捷键说明

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