📄 xmlschemas.c
字号:
if (actxt->type == XML_SCHEMA_CTXT_VALIDATOR)
xmlSchemaErr(actxt, XML_SCHEMAV_INTERNAL, NULL,
(const char *) msg, NULL, NULL);
else if (actxt->type == XML_SCHEMA_CTXT_PARSER)
xmlSchemaErr(actxt, XML_SCHEMAP_INTERNAL, NULL,
(const char *) msg, NULL, NULL);
FREE_AND_NULL(msg)
}
static void
xmlSchemaCustomErr(xmlSchemaAbstractCtxtPtr actxt,
xmlParserErrors error,
xmlNodePtr node,
xmlSchemaTypePtr type ATTRIBUTE_UNUSED,
const char *message,
const xmlChar *str1,
const xmlChar *str2)
{
xmlChar *msg = NULL;
xmlSchemaFormatNodeForError(&msg, actxt, node);
msg = xmlStrcat(msg, (const xmlChar *) message);
msg = xmlStrcat(msg, BAD_CAST ".\n");
xmlSchemaErr(actxt, error, node,
(const char *) msg, str1, str2);
FREE_AND_NULL(msg)
}
static int
xmlSchemaEvalErrorNodeType(xmlSchemaAbstractCtxtPtr actxt,
xmlNodePtr node)
{
if (node != NULL)
return (node->type);
if ((actxt->type == XML_SCHEMA_CTXT_VALIDATOR) &&
(((xmlSchemaValidCtxtPtr) actxt)->inode != NULL))
return ( ((xmlSchemaValidCtxtPtr) actxt)->inode->nodeType);
return (-1);
}
static int
xmlSchemaIsGlobalItem(xmlSchemaTypePtr item)
{
switch (item->type) {
case XML_SCHEMA_TYPE_COMPLEX:
case XML_SCHEMA_TYPE_SIMPLE:
if (item->flags & XML_SCHEMAS_TYPE_GLOBAL)
return(1);
break;
case XML_SCHEMA_TYPE_GROUP:
return (1);
case XML_SCHEMA_TYPE_ELEMENT:
if ( ((xmlSchemaElementPtr) item)->flags &
XML_SCHEMAS_ELEM_GLOBAL)
return(1);
break;
case XML_SCHEMA_TYPE_ATTRIBUTE:
if ( ((xmlSchemaAttributePtr) item)->flags &
XML_SCHEMAS_ATTR_GLOBAL)
return(1);
break;
/* Note that attribute groups are always global. */
default:
return(1);
}
return (0);
}
static void
xmlSchemaSimpleTypeErr(xmlSchemaAbstractCtxtPtr actxt,
xmlParserErrors error,
xmlNodePtr node,
const xmlChar *value,
xmlSchemaTypePtr type,
int displayValue)
{
xmlChar *msg = NULL;
xmlSchemaFormatNodeForError(&msg, actxt, node);
if (displayValue || (xmlSchemaEvalErrorNodeType(actxt, node) ==
XML_ATTRIBUTE_NODE))
msg = xmlStrcat(msg, BAD_CAST "'%s' is not a valid value of ");
else
msg = xmlStrcat(msg, BAD_CAST "The character content is not a valid "
"value of ");
if (! xmlSchemaIsGlobalItem(type))
msg = xmlStrcat(msg, BAD_CAST "the local ");
else
msg = xmlStrcat(msg, BAD_CAST "the ");
if (VARIETY_ATOMIC(type))
msg = xmlStrcat(msg, BAD_CAST "atomic type");
else if (VARIETY_LIST(type))
msg = xmlStrcat(msg, BAD_CAST "list type");
else if (VARIETY_UNION(type))
msg = xmlStrcat(msg, BAD_CAST "union type");
if (xmlSchemaIsGlobalItem(type)) {
xmlChar *str = NULL;
msg = xmlStrcat(msg, BAD_CAST " '");
if (type->builtInType != 0) {
msg = xmlStrcat(msg, BAD_CAST "xs:");
msg = xmlStrcat(msg, type->name);
} else
msg = xmlStrcat(msg,
xmlSchemaFormatQName(&str,
type->targetNamespace, type->name));
msg = xmlStrcat(msg, BAD_CAST "'");
FREE_AND_NULL(str);
}
msg = xmlStrcat(msg, BAD_CAST ".\n");
if (displayValue || (xmlSchemaEvalErrorNodeType(actxt, node) ==
XML_ATTRIBUTE_NODE))
xmlSchemaErr(actxt, error, node, (const char *) msg, value, NULL);
else
xmlSchemaErr(actxt, error, node, (const char *) msg, NULL, NULL);
FREE_AND_NULL(msg)
}
static const xmlChar *
xmlSchemaFormatErrorNodeQName(xmlChar ** str,
xmlSchemaNodeInfoPtr ni,
xmlNodePtr node)
{
if (node != NULL) {
if (node->ns != NULL)
return (xmlSchemaFormatQName(str, node->ns->href, node->name));
else
return (xmlSchemaFormatQName(str, NULL, node->name));
} else if (ni != NULL)
return (xmlSchemaFormatQName(str, ni->nsName, ni->localName));
return (NULL);
}
static void
xmlSchemaIllegalAttrErr(xmlSchemaAbstractCtxtPtr actxt,
xmlParserErrors error,
xmlSchemaAttrInfoPtr ni,
xmlNodePtr node)
{
xmlChar *msg = NULL, *str = NULL;
xmlSchemaFormatNodeForError(&msg, actxt, node);
msg = xmlStrcat(msg, BAD_CAST "The attribute '%s' is not allowed.\n");
xmlSchemaErr(actxt, error, node, (const char *) msg,
xmlSchemaFormatErrorNodeQName(&str, (xmlSchemaNodeInfoPtr) ni, node),
NULL);
FREE_AND_NULL(str)
FREE_AND_NULL(msg)
}
static void
xmlSchemaComplexTypeErr(xmlSchemaAbstractCtxtPtr actxt,
xmlParserErrors error,
xmlNodePtr node,
xmlSchemaTypePtr type ATTRIBUTE_UNUSED,
const char *message,
int nbval,
int nbneg,
xmlChar **values)
{
xmlChar *str = NULL, *msg = NULL;
xmlChar *localName, *nsName;
const xmlChar *cur, *end;
int i;
xmlSchemaFormatNodeForError(&msg, actxt, node);
msg = xmlStrcat(msg, (const xmlChar *) message);
msg = xmlStrcat(msg, BAD_CAST ".");
/*
* Note that is does not make sense to report that we have a
* wildcard here, since the wildcard might be unfolded into
* multiple transitions.
*/
if (nbval + nbneg > 0) {
if (nbval + nbneg > 1) {
str = xmlStrdup(BAD_CAST " Expected is one of ( ");
} else
str = xmlStrdup(BAD_CAST " Expected is ( ");
nsName = NULL;
for (i = 0; i < nbval + nbneg; i++) {
cur = values[i];
/*
* Get the local name.
*/
localName = NULL;
end = cur;
if (*end == '*') {
localName = xmlStrdup(BAD_CAST "*");
end++;
} else {
while ((*end != 0) && (*end != '|'))
end++;
localName = xmlStrncat(localName, BAD_CAST cur, end - cur);
}
if (*end != 0) {
end++;
/*
* Skip "*|*" if they come with negated expressions, since
* they represent the same negated wildcard.
*/
if ((nbneg == 0) || (*end != '*') || (*localName != '*')) {
/*
* Get the namespace name.
*/
cur = end;
if (*end == '*') {
nsName = xmlStrdup(BAD_CAST "{*}");
} else {
while (*end != 0)
end++;
if (i >= nbval)
nsName = xmlStrdup(BAD_CAST "{##other:");
else
nsName = xmlStrdup(BAD_CAST "{");
nsName = xmlStrncat(nsName, BAD_CAST cur, end - cur);
nsName = xmlStrcat(nsName, BAD_CAST "}");
}
str = xmlStrcat(str, BAD_CAST nsName);
FREE_AND_NULL(nsName)
} else {
FREE_AND_NULL(localName);
continue;
}
}
str = xmlStrcat(str, BAD_CAST localName);
FREE_AND_NULL(localName);
if (i < nbval + nbneg -1)
str = xmlStrcat(str, BAD_CAST ", ");
}
str = xmlStrcat(str, BAD_CAST " ).\n");
msg = xmlStrcat(msg, BAD_CAST str);
FREE_AND_NULL(str)
} else
msg = xmlStrcat(msg, BAD_CAST "\n");
xmlSchemaErr(actxt, error, node, (const char *) msg, NULL, NULL);
xmlFree(msg);
}
static void
xmlSchemaFacetErr(xmlSchemaAbstractCtxtPtr actxt,
xmlParserErrors error,
xmlNodePtr node,
const xmlChar *value,
unsigned long length,
xmlSchemaTypePtr type,
xmlSchemaFacetPtr facet,
const char *message,
const xmlChar *str1,
const xmlChar *str2)
{
xmlChar *str = NULL, *msg = NULL;
xmlSchemaTypeType facetType;
int nodeType = xmlSchemaEvalErrorNodeType(actxt, node);
xmlSchemaFormatNodeForError(&msg, actxt, node);
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, BAD_CAST "[");
msg = xmlStrcat(msg, BAD_CAST "facet '");
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 (nodeType == 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 (nodeType == XML_ATTRIBUTE_NODE)
xmlSchemaErr3(actxt, error, node, (const char *) msg,
value, (const xmlChar *) actLen, (const xmlChar *) len);
else
xmlSchemaErr(actxt, error, node, (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");
xmlSchemaErr(actxt, error, node, (const char *) msg, value,
xmlSchemaFormatFacetEnumSet(actxt, &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");
xmlSchemaErr(actxt, error, node, (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");
xmlSchemaErr(actxt, error, node, (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");
xmlSchemaErr(actxt, error, node, (const char *) msg, value,
facet->value);
} else if (facetType == XML_SCHEMA_FACET_MINEXCLUSIVE) {
msg = xmlStrcat(msg, BAD_CAST "The value '%s' must be less than "
"'%s'.\n");
xmlSchemaErr(actxt, error, node, (const char *) msg, value,
facet->value);
} else if (facetType == XML_SCHEMA_FACET_MAXEXCLUSIVE) {
msg = xmlStrcat(msg, BAD_CAST "The value '%s' must be more than "
"'%s'.\n");
xmlSchemaErr(actxt, error, node, (const char *) msg, value,
facet->value);
} else if (facetType == XML_SCHEMA_FACET_TOTALDIGITS) {
msg = xmlStrcat(msg, BAD_CAST "The value '%s' has more "
"digits than are allowed ('%s').\n");
xmlSchemaErr(actxt, error, node, (const char*) msg, value,
facet->value);
} else if (facetType == XML_SCHEMA_FACET_FRACTIONDIGITS) {
msg = xmlStrcat(msg, BAD_CAST "The value '%s' has more fractional "
"digits than are allowed ('%s').\n");
xmlSchemaErr(actxt, error, node, (const char*) msg, value,
facet->value);
} else if (nodeType == XML_ATTRIBUTE_NODE) {
msg = xmlStrcat(msg, BAD_CAST "The value '%s' is not facet-valid.\n");
xmlSchemaErr(actxt, error, node, (const char *) msg, value, NULL);
} else {
msg = xmlStrcat(msg, BAD_CAST "The value is not facet-valid.\n");
xmlSchemaErr(actxt, error, node, (const char *) msg, NULL, NULL);
}
} else {
msg = xmlStrcat(msg, (const xmlChar *) message);
msg = xmlStrcat(msg, BAD_CAST ".\n");
xmlSchemaErr(actxt, error, node, (const char *) msg, str1, str2);
}
FREE_AND_NULL(str)
xmlFree(msg);
}
#define VERROR(err, type, msg) \
xmlSchemaCustomErr((xmlSchemaAbstractCtxtPtr) vctxt, err, NULL, type, msg, NULL, NULL);
#define VERROR_INT(func, msg) xmlSchemaInternalErr((xmlSchemaAbstractCtxtPtr) vctxt, func, msg);
#define PERROR_INT(func, msg) xmlSchemaInternalErr((xmlSchemaAbstractCtxtPtr) pctxt, func, msg);
#define AERROR_INT(func, msg) xmlSchemaInternalErr(actxt, func, msg);
/**
* xmlSchemaPMissingAttrErr:
* @ctxt: the schema validation context
* @ownerDes: the designation of the owner
* @ownerName: the name of the owner
* @ownerItem: the owner as a schema object
* @ownerElem: the owner as an element node
* @node: the parent element node of the missing attribute node
* @type: the corresponding type of the attribute node
*
* Reports an illegal attribute.
*/
static void
xmlSchemaPMissingAttrErr(xmlSchemaParserCtxtPtr ctxt,
xmlParserErrors error,
xmlSchemaTypePtr ownerItem,
xmlNodePtr ownerElem,
const char *name,
const char *message)
{
xmlChar *des = NULL;
xmlSchemaFormatItemForReport(&des, NULL, ownerItem, ownerElem);
if (message != NULL)
xmlSchemaPErr(ctxt, ownerElem, error, "%s: %s.\n", BAD_CAST des, BAD_CAST message);
else
xmlSchemaPErr(ctxt, ownerElem, error,
"%s: The attribute '%s' is required but missing.\n",
BAD_CAST des, BAD_CAST name);
FREE_AND_NULL(des);
}
/**
* xmlSchemaPResCompAttrErr:
* @ctxt: the schema validation context
* @error: the error code
* @ownerDes: the designation of the owner
* @ownerItem: the owner as a schema object
* @ownerElem: the owner as an element node
* @n
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -