📄 xmlschemas.c
字号:
*buf = xmlStrcat(*buf, BAD_CAST ":"); *buf = xmlStrcat(*buf, attr->ref); *buf = xmlStrcat(*buf, BAD_CAST "'"); } } break; case XML_SCHEMA_TYPE_ELEMENT: { xmlSchemaElementPtr elem; elem = (xmlSchemaElementPtr) item; if ((elem->flags & XML_SCHEMAS_ELEM_GLOBAL) || (elem->ref == NULL)) { *buf = xmlStrdup(xmlSchemaElemDesElemDecl); *buf = xmlStrcat(*buf, BAD_CAST " '"); *buf = xmlStrcat(*buf, elem->name); *buf = xmlStrcat(*buf, BAD_CAST "'"); } else { *buf = xmlStrdup(xmlSchemaElemDesElemRef); *buf = xmlStrcat(*buf, BAD_CAST " '"); *buf = xmlStrcat(*buf, elem->refPrefix); *buf = xmlStrcat(*buf, BAD_CAST ":"); *buf = xmlStrcat(*buf, elem->ref); *buf = xmlStrcat(*buf, BAD_CAST "'"); } } break; case XML_SCHEMA_TYPE_IDC_UNIQUE: case XML_SCHEMA_TYPE_IDC_KEY: case XML_SCHEMA_TYPE_IDC_KEYREF: if (item->type == XML_SCHEMA_TYPE_IDC_UNIQUE) *buf = xmlStrdup(BAD_CAST "unique '"); else if (item->type == XML_SCHEMA_TYPE_IDC_KEY) *buf = xmlStrdup(BAD_CAST "key '"); else *buf = xmlStrdup(BAD_CAST "keyRef '"); *buf = xmlStrcat(*buf, ((xmlSchemaIDCPtr) item)->name); *buf = xmlStrcat(*buf, BAD_CAST "'"); break; case XML_SCHEMA_TYPE_ANY: case XML_SCHEMA_TYPE_ANY_ATTRIBUTE: *buf = xmlStrdup(xmlSchemaWildcardPCToString( ((xmlSchemaWildcardPtr) item)->processContents)); *buf = xmlStrcat(*buf, BAD_CAST " wildcard"); break; case XML_SCHEMA_FACET_MININCLUSIVE: case XML_SCHEMA_FACET_MINEXCLUSIVE: case XML_SCHEMA_FACET_MAXINCLUSIVE: case XML_SCHEMA_FACET_MAXEXCLUSIVE: case XML_SCHEMA_FACET_TOTALDIGITS: case XML_SCHEMA_FACET_FRACTIONDIGITS: case XML_SCHEMA_FACET_PATTERN: case XML_SCHEMA_FACET_ENUMERATION: case XML_SCHEMA_FACET_WHITESPACE: case XML_SCHEMA_FACET_LENGTH: case XML_SCHEMA_FACET_MAXLENGTH: case XML_SCHEMA_FACET_MINLENGTH: *buf = xmlStrdup(BAD_CAST "facet '"); *buf = xmlStrcat(*buf, xmlSchemaFacetTypeToString(item->type)); *buf = xmlStrcat(*buf, BAD_CAST "'"); break; case XML_SCHEMA_TYPE_NOTATION: *buf = xmlStrdup(BAD_CAST "notation"); break; case XML_SCHEMA_TYPE_GROUP: { xmlChar *s = NULL; *buf = xmlStrdup(xmlSchemaElemModelGrDef); *buf = xmlStrcat(*buf, BAD_CAST " '"); *buf = xmlStrcat(*buf, xmlSchemaFormatQName(&s, ((xmlSchemaModelGroupDefPtr) item)->targetNamespace, ((xmlSchemaModelGroupDefPtr) item)->name)); *buf = xmlStrcat(*buf, BAD_CAST "'"); FREE_AND_NULL(s) } break; case XML_SCHEMA_TYPE_SEQUENCE: case XML_SCHEMA_TYPE_CHOICE: case XML_SCHEMA_TYPE_ALL: case XML_SCHEMA_TYPE_PARTICLE: *buf = xmlStrdup(xmlSchemaCompTypeToString(item->type)); break; default: named = 0; } } else named = 0; if ((named == 0) && (itemNode != NULL)) { xmlNodePtr elem; if (itemNode->type == XML_ATTRIBUTE_NODE) elem = itemNode->parent; else elem = itemNode; *buf = xmlStrdup(BAD_CAST "Element '"); if (parsing) *buf = xmlStrcat(*buf, elem->name); else *buf = xmlStrcat(*buf, xmlSchemaFormatNsPrefixLocal(&str, elem->ns, elem->name)); *buf = xmlStrcat(*buf, BAD_CAST "'"); } if ((itemNode != NULL) && (itemNode->type == XML_ATTRIBUTE_NODE)) { *buf = xmlStrcat(*buf, BAD_CAST ", attribute '"); *buf = xmlStrcat(*buf, xmlSchemaFormatNsPrefixLocal(&str, itemNode->ns, itemNode->name)); *buf = xmlStrcat(*buf, BAD_CAST "'"); } FREE_AND_NULL(str); return (*buf);}/** * xmlSchemaPFormatItemDes: * @buf: the string buffer * @item: the item as a schema object * @itemNode: the item as a node * * If the pointer to @buf is not NULL and @but holds no value, * the value is set to a item designation using * xmlSchemaFormatItemForReport. This one avoids adding * an attribute designation postfix. * * Returns a string of all enumeration elements. */static voidxmlSchemaPRequestItemDes(xmlChar **buf, xmlSchemaTypePtr item, xmlNodePtr itemNode){ if ((buf == 0) || (*buf != NULL)) return; if (itemNode->type == XML_ATTRIBUTE_NODE) itemNode = itemNode->parent; xmlSchemaFormatItemForReport(buf, NULL, item, itemNode, 1); }/** * xmlSchemaGetCanonValueWhtsp: * @val: the precomputed value * @retValue: the returned value * @ws: the whitespace type of the value * * Get a the cononical representation of the value. * The caller has to free the returned retValue. * * Returns 0 if the value could be built and -1 in case of * API errors or if the value type is not supported yet. */static intxmlSchemaGetCanonValueWhtsp(const xmlChar *value, xmlSchemaValPtr val, xmlSchemaWhitespaceValueType ws, const xmlChar **retValue){ xmlSchemaValType valType; if ((retValue == NULL) || (value == NULL) || (val == NULL)) return (-1); *retValue = NULL; valType = xmlSchemaGetValType(val); switch (valType) { case XML_SCHEMAS_STRING: if (value == NULL) *retValue = BAD_CAST xmlStrdup(BAD_CAST ""); else if (ws == XML_SCHEMA_WHITESPACE_COLLAPSE) *retValue = xmlSchemaCollapseString(value); else if (ws == XML_SCHEMA_WHITESPACE_REPLACE) *retValue = xmlSchemaWhiteSpaceReplace(value); if ((*retValue) == NULL) *retValue = BAD_CAST xmlStrdup(value); break; case XML_SCHEMAS_NORMSTRING: if (value == NULL) *retValue = BAD_CAST xmlStrdup(BAD_CAST ""); else { if (ws == XML_SCHEMA_WHITESPACE_COLLAPSE) *retValue = xmlSchemaCollapseString(value); else *retValue = xmlSchemaWhiteSpaceReplace(value); if ((*retValue) == NULL) *retValue = BAD_CAST xmlStrdup(value); } break; default: return (xmlSchemaGetCanonValue(val, retValue)); } return (0);}/** * xmlSchemaFormatFacetEnumSet: * @buf: the string buffer * @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(xmlChar **buf, xmlSchemaTypePtr type){ xmlSchemaFacetPtr facet; xmlSchemaWhitespaceValueType ws; const xmlChar *value = NULL; int res, found = 0; if (*buf != NULL) xmlFree(*buf); *buf = NULL; do { /* * Use the whitespace type of the base type. */ ws = (xmlSchemaWhitespaceValueType) xmlSchemaGetWhiteSpaceFacetValue(type->baseType); for (facet = type->facets; facet != NULL; facet = facet->next) { if (facet->type != XML_SCHEMA_FACET_ENUMERATION) continue; found = 1; res = xmlSchemaGetCanonValueWhtsp(facet->value, facet->val, ws, &value); if (res == -1) { xmlSchemaVErr(NULL, NULL, XML_SCHEMAV_INTERNAL, "Internal error: xmlSchemaFormatFacetEnumSet, failed to " "compute the canonical lexical representation.\n", NULL, NULL); if (*buf != NULL) xmlFree(*buf); *buf = NULL; return (NULL); } if (*buf == NULL) { *buf = xmlStrdup(BAD_CAST "'"); *buf = xmlStrcat(*buf, value); *buf = xmlStrcat(*buf, BAD_CAST "'"); } else { *buf = xmlStrcat(*buf, BAD_CAST ", '"); *buf = xmlStrcat(*buf, value); *buf = xmlStrcat(*buf, BAD_CAST "'"); } if (value != NULL) { xmlFree((xmlChar *)value); value = NULL; } } type = type->baseType; } while ((! found) && (type != NULL) && (type->type != XML_SCHEMA_TYPE_BASIC)); return ((const xmlChar *) *buf);}/** * xmlSchemaVFacetErr: * @ctxt: the schema validation context * @error: the error code * @node: the node to be validated * @value: the value of the node * @type: the type holding the facet * @facet: the facet * @message: the error message of NULL * @str1: extra data * @str2: extra data * @str3: extra data * * Reports a facet validation error. * TODO: Should this report the value of an element as well? */static voidxmlSchemaVFacetErr(xmlSchemaValidCtxtPtr ctxt, xmlParserErrors error, xmlNodePtr node, const xmlChar *value, unsigned long length, xmlSchemaTypePtr type, xmlSchemaFacetPtr facet, const char *message, const xmlChar *str1, const xmlChar *str2, const xmlChar *str3){ xmlChar *str = NULL, *msg = NULL; xmlSchemaTypeType facetType; xmlSchemaFormatItemForReport(&msg, NULL, NULL, node, 0); msg = xmlStrcat(msg, BAD_CAST " ["); msg = xmlStrcat(msg, xmlSchemaFormatItemForReport(&str, NULL, type, NULL, 0)); msg = xmlStrcat(msg, BAD_CAST ", facet '"); if (error == XML_SCHEMAV_CVC_ENUMERATION_VALID) { facetType = XML_SCHEMA_FACET_ENUMERATION; /* * If enumerations are validated, one must not expect the * facet to be given. */ } else facetType = facet->type; msg = xmlStrcat(msg, xmlSchemaFacetTypeToString(facetType)); msg = xmlStrcat(msg, BAD_CAST "']: "); if (message == NULL) { /* * Use a default message. */ if ((facetType == XML_SCHEMA_FACET_LENGTH) || (facetType == XML_SCHEMA_FACET_MINLENGTH) || (facetType == XML_SCHEMA_FACET_MAXLENGTH)) { char len[25], actLen[25]; /* FIXME, TODO: What is the max expected string length of the * this value? */ if (node->type == XML_ATTRIBUTE_NODE) msg = xmlStrcat(msg, BAD_CAST "The value '%s' has a length of '%s'; "); else msg = xmlStrcat(msg, BAD_CAST "The value has a length of '%s'; "); snprintf(len, 24, "%lu", xmlSchemaGetFacetValueAsULong(facet)); snprintf(actLen, 24, "%lu", length); if (facetType == XML_SCHEMA_FACET_LENGTH) msg = xmlStrcat(msg, BAD_CAST "this differs from the allowed length of '%s'.\n"); else if (facetType == XML_SCHEMA_FACET_MAXLENGTH) msg = xmlStrcat(msg, BAD_CAST "this exceeds the allowed maximum length of '%s'.\n"); else if (facetType == XML_SCHEMA_FACET_MINLENGTH) msg = xmlStrcat(msg, BAD_CAST "this underruns the allowed minimum length of '%s'.\n"); if (node->type == XML_ATTRIBUTE_NODE) xmlSchemaVErrExt(ctxt, node, error, (const char *) msg, value, (const xmlChar *) actLen, (const xmlChar *) len, NULL, NULL); else xmlSchemaVErr(ctxt, node, error, (const char *) msg, (const xmlChar *) actLen, (const xmlChar *) len); } else if (facetType == XML_SCHEMA_FACET_ENUMERATION) { msg = xmlStrcat(msg, BAD_CAST "The value '%s' is not an element " "of the set {%s}.\n"); xmlSchemaVErr(ctxt, node, error, (const char *) msg, value, xmlSchemaFormatFacetEnumSet(&str, type)); } else if (facetType == XML_SCHEMA_FACET_PATTERN) { msg = xmlStrcat(msg, BAD_CAST "The value '%s' is not accepted " "by the pattern '%s'.\n"); xmlSchemaVErr(ctxt, node, error, (const char *) msg, value, facet->value); } else if (facetType == XML_SCHEMA_FACET_MININCLUSIVE) { msg = xmlStrcat(msg, BAD_CAST "The value '%s' is less than the " "minimum value allowed ('%s').\n"); xmlSchemaVErr(ctxt, node, error, (const char *) msg, value, facet->value); } else if (facetType == XML_SCHEMA_FACET_MAXINCLUSIVE) { msg = xmlStrcat(msg, BAD_CAST "The value '%s' is greater than the " "maximum value allowed ('%s').\n"); xmlSchemaVErr(ctxt, node, error, (const char *) msg, value, facet->value);#if 0 } else if (facetType == XML_SCHEMA_FACET_MINEXCLUSIVE) { msg = xmlStrcat(msg, BAD_CAST "The value '%s' is less than the " "minimum exclusive value allowed ('%s').\n"); xmlSchemaVErr(ctxt, node, error, (const char *) msg, value, facet->value); } else if (facetType == XML_SCHEMA_FACET_MAXEXCLUSIVE) { msg = xmlStrcat(msg, BAD_CAST "The value '%s' is greater than the " "maximum exclusive value allowed ('%s').\n"); xmlSchemaVErr(ctxt, node, error, (const char *) msg, value, facet->value);#endif } else if (node->type == XML_ATTRIBUTE_NODE) { msg = xmlStrcat(msg, BAD_CAST "The value '%s' is not facet-valid.\n"); xmlSchemaVErr(ctxt, node, error, (const char *) msg, value, NULL); } else { msg = xmlStrcat(msg, BAD_CAST "The value is not facet-valid.\n"); xmlSchemaVErr(ctxt, node, error, (const char *) msg, NULL, NULL); } } else { msg = xmlStrcat(msg, (const xmlChar *) message); msg = xmlStrcat(msg, BAD_CAST ".\n"); xmlSchemaVErr3(ctxt, node, error, (const char *) msg, str1, str2, str3); } FREE_AND_NULL(str) xmlFree(msg);}/** * xmlSchemaVSimpleTypeErr: * @ctxt: the schema validation context * @error: the error code * @type: the type used for validation * @node: the node containing the validated value * @value: the validated value * * Reports a simple type validation error. * TODO: Should this report the value of an element as well? */static voidxmlSchemaVSimpleTypeErr(xmlSchemaValidCtxtPtr ctxt, xmlParserErrors error, xmlNodePtr node, const xmlChar *value, xmlSchemaTypePtr type){ xmlChar *str = NULL, *msg = NULL; xmlSchemaFormatItemForReport(&msg, NULL, NULL, node, 0); msg = xmlStrcat(msg, BAD_CAST " ["); msg = xmlStrcat(msg, xmlSchemaFormatItemForReport(&str, NULL, type, NULL, 0)); if (node->type == XML_ATTRIBUTE_NODE) { msg = xmlStrcat(msg, BAD_CAST "]: The value '%s' is not valid.\n"); xmlSchemaVErr(ctxt, node, error, (const char *) msg, value, NULL); } else { msg = xmlStrcat(msg, BAD_CAST "]: The character content is not valid.\n"); xmlSchemaVErr(ctxt, node, error, (const char *) msg, NULL, NULL); } FREE_AND_NULL(str) xmlFree(msg);}/** * xmlSchemaVComplexTypeErr: * @ctxt: the schema validation context * @error: the error code * @node: the node containing the validated value * @type: the complex type used for validation * @message: the error message * * Reports a complex type validation error. */static voidxmlSchemaVComplexTypeErr(xmlSchemaValidCtxtPtr ctxt, xmlParserErrors error, xmlNodePtr node, xmlSchemaTypePtr type, const char *message)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -