📄 xmlschemas.c
字号:
if (ctxt != NULL) { ctxt->nberrors++; ctxt->err = error; channel = ctxt->error; schannel = ctxt->serror; data = ctxt->userData; } /* reajust to global error numbers */ /* Removed, since the old schema error codes have been * substituted for the global error codes. * * error += XML_SCHEMAV_NOROOT - XML_SCHEMAS_ERR_NOROOT; */ __xmlRaiseError(schannel, channel, data, ctxt, node, XML_FROM_SCHEMASP, error, XML_ERR_ERROR, NULL, 0, NULL, NULL, NULL, 0, 0, msg, str1, str2, str3, str4, str5);}/** * 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 */ /* Removed, since the old schema error codes have been * substituted for the global error codes. * * 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);}/** * xmlSchemaGetComponentNode: * @item: a schema component * * Returns node associated with the schema component. * NOTE that such a node need not be available; plus, a component's * node need not to reflect the component directly, since there is no * one-to-one relationship between the XML Schema representation and * the component representation. */static xmlNodePtrxmlSchemaGetComponentNode(xmlSchemaBasicItemPtr item){ switch (item->type) { case XML_SCHEMA_TYPE_ELEMENT: return (((xmlSchemaElementPtr) item)->node); case XML_SCHEMA_TYPE_ATTRIBUTE: return (((xmlSchemaAttributePtr) item)->node); case XML_SCHEMA_TYPE_COMPLEX: case XML_SCHEMA_TYPE_SIMPLE: return (((xmlSchemaTypePtr) item)->node); case XML_SCHEMA_TYPE_ANY: case XML_SCHEMA_TYPE_ANY_ATTRIBUTE: return (((xmlSchemaWildcardPtr) item)->node); case XML_SCHEMA_TYPE_PARTICLE: return (((xmlSchemaParticlePtr) item)->node); case XML_SCHEMA_TYPE_SEQUENCE: case XML_SCHEMA_TYPE_CHOICE: case XML_SCHEMA_TYPE_ALL: return (((xmlSchemaModelGroupPtr) item)->node); case XML_SCHEMA_TYPE_GROUP: return (((xmlSchemaModelGroupDefPtr) item)->node); case XML_SCHEMA_TYPE_ATTRIBUTEGROUP: return (((xmlSchemaAttributeGroupPtr) item)->node); case XML_SCHEMA_TYPE_IDC_UNIQUE: case XML_SCHEMA_TYPE_IDC_KEY: case XML_SCHEMA_TYPE_IDC_KEYREF: return (((xmlSchemaIDCPtr) item)->node); default: return (NULL); } }#if 0/** * xmlSchemaGetNextComponent: * @item: a schema component * * Returns the next sibling of the schema component. */static xmlSchemaBasicItemPtrxmlSchemaGetNextComponent(xmlSchemaBasicItemPtr item){ switch (item->type) { case XML_SCHEMA_TYPE_ELEMENT: return ((xmlSchemaBasicItemPtr) ((xmlSchemaElementPtr) item)->next); case XML_SCHEMA_TYPE_ATTRIBUTE: return ((xmlSchemaBasicItemPtr) ((xmlSchemaAttributePtr) item)->next); case XML_SCHEMA_TYPE_COMPLEX: case XML_SCHEMA_TYPE_SIMPLE: return ((xmlSchemaBasicItemPtr) ((xmlSchemaTypePtr) item)->next); case XML_SCHEMA_TYPE_ANY: case XML_SCHEMA_TYPE_ANY_ATTRIBUTE: return (NULL); case XML_SCHEMA_TYPE_PARTICLE: return ((xmlSchemaBasicItemPtr) ((xmlSchemaParticlePtr) item)->next); case XML_SCHEMA_TYPE_SEQUENCE: case XML_SCHEMA_TYPE_CHOICE: case XML_SCHEMA_TYPE_ALL: return (NULL); case XML_SCHEMA_TYPE_GROUP: return (NULL); case XML_SCHEMA_TYPE_ATTRIBUTEGROUP: return ((xmlSchemaBasicItemPtr) ((xmlSchemaAttributeGroupPtr) item)->next); case XML_SCHEMA_TYPE_IDC_UNIQUE: case XML_SCHEMA_TYPE_IDC_KEY: case XML_SCHEMA_TYPE_IDC_KEYREF: return ((xmlSchemaBasicItemPtr) ((xmlSchemaIDCPtr) item)->next); default: return (NULL); } }#endif/** * xmlSchemaGetAttrName: * @attr: the attribute declaration/use * * Returns the name of the attribute; if the attribute * is a reference, the name of the referenced global type will be returned. */static const xmlChar *xmlSchemaGetAttrName(xmlSchemaAttributePtr attr) { if (attr->ref != NULL) return(attr->ref); else return(attr->name); }/** * xmlSchemaGetAttrTargetNsURI: * @type: the type (element or attribute) * * Returns the target namespace URI of the type; if the type is a reference, * the target namespace of the referenced type will be returned. */static const xmlChar *xmlSchemaGetAttrTargetNsURI(xmlSchemaAttributePtr attr){ if (attr->ref != NULL) return (attr->refNs); else return(attr->targetNamespace); }/** * xmlSchemaFormatNsUriLocal: * @buf: the string buffer * @uri: the namespace URI * @local: the local name * * Returns a representation of the given URI used * for error reports. * * Returns an empty string, if @ns is NULL, a formatted * string otherwise. */ static const xmlChar* xmlSchemaFormatNsUriLocal(xmlChar **buf, const xmlChar *uri, const xmlChar *local){ if (*buf != NULL) xmlFree(*buf); if (uri == NULL) { *buf = xmlStrdup(BAD_CAST "{'"); *buf = xmlStrcat(*buf, local); } else { *buf = xmlStrdup(BAD_CAST "{'"); *buf = xmlStrcat(*buf, uri); *buf = xmlStrcat(*buf, BAD_CAST "', '"); *buf = xmlStrcat(*buf, local); } *buf = xmlStrcat(*buf, BAD_CAST "'}"); return ((const xmlChar *) *buf);}/** * xmlSchemaFormatNsPrefixLocal: * @buf: the string buffer * @ns: the namespace * @local: the local name * * Returns a representation of the given URI used * for error reports. * * Returns an empty string, if @ns is NULL, a formatted * string otherwise. */ static const xmlChar* xmlSchemaFormatNsPrefixLocal(xmlChar **buf, xmlNsPtr ns, const xmlChar *local){ if (*buf != NULL) { xmlFree(*buf); *buf = NULL; } if ((ns == NULL) || (ns->prefix == NULL)) return(local); else { *buf = xmlStrdup(ns->prefix); *buf = xmlStrcat(*buf, BAD_CAST ":"); *buf = xmlStrcat(*buf, local); } return ((const xmlChar *) *buf);}/** * xmlSchemaFormatQName: * @buf: the string buffer * @namespaceName: the namespace name * @localName: the local name * * Returns the given QName in the format "{namespaceName}localName" or * just "localName" if @namespaceName is NULL. * * Returns the localName if @namespaceName is NULL, a formatted * string otherwise. */ static const xmlChar* xmlSchemaFormatQName(xmlChar **buf, const xmlChar *namespaceName, const xmlChar *localName){ FREE_AND_NULL(*buf) if (namespaceName == NULL) return(localName); *buf = xmlStrdup(BAD_CAST "{"); *buf = xmlStrcat(*buf, namespaceName); *buf = xmlStrcat(*buf, BAD_CAST "}"); *buf = xmlStrcat(*buf, localName); return ((const xmlChar *) *buf);}static const xmlChar *xmlSchemaGetComponentName(xmlSchemaBasicItemPtr item){ switch (item->type) { case XML_SCHEMA_TYPE_ELEMENT: return (((xmlSchemaElementPtr) item)->name); case XML_SCHEMA_TYPE_ATTRIBUTE: return (((xmlSchemaAttributePtr) item)->name); case XML_SCHEMA_TYPE_ATTRIBUTEGROUP: return (((xmlSchemaAttributeGroupPtr) item)->name); case XML_SCHEMA_TYPE_SIMPLE: case XML_SCHEMA_TYPE_COMPLEX: return (((xmlSchemaTypePtr) item)->name); case XML_SCHEMA_TYPE_GROUP: return (((xmlSchemaModelGroupDefPtr) item)->name); case XML_SCHEMA_TYPE_IDC_KEY: case XML_SCHEMA_TYPE_IDC_UNIQUE: case XML_SCHEMA_TYPE_IDC_KEYREF: return (((xmlSchemaIDCPtr) item)->name); default: /* * Other components cannot have names. */ break; } return (NULL);}static const xmlChar *xmlSchemaGetComponentTargetNs(xmlSchemaBasicItemPtr item){ switch (item->type) { case XML_SCHEMA_TYPE_ELEMENT: return (((xmlSchemaElementPtr) item)->targetNamespace); case XML_SCHEMA_TYPE_ATTRIBUTE: return (((xmlSchemaAttributePtr) item)->targetNamespace); case XML_SCHEMA_TYPE_ATTRIBUTEGROUP: return (((xmlSchemaAttributeGroupPtr) item)->targetNamespace); case XML_SCHEMA_TYPE_SIMPLE: case XML_SCHEMA_TYPE_COMPLEX: return (((xmlSchemaTypePtr) item)->targetNamespace); case XML_SCHEMA_TYPE_GROUP: return (((xmlSchemaModelGroupDefPtr) item)->targetNamespace); case XML_SCHEMA_TYPE_IDC_KEY: case XML_SCHEMA_TYPE_IDC_UNIQUE: case XML_SCHEMA_TYPE_IDC_KEYREF: return (((xmlSchemaIDCPtr) item)->targetNamespace); default: /* * Other components cannot have names. */ break; } return (NULL);}static const xmlChar*xmlSchemaGetComponentQName(xmlChar **buf, void *item){ return (xmlSchemaFormatQName(buf, xmlSchemaGetComponentTargetNs((xmlSchemaBasicItemPtr) item), xmlSchemaGetComponentName((xmlSchemaBasicItemPtr) item)));}/** * xmlSchemaWildcardPCToString: * @pc: the type of processContents * * Returns a string representation of the type of * processContents. */static const xmlChar *xmlSchemaWildcardPCToString(int pc){ switch (pc) { case XML_SCHEMAS_ANY_SKIP: return (BAD_CAST "skip"); case XML_SCHEMAS_ANY_LAX: return (BAD_CAST "lax"); case XML_SCHEMAS_ANY_STRICT: return (BAD_CAST "strict"); default: return (BAD_CAST "invalid process contents"); }}/** * xmlSchemaFormatItemForReport: * @buf: the string buffer * @itemDes: the designation of the item * @itemName: the name of the item * @item: the item as an object * @itemNode: the node of the item * @local: the local name * @parsing: if the function is used during the parse * * Returns a representation of the given item used * for error reports. * * The following order is used to build the resulting * designation if the arguments are not NULL: * 1a. If itemDes not NULL -> itemDes * 1b. If (itemDes not NULL) and (itemName not NULL) * -> itemDes + itemName * 2. If the preceding was NULL and (item not NULL) -> item * 3. If the preceding was NULL and (itemNode not NULL) -> itemNode * * If the itemNode is an attribute node, the name of the attribute * will be appended to the result. * * Returns the formatted string and sets @buf to the resulting value. */ static xmlChar* xmlSchemaFormatItemForReport(xmlChar **buf, const xmlChar *itemDes, xmlSchemaTypePtr item, xmlNodePtr itemNode, int parsing){ xmlChar *str = NULL; int named = 1; if (*buf != NULL) { xmlFree(*buf); *buf = NULL; } if (itemDes != NULL) { *buf = xmlStrdup(itemDes); } else if (item != NULL) { switch (item->type) { case XML_SCHEMA_TYPE_BASIC: if (item->builtInType == XML_SCHEMAS_ANYTYPE) *buf = xmlStrdup(BAD_CAST "'anyType'"); else if (item->builtInType == XML_SCHEMAS_ANYSIMPLETYPE) *buf = xmlStrdup(BAD_CAST "'anySimpleType'"); else { /* *buf = xmlStrdup(BAD_CAST "bi "); */ /* *buf = xmlStrcat(*buf, xmlSchemaElemDesST); */ *buf = xmlStrdup(BAD_CAST "'"); *buf = xmlStrcat(*buf, item->name); *buf = xmlStrcat(*buf, BAD_CAST "'"); } break; case XML_SCHEMA_TYPE_SIMPLE: if (item->flags & XML_SCHEMAS_TYPE_GLOBAL) { *buf = xmlStrdup(xmlSchemaElemDesST); *buf = xmlStrcat(*buf, BAD_CAST " '"); *buf = xmlStrcat(*buf, item->name); *buf = xmlStrcat(*buf, BAD_CAST "'"); } else { *buf = xmlStrdup(xmlSchemaElemDesST); } break; case XML_SCHEMA_TYPE_COMPLEX: if (item->flags & XML_SCHEMAS_TYPE_GLOBAL) { *buf = xmlStrdup(xmlSchemaElemDesCT); *buf = xmlStrcat(*buf, BAD_CAST " '"); *buf = xmlStrcat(*buf, item->name); *buf = xmlStrcat(*buf, BAD_CAST "'"); } else { *buf = xmlStrdup(xmlSchemaElemDesCT); } break; case XML_SCHEMA_TYPE_ATTRIBUTE: { xmlSchemaAttributePtr attr; attr = (xmlSchemaAttributePtr) item; if ((attr->flags & XML_SCHEMAS_ATTR_GLOBAL) || (attr->ref == NULL)) { *buf = xmlStrdup(xmlSchemaElemDesAttrDecl); *buf = xmlStrcat(*buf, BAD_CAST " '"); *buf = xmlStrcat(*buf, attr->name); *buf = xmlStrcat(*buf, BAD_CAST "'"); } else { *buf = xmlStrdup(xmlSchemaElemDesAttrRef); *buf = xmlStrcat(*buf, BAD_CAST " '"); *buf = xmlStrcat(*buf, attr->refPrefix);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -