📄 xmlschemas.c.svn-base
字号:
xmlSchemaAnnotDump(output, schema->annot); xmlHashScan(schema->typeDecl, (xmlHashScanner) xmlSchemaTypeDump, output); xmlHashScanFull(schema->elemDecl, (xmlHashScannerFull) xmlSchemaElementDump, output);}#endif /* LIBXML_OUTPUT_ENABLED *//************************************************************************ * * * Utilities * * * ************************************************************************//** * xmlSchemaGetProp: * @ctxt: the parser context * @node: the node * @name: the property name * * Read a attribute value and internalize the string * * Returns the string or NULL if not present. */static const xmlChar *xmlSchemaGetProp(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node, const char *name){ xmlChar *val; const xmlChar *ret; val = xmlGetProp(node, BAD_CAST name); if (val == NULL) return(NULL); ret = xmlDictLookup(ctxt->dict, val, -1); xmlFree(val); return(ret);}#if 0/** * xmlSchemaGetNamespace: * @ctxt: the parser context * @schema: the schemas containing the declaration * @node: the node * @qname: the QName to analyze * * Find the namespace name for the given declaration. * * Returns the local name for that declaration, as well as the namespace name * NOTE: This function is no longer used (Buchcik, May '04) */static const xmlChar *xmlSchemaGetNamespace(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, xmlNodePtr node, const xmlChar *qname, const xmlChar **namespace) { int len; const xmlChar *name, *prefix, *def = NULL; xmlNsPtr ns; *namespace = NULL; /* TODO: The following seems to be not correct here: * 1. The name of a declaration is a NCName, not a QName. * 2. The attribute "targetNamespace" is allowed for the * <schema> Element Information Item only. * 3. One cannot evaluate the target namespace, by the type * of declaration, since it is dependant on the xxxFormDefault * of <schema> and the form attribute of an <element> or <attribute>. */ if (xmlStrEqual(node->name, BAD_CAST "element") || xmlStrEqual(node->name, BAD_CAST "attribute") || xmlStrEqual(node->name, BAD_CAST "simpleType") || xmlStrEqual(node->name, BAD_CAST "complexType")) { def = xmlSchemaGetProp(ctxt, node, "targetNamespace"); } qname = xmlDictLookup(ctxt->dict, qname, -1); /* intern the string */ name = xmlSplitQName3(qname, &len); if (name == NULL) { if (def == NULL) { if (xmlStrEqual(node->name, BAD_CAST "element")) { if (schema->flags & XML_SCHEMAS_QUALIF_ELEM) *namespace = schema->targetNamespace; } else if (xmlStrEqual(node->name, BAD_CAST "attribute")) { if (schema->flags & XML_SCHEMAS_QUALIF_ATTR) *namespace = schema->targetNamespace; } else if ((xmlStrEqual(node->name, BAD_CAST "simpleType")) || (xmlStrEqual(node->name, BAD_CAST "complexType"))) { *namespace = schema->targetNamespace; } } else { *namespace = def; } return(qname); } name = xmlDictLookup(ctxt->dict, name, -1); prefix = xmlDictLookup(ctxt->dict, qname, len); if (def != NULL) { xmlSchemaPErr(ctxt, node, XML_SCHEMAP_DEF_AND_PREFIX, "%s: presence of both prefix %s and targetNamespace\n", node->name, prefix); } ns = xmlSearchNs(node->doc, node, prefix); if (ns == NULL) { xmlSchemaPErr(ctxt, node, XML_SCHEMAP_PREFIX_UNDEFINED, "%s: the QName prefix %s is undefined\n", node->name, prefix); return(name); } *namespace = xmlDictLookup(ctxt->dict, ns->href, -1); return(name);}#endif/************************************************************************ * * * Parsing functions * * * ************************************************************************//** * xmlSchemaGetElem: * @schema: the schemas context * @name: the element name * @ns: the element namespace * @level: how deep is the request * * Lookup a an element in the schemas or the accessible schemas * * Returns the element definition or NULL if not found. */static xmlSchemaElementPtrxmlSchemaGetElem(xmlSchemaPtr schema, const xmlChar * name, const xmlChar * namespace, int level){ xmlSchemaElementPtr ret; xmlSchemaImportPtr import = NULL; if ((name == NULL) || (schema == NULL)) return (NULL); if (namespace == NULL) { ret = xmlHashLookup2(schema->elemDecl, name, namespace); if ((ret != NULL) && ((level == 0) || (ret->flags & XML_SCHEMAS_ELEM_TOPLEVEL))) { return (ret); } /* * This one was removed, since top level element declarations have * the target namespace specified in targetNamespace of the <schema> * information element, even if elementFormDefault is "unqualified". */ /* else if ((schema->flags & XML_SCHEMAS_QUALIF_ELEM) == 0) { if (xmlStrEqual(namespace, schema->targetNamespace)) ret = xmlHashLookup2(schema->elemDecl, name, NULL); else ret = xmlHashLookup2(schema->elemDecl, name, namespace); if ((ret != NULL) && ((level == 0) || (ret->flags & XML_SCHEMAS_ELEM_TOPLEVEL))) { return (ret); } */ } else { ret = xmlHashLookup2(schema->elemDecl, name, namespace); if ((ret != NULL) && ((level == 0) || (ret->flags & XML_SCHEMAS_ELEM_TOPLEVEL))) { return (ret); } } if (level > 0) import = xmlHashLookup(schema->schemasImports, namespace); if (import != NULL) ret = xmlSchemaGetElem(import->schema, name, namespace, level + 1);#ifdef DEBUG if (ret == NULL) { if (namespace == NULL) fprintf(stderr, "Unable to lookup type %s", name); else fprintf(stderr, "Unable to lookup type %s:%s", name, namespace); }#endif return (ret);}/** * xmlSchemaGetType: * @schema: the schemas context * @name: the type name * @ns: the type namespace * * Lookup a type in the schemas or the predefined types * * Returns the group definition or NULL if not found. */static xmlSchemaTypePtrxmlSchemaGetType(xmlSchemaPtr schema, const xmlChar * name, const xmlChar * namespace){ xmlSchemaTypePtr ret; xmlSchemaImportPtr import; if (name == NULL) return (NULL); if (schema != NULL) { ret = xmlHashLookup2(schema->typeDecl, name, namespace); if (ret != NULL) return (ret); } ret = xmlSchemaGetPredefinedType(name, namespace); if (ret != NULL) return (ret); import = xmlHashLookup(schema->schemasImports, namespace); if (import != NULL) ret = xmlSchemaGetType(import->schema, name, namespace);#ifdef DEBUG if (ret == NULL) { if (namespace == NULL) fprintf(stderr, "Unable to lookup type %s", name); else fprintf(stderr, "Unable to lookup type %s:%s", name, namespace); }#endif return (ret);}/************************************************************************ * * * Parsing functions * * * ************************************************************************/#define IS_BLANK_NODE(n) \ (((n)->type == XML_TEXT_NODE) && (xmlSchemaIsBlank((n)->content)))/** * xmlSchemaIsBlank: * @str: a string * * Check if a string is ignorable * * Returns 1 if the string is NULL or made of blanks chars, 0 otherwise */static intxmlSchemaIsBlank(xmlChar * str){ if (str == NULL) return (1); while (*str != 0) { if (!(IS_BLANK_CH(*str))) return (0); str++; } return (1);}/** * xmlSchemaAddNotation: * @ctxt: a schema validation context * @schema: the schema being built * @name: the item name * * Add an XML schema Attrribute declaration * *WARNING* this interface is highly subject to change * * Returns the new struture or NULL in case of error */static xmlSchemaNotationPtrxmlSchemaAddNotation(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, const xmlChar * name){ xmlSchemaNotationPtr ret = NULL; int val; if ((ctxt == NULL) || (schema == NULL) || (name == NULL)) return (NULL); if (schema->notaDecl == NULL) schema->notaDecl = xmlHashCreate(10); if (schema->notaDecl == NULL) return (NULL); ret = (xmlSchemaNotationPtr) xmlMalloc(sizeof(xmlSchemaNotation)); if (ret == NULL) { xmlSchemaPErrMemory(ctxt, "add annotation", NULL); return (NULL); } memset(ret, 0, sizeof(xmlSchemaNotation)); ret->name = xmlDictLookup(ctxt->dict, name, -1); val = xmlHashAddEntry2(schema->notaDecl, name, schema->targetNamespace, ret); if (val != 0) { xmlSchemaPErr(ctxt, (xmlNodePtr) ctxt->doc, XML_SCHEMAP_REDEFINED_NOTATION, "Notation %s already defined\n", name, NULL); xmlFree(ret); return (NULL); } return (ret);}/** * xmlSchemaAddAttribute: * @ctxt: a schema validation context * @schema: the schema being built * @name: the item name * @namespace: the namespace * * Add an XML schema Attrribute declaration * *WARNING* this interface is highly subject to change * * Returns the new struture or NULL in case of error */static xmlSchemaAttributePtrxmlSchemaAddAttribute(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, const xmlChar * name, const xmlChar * namespace){ xmlSchemaAttributePtr ret = NULL; int val; if ((ctxt == NULL) || (schema == NULL) || (name == NULL)) return (NULL);#ifdef DEBUG fprintf(stderr, "Adding attribute %s\n", name); if (namespace != NULL) fprintf(stderr, " target namespace %s\n", namespace);#endif if (schema->attrDecl == NULL) schema->attrDecl = xmlHashCreate(10); if (schema->attrDecl == NULL) return (NULL); ret = (xmlSchemaAttributePtr) xmlMalloc(sizeof(xmlSchemaAttribute)); if (ret == NULL) { xmlSchemaPErrMemory(ctxt, "allocating attribute", NULL); return (NULL); } memset(ret, 0, sizeof(xmlSchemaAttribute)); ret->name = xmlDictLookup(ctxt->dict, name, -1); ret->targetNamespace = xmlDictLookup(ctxt->dict, namespace, -1); val = xmlHashAddEntry3(schema->attrDecl, name, schema->targetNamespace, ctxt->container, ret); if (val != 0) { xmlSchemaPErr(ctxt, (xmlNodePtr) ctxt->doc, XML_SCHEMAP_REDEFINED_ATTR, "Attribute %s already defined\n", name, NULL); xmlFree(ret); return (NULL); } return (ret);}/** * xmlSchemaAddAttributeGroup: * @ctxt: a schema validation context * @schema: the schema being built * @name: the item name * * Add an XML schema Attrribute Group declaration * * Returns the new struture or NULL in case of error */static xmlSchemaAttributeGroupPtrxmlSchemaAddAttributeGroup(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, const xmlChar * name){ xmlSchemaAttributeGroupPtr ret = NULL; int val; if ((ctxt == NULL) || (schema == NULL) || (name == NULL)) return (NULL); if (schema->attrgrpDecl == NULL) schema->attrgrpDecl = xmlHashCreate(10); if (schema->attrgrpDecl == NULL) return (NULL); ret = (xmlSchemaAttributeGroupPtr) xmlMalloc(sizeof(xmlSchemaAttributeGroup)); if (ret == NULL) { xmlSchemaPErrMemory(ctxt, "allocating attribute group", NULL); return (NULL); } memset(ret, 0, sizeof(xmlSchemaAttributeGroup)); ret->name = xmlDictLookup(ctxt->dict, name, -1); val = xmlHashAddEntry3(schema->attrgrpDecl, name, schema->targetNamespace, ctxt->container, ret); if (val != 0) { xmlSchemaPErr(ctxt, (xmlNodePtr) ctxt->doc, XML_SCHEMAP_REDEFINED_ATTRGROUP, "Attribute group %s already defined\n", name, NULL); xmlFree(ret); return (NULL); } return (ret);}/** * xmlSchemaAddElement: * @ctxt: a schema validation context * @schema: the schema being built * @name: the type name * @namespace: the type namespace * * Add an XML schema Element declaration * *WARNING* this interface is highly subject to change * * Returns the new struture or NULL in case of error */static xmlSchemaElementPtrxmlSchemaAddElement(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, const xmlChar * name, const xmlChar * namespace){ xmlSchemaElementPtr ret = NULL; int val; if ((ctxt == NULL) || (schema == NULL) || (name == NULL)) return (NULL);#ifdef DEBUG fprintf(stderr, "Adding element %s\n", name); if (namespace != NULL) fprintf(stderr, " target namespace %s\n", namespace);#endif if (schema->elemDecl == NULL) schema->elemDecl = xmlHashCreate(10); if (schema->elemDecl == NULL) return (NULL); ret = (xmlSchemaElementPtr) xmlMalloc(sizeof(xmlSchemaElement)); if (ret == NULL) { xmlSchemaPErrMemory(ctxt, "allocating element", NULL); return (NULL);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -