📄 xmlschemas.c.svn-base
字号:
xmlNodePtr child = NULL; const xmlChar *value; if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) return (NULL); facet = xmlSchemaNewFacet(); if (facet == NULL) { xmlSchemaPErrMemory(ctxt, "allocating facet", node); return (NULL); } facet->node = node; value = xmlSchemaGetProp(ctxt, node, "value"); if (value == NULL) { xmlSchemaPErr2(ctxt, node, child, XML_SCHEMAP_FACET_NO_VALUE, "Facet %s has no value\n", node->name, NULL); xmlSchemaFreeFacet(facet); return (NULL); } if (IS_SCHEMA(node, "minInclusive")) { facet->type = XML_SCHEMA_FACET_MININCLUSIVE; } else if (IS_SCHEMA(node, "minExclusive")) { facet->type = XML_SCHEMA_FACET_MINEXCLUSIVE; } else if (IS_SCHEMA(node, "maxInclusive")) { facet->type = XML_SCHEMA_FACET_MAXINCLUSIVE; } else if (IS_SCHEMA(node, "maxExclusive")) { facet->type = XML_SCHEMA_FACET_MAXEXCLUSIVE; } else if (IS_SCHEMA(node, "totalDigits")) { facet->type = XML_SCHEMA_FACET_TOTALDIGITS; } else if (IS_SCHEMA(node, "fractionDigits")) { facet->type = XML_SCHEMA_FACET_FRACTIONDIGITS; } else if (IS_SCHEMA(node, "pattern")) { facet->type = XML_SCHEMA_FACET_PATTERN; } else if (IS_SCHEMA(node, "enumeration")) { facet->type = XML_SCHEMA_FACET_ENUMERATION; } else if (IS_SCHEMA(node, "whiteSpace")) { facet->type = XML_SCHEMA_FACET_WHITESPACE; } else if (IS_SCHEMA(node, "length")) { facet->type = XML_SCHEMA_FACET_LENGTH; } else if (IS_SCHEMA(node, "maxLength")) { facet->type = XML_SCHEMA_FACET_MAXLENGTH; } else if (IS_SCHEMA(node, "minLength")) { facet->type = XML_SCHEMA_FACET_MINLENGTH; } else { xmlSchemaPErr2(ctxt, node, child, XML_SCHEMAP_UNKNOWN_FACET_TYPE, "Unknown facet type %s\n", node->name, NULL); xmlSchemaFreeFacet(facet); return (NULL); } facet->id = xmlSchemaGetProp(ctxt, node, "id"); facet->value = value; child = node->children; if (IS_SCHEMA(child, "annotation")) { facet->annot = xmlSchemaParseAnnotation(ctxt, schema, child); child = child->next; } if (child != NULL) { xmlSchemaPErr2(ctxt, node, child, XML_SCHEMAP_UNKNOWN_FACET_CHILD, "Facet %s has unexpected child content\n", node->name, NULL); } return (facet);}/** * xmlSchemaParseAny: * @ctxt: a schema validation context * @schema: the schema being built * @node: a subtree containing XML Schema informations * * parse a XML schema Any declaration * *WARNING* this interface is highly subject to change * * Returns the new type structure or NULL in case of error */static xmlSchemaTypePtrxmlSchemaParseAny(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, xmlNodePtr node){ xmlSchemaTypePtr type; xmlNodePtr child = NULL; xmlChar name[30]; if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) return (NULL); _snprintf((char *) name, 30, "any %d", ctxt->counter++ + 1); type = xmlSchemaAddType(ctxt, schema, name, NULL); if (type == NULL) return (NULL); type->node = node; type->type = XML_SCHEMA_TYPE_ANY; child = node->children; type->minOccurs = xmlGetMinOccurs(ctxt, node); type->maxOccurs = xmlGetMaxOccurs(ctxt, node); if (IS_SCHEMA(child, "annotation")) { type->annot = xmlSchemaParseAnnotation(ctxt, schema, child); child = child->next; } if (child != NULL) { xmlSchemaPErr2(ctxt, node, child, XML_SCHEMAP_UNKNOWN_SEQUENCE_CHILD, "Sequence %s has unexpected content\n", type->name, NULL); } return (type);}/** * xmlSchemaParseNotation: * @ctxt: a schema validation context * @schema: the schema being built * @node: a subtree containing XML Schema informations * * parse a XML schema Notation declaration * * Returns the new structure or NULL in case of error */static xmlSchemaNotationPtrxmlSchemaParseNotation(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, xmlNodePtr node){ const xmlChar *name; xmlSchemaNotationPtr ret; xmlNodePtr child = NULL; if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) return (NULL); name = xmlSchemaGetProp(ctxt, node, "name"); if (name == NULL) { xmlSchemaPErr2(ctxt, node, child, XML_SCHEMAP_NOTATION_NO_NAME, "Notation has no name\n", NULL, NULL); return (NULL); } ret = xmlSchemaAddNotation(ctxt, schema, name); if (ret == NULL) { return (NULL); } child = node->children; if (IS_SCHEMA(child, "annotation")) { ret->annot = xmlSchemaParseAnnotation(ctxt, schema, child); child = child->next; } if (child != NULL) { xmlSchemaPErr2(ctxt, node, child, XML_SCHEMAP_UNKNOWN_NOTATION_CHILD, "notation %s has unexpected content\n", name, NULL); } return (ret);}/** * xmlSchemaParseAnyAttribute: * @ctxt: a schema validation context * @schema: the schema being built * @node: a subtree containing XML Schema informations * * parse a XML schema AnyAttrribute declaration * *WARNING* this interface is highly subject to change * * Returns an attribute def structure or NULL */static xmlSchemaAttributePtrxmlSchemaParseAnyAttribute(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, xmlNodePtr node){ const xmlChar *processContents; xmlSchemaAttributePtr ret; xmlNodePtr child = NULL; char name[100]; if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) return (NULL); _snprintf(name, 99, "anyattr %d", ctxt->counter++ + 1); /* local = xmlSchemaGetNamespace(ctxt, schema, node, BAD_CAST "anyattr", &ns); */ /* * TODO: namespace = ((##any | ##other) | List of (anyURI | * (##targetNamespace | * ##local)) ) : ##any */ ret = xmlSchemaAddAttribute(ctxt, schema, BAD_CAST name, NULL); if (ret == NULL) { return (NULL); } ret->type = XML_SCHEMA_TYPE_ANY_ATTRIBUTE; ret->id = xmlSchemaGetProp(ctxt, node, "id"); processContents = xmlSchemaGetProp(ctxt, node, "processContents"); if ((processContents == NULL) || (xmlStrEqual(processContents, (const xmlChar *) "strict"))) { ret->occurs = XML_SCHEMAS_ANYATTR_STRICT; } else if (xmlStrEqual(processContents, (const xmlChar *) "skip")) { ret->occurs = XML_SCHEMAS_ANYATTR_SKIP; } else if (xmlStrEqual(processContents, (const xmlChar *) "lax")) { ret->occurs = XML_SCHEMAS_ANYATTR_LAX; } else { xmlSchemaPErr2(ctxt, node, child, XML_SCHEMAP_UNKNOWN_PROCESSCONTENT_CHILD, "anyAttribute has unexpected content " "for processContents: %s\n", processContents, NULL); ret->occurs = XML_SCHEMAS_ANYATTR_STRICT; } child = node->children; if (IS_SCHEMA(child, "annotation")) { ret->annot = xmlSchemaParseAnnotation(ctxt, schema, child); child = child->next; } if (child != NULL) { xmlSchemaPErr2(ctxt, node, child, XML_SCHEMAP_UNKNOWN_ANYATTRIBUTE_CHILD, "anyAttribute %s has unexpected content\n", (const xmlChar *) name, NULL); } return (ret);}/** * xmlSchemaParseAttribute: * @ctxt: a schema validation context * @schema: the schema being built * @node: a subtree containing XML Schema informations * * parse a XML schema Attrribute declaration * *WARNING* this interface is highly subject to change * * Returns the attribute declaration. */static xmlSchemaAttributePtrxmlSchemaParseAttribute(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, xmlNodePtr node, int topLevel){ const xmlChar *name, *refNs = NULL, *ref = NULL, *attrVal; xmlSchemaAttributePtr ret; xmlNodePtr child = NULL; char buf[100]; int hasRefType = 0; /* * Note that the w3c spec assumes the schema to be validated with schema * for schemas beforehand. * * 3.2.3 Constraints on XML Representations of Attribute Declarations * * TODO: Complete implementation of: * 3.2.6 Schema Component Constraint: Attribute Declaration Properties * Correct */ if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) return (NULL); name = xmlSchemaGetProp(ctxt, node, "name"); if (name == NULL) { ref = xmlGetQNameProp(ctxt, node, "ref", &refNs); /* 3.2.3 : 3.1 * One of ref or name must be present, but not both */ if (ref == NULL) { xmlSchemaPErr(ctxt, node, XML_SCHEMAP_ATTR_NONAME_NOREF, "Attribute declaration has no \"name\" or \"ref\"\n", NULL, NULL); return (NULL); } hasRefType = 1; _snprintf(buf, 99, "anonattr %d", ctxt->counter++ + 1); name = (const xmlChar *) buf; ret = xmlSchemaAddAttribute(ctxt, schema, name, NULL); if (!topLevel) { /* 3.2.3 : 3.2 * If ref is present, then all of <simpleType>, * form and type must be absent. */ if (xmlSchemaGetProp(ctxt, node, "form") != NULL) { xmlSchemaPErr(ctxt, node, XML_SCHEMAP_INVALID_ATTR_COMBINATION, "Attribute declaration %s has \"ref\", thus " "\"form\" must be absent\n", name, NULL); } if (xmlSchemaGetProp(ctxt, node, "type") != NULL) { xmlSchemaPErr(ctxt, node, XML_SCHEMAP_INVALID_ATTR_COMBINATION, "Attribute declaration %s has \"ref\", thus " "\"type\" must be absent\n", name, NULL); } } } else { const xmlChar *ns = NULL; /* 3.2.3 : 3.1 * One of ref or name must be present, but not both */ if ((!topLevel) && (xmlSchemaGetProp(ctxt, node, "ref") != NULL)) { xmlSchemaPErr(ctxt, node, XML_SCHEMAP_INVALID_ATTR_COMBINATION, "Attribute declaration has both, \"name\" and " "\"ref\"\n", NULL, NULL); } /* local = xmlSchemaGetNamespace(ctxt, schema, node, name, &ns); */ /* Evaluate the target namespace */ if (schema->targetNamespace != NULL) { if (topLevel) { ns = schema->targetNamespace; } else if (xmlSchemaGetProp(ctxt, node, "form") != NULL) { if (xmlStrEqual( xmlSchemaGetProp(ctxt, node, "form"), BAD_CAST "qualified")) { ns = schema->targetNamespace; } } else if (schema->flags & XML_SCHEMAS_QUALIF_ATTR) { ns = schema->targetNamespace; } } ret = xmlSchemaAddAttribute(ctxt, schema, name, ns); /* 3.2.6 Schema Component Constraint: xmlns Not Allowed */ if (xmlStrEqual(name, BAD_CAST "xmlns")) { xmlSchemaPErr(ctxt, node, XML_SCHEMAP_INVALID_ATTR_NAME, "The name of an attribute declaration must not match " "\"xmlns\".\n", NULL, NULL); } /* 3.2.6 Schema Component Constraint: xsi: Not Allowed */ if (xmlStrEqual(ret->targetNamespace, xmlSchemaInstanceNs)) { xmlSchemaPErr(ctxt, node, XML_SCHEMAP_INVALID_ATTR_NAME, "The target namespace of an attribute declaration, " "must not match \"http://www.w3.org/2001/" "XMLSchema-instance\"", NULL, NULL); } } if (ret == NULL) { return (NULL); } ret->type = XML_SCHEMA_TYPE_ATTRIBUTE; /* Handle the "use" attribute. */ attrVal = xmlSchemaGetProp(ctxt, node, "use"); if (attrVal != NULL) { if (xmlStrEqual(attrVal, BAD_CAST "optional")) ret->occurs = XML_SCHEMAS_ATTR_USE_OPTIONAL; else if (xmlStrEqual(attrVal, BAD_CAST "prohibited")) ret->occurs = XML_SCHEMAS_ATTR_USE_PROHIBITED; else if (xmlStrEqual(attrVal, BAD_CAST "required")) ret->occurs = XML_SCHEMAS_ATTR_USE_REQUIRED; else xmlSchemaPErr(ctxt, node, XML_SCHEMAP_INVALID_ATTR_USE, "Attribute declaration %s has an invalid " "value for \"use\"\n", name, NULL); } else ret->occurs = XML_SCHEMAS_ATTR_USE_OPTIONAL; if (xmlSchemaGetProp(ctxt, node, "default") != NULL) { /* 3.2.3 : 1 * default and fixed must not both be present. */ if (xmlSchemaGetProp(ctxt, node, "fixed") != NULL) { xmlSchemaPErr(ctxt, node, XML_SCHEMAP_INVALID_ATTR_COMBINATION, "Attribute declaration has both, \"default\" " "and \"fixed\"\n", NULL, NULL); } /* 3.2.3 : 2 * If default and use are both present, use must have * the actual value optional. */ if (ret->occurs != XML_SCHEMAS_ATTR_USE_OPTIONAL) { xmlSchemaPErr(ctxt, node, XML_SCHEMAP_INVALID_ATTR_COMBINATION, "Attribute declaration has \"default\" but " "\"use\" is not \"optional\"\n", NULL, NULL); } } ret->ref = ref; ret->refNs = refNs; /* * The setting of XML_SCHEMAS_ATTR_NSDEFAULT is not needed anymore, * since the target namespace was already evaluated and took * attributeFormDefault into account. */ /* if ((ret->targetNamespace != NULL) && ((schema->flags & XML_SCHEMAS_QUALIF_ATTR) == 0) && (xmlStrEqual(ret->targetNamespace, schema->targetNamespace))) ret->flags |= XML_SCHEMAS_ATTR_NSDEFAULT; */ ret->typeName = xmlGetQNameProp(ctxt, node, "type", &(ret->typeNs)); if (ret->typeName != NULL) hasRefType = 1; ret->node = node; child = node->children; if (IS_SCHEMA(child, "annotation")) { ret->annot = xmlSchemaParseAnnotation(ctxt, schema, child); child = child->next; } if (IS_SCHEMA(child, "simpleType")) { if (hasRefType) { /* 3.2.3 : 4 * type and <simpleType> must not both be present. * * TODO: XML_SCHEMAP_INVALID_ATTR_COMBINATION seems not to be * a proper error type here. */ xmlSchemaPErr2(ctxt, node, child, XML_SCHEMAP_INVALID_ATTR_COMBINATION, "Attribute declaration %s has both (\"ref\" or " "\"type\") and <simpleType>\n", name, NULL); } else ret->subtypes = xmlSchemaParseSimpleType(ctxt, schema, child); child = child->next; } if (child != NULL) { xmlSchemaPErr2(ctxt, node, child, XML_SCHEMAP_UNKNOWN_ATTR_CHILD, "attribute %s has unexpected content\n", name, NULL); } return (ret);}/** * xmlSchemaParseAttributeGroup: * @ctxt: a schema validation context * @schema: the schema being built * @node: a subtree containing XML Schema informations * * parse a XML schema Attribute Group declaration * *WARNING* this interface is highly subject to change * * Returns the attribute group or NULL in case of error. */static xmlSchemaAttr
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -