⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xmlschemas.c.svn-base

📁 这是一个用于解析xml文件的类库。使用这个类库
💻 SVN-BASE
📖 第 1 页 / 共 5 页
字号:
    }    memset(ret, 0, sizeof(xmlSchemaElement));    ret->name = xmlDictLookup(ctxt->dict, name, -1);    ret->targetNamespace = xmlDictLookup(ctxt->dict, namespace, -1);    val = xmlHashAddEntry3(schema->elemDecl, name,                           namespace, ctxt->container, ret);    if (val != 0) {        char buf[100];        _snprintf(buf, 99, "privatieelem %d", ctxt->counter++ + 1);        val = xmlHashAddEntry3(schema->elemDecl, name, (xmlChar *) buf,                               namespace, ret);        if (val != 0) {	    xmlSchemaPErr(ctxt, (xmlNodePtr) ctxt->doc,			  XML_SCHEMAP_REDEFINED_ELEMENT,			  "Element %s already defined\n",			  name, NULL);            xmlFree(ret);            return (NULL);        }    }    return (ret);}/** * xmlSchemaAddType: * @ctxt:  a schema validation context * @schema:  the schema being built * @name:  the item name * @namespace:  the namespace * * Add an XML schema Simple Type definition * *WARNING* this interface is highly subject to change * * Returns the new struture or NULL in case of error */static xmlSchemaTypePtrxmlSchemaAddType(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,                 const xmlChar * name, const xmlChar * namespace){    xmlSchemaTypePtr ret = NULL;    int val;    if ((ctxt == NULL) || (schema == NULL) || (name == NULL))        return (NULL);#ifdef DEBUG    fprintf(stderr, "Adding type %s\n", name);    if (namespace != NULL)	fprintf(stderr, "  target namespace %s\n", namespace);#endif    if (schema->typeDecl == NULL)        schema->typeDecl = xmlHashCreate(10);    if (schema->typeDecl == NULL)        return (NULL);    ret = (xmlSchemaTypePtr) xmlMalloc(sizeof(xmlSchemaType));    if (ret == NULL) {        xmlSchemaPErrMemory(ctxt, "allocating type", NULL);        return (NULL);    }    memset(ret, 0, sizeof(xmlSchemaType));    ret->name = xmlDictLookup(ctxt->dict, name, -1);    ret->redef = NULL;    val = xmlHashAddEntry2(schema->typeDecl, name, namespace, ret);    if (val != 0) {        if (ctxt->includes == 0) {	    xmlSchemaPErr(ctxt, (xmlNodePtr) ctxt->doc,			  XML_SCHEMAP_REDEFINED_TYPE,			  "Type %s already defined\n",			  name, NULL);	    xmlFree(ret);	    return (NULL);	} else {	    xmlSchemaTypePtr prev;	    prev = xmlHashLookup2(schema->typeDecl, name, namespace);	    if (prev == NULL) {		xmlSchemaPErr(ctxt, (xmlNodePtr) ctxt->doc,			      XML_ERR_INTERNAL_ERROR,			      "Internal error on type %s definition\n",			      name, NULL);		xmlFree(ret);		return (NULL);	    }	    ret->redef = prev->redef;	    prev->redef = ret;	}    }    ret->minOccurs = 1;    ret->maxOccurs = 1;    return (ret);}/** * xmlSchemaAddGroup: * @ctxt:  a schema validation context * @schema:  the schema being built * @name:  the group name * * Add an XML schema Group definition * * Returns the new struture or NULL in case of error */static xmlSchemaTypePtrxmlSchemaAddGroup(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,                  const xmlChar * name){    xmlSchemaTypePtr ret = NULL;    int val;    if ((ctxt == NULL) || (schema == NULL) || (name == NULL))        return (NULL);    if (schema->groupDecl == NULL)        schema->groupDecl = xmlHashCreate(10);    if (schema->groupDecl == NULL)        return (NULL);    ret = (xmlSchemaTypePtr) xmlMalloc(sizeof(xmlSchemaType));    if (ret == NULL) {        xmlSchemaPErrMemory(ctxt, "adding group", NULL);        return (NULL);    }    memset(ret, 0, sizeof(xmlSchemaType));    ret->name = xmlDictLookup(ctxt->dict, name, -1);    val =        xmlHashAddEntry2(schema->groupDecl, name, schema->targetNamespace,                         ret);    if (val != 0) {	xmlSchemaPErr(ctxt, (xmlNodePtr) ctxt->doc,		      XML_SCHEMAP_REDEFINED_GROUP,                      "Group %s already defined\n",                      name, NULL);        xmlFree(ret);        return (NULL);    }    ret->minOccurs = 1;    ret->maxOccurs = 1;    return (ret);}/************************************************************************ * 									* *		Utilities for parsing					* * 									* ************************************************************************//** * xmlGetQNameProp: * @ctxt:  a schema validation context * @node:  a subtree containing XML Schema informations * @name:  the attribute name * @namespace:  the result namespace if any * * Extract a QName Attribute value * * Returns the NCName or NULL if not found, and also update @namespace *    with the namespace URI */static const xmlChar *xmlGetQNameProp(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node,                const char *name, const xmlChar ** namespace){    const xmlChar *val;    xmlNsPtr ns;    const xmlChar *ret, *prefix;    int len;    *namespace = NULL;    val = xmlSchemaGetProp(ctxt, node, name);    if (val == NULL)        return (NULL);    if (!strchr((char *) val, ':')) {	ns = xmlSearchNs(node->doc, node, 0);	if (ns) {	    *namespace = xmlDictLookup(ctxt->dict, ns->href, -1);	    return (val);	}    }    ret = xmlSplitQName3(val, &len);    if (ret == NULL) {        return (val);    }    ret = xmlDictLookup(ctxt->dict, ret, -1);    prefix = xmlDictLookup(ctxt->dict, val, len);    ns = xmlSearchNs(node->doc, node, prefix);    if (ns == NULL) {        xmlSchemaPErr(ctxt, node, XML_SCHEMAP_PREFIX_UNDEFINED,                      "Attribute %s: the QName prefix %s is undefined\n",                      (const xmlChar *) name, prefix);    } else {        *namespace = xmlDictLookup(ctxt->dict, ns->href, -1);    }    return (ret);}/** * xmlGetMaxOccurs: * @ctxt:  a schema validation context * @node:  a subtree containing XML Schema informations * * Get the maxOccurs property * * Returns the default if not found, or the value */static intxmlGetMaxOccurs(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node){    const xmlChar *val, *cur;    int ret = 0;    val = xmlSchemaGetProp(ctxt, node, "maxOccurs");    if (val == NULL)        return (1);    if (xmlStrEqual(val, (const xmlChar *) "unbounded")) {        return (UNBOUNDED);  /* encoding it with -1 might be another option */    }    cur = val;    while (IS_BLANK_CH(*cur))        cur++;    while ((*cur >= '0') && (*cur <= '9')) {        ret = ret * 10 + (*cur - '0');        cur++;    }    while (IS_BLANK_CH(*cur))        cur++;    if (*cur != 0) {        xmlSchemaPErr(ctxt, node, XML_SCHEMAP_INVALID_MAXOCCURS,                      "invalid value for maxOccurs: %s\n", val, NULL);        return (1);    }    return (ret);}/** * xmlGetMinOccurs: * @ctxt:  a schema validation context * @node:  a subtree containing XML Schema informations * * Get the minOccurs property * * Returns the default if not found, or the value */static intxmlGetMinOccurs(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node){    const xmlChar *val, *cur;    int ret = 0;    val = xmlSchemaGetProp(ctxt, node, "minOccurs");    if (val == NULL)        return (1);    cur = val;    while (IS_BLANK_CH(*cur))        cur++;    while ((*cur >= '0') && (*cur <= '9')) {        ret = ret * 10 + (*cur - '0');        cur++;    }    while (IS_BLANK_CH(*cur))        cur++;    if (*cur != 0) {        xmlSchemaPErr(ctxt, node, XML_SCHEMAP_INVALID_MINOCCURS,                      "invalid value for minOccurs: %s\n", val, NULL);        return (1);    }    return (ret);}/** * xmlGetBooleanProp: * @ctxt:  a schema validation context * @node:  a subtree containing XML Schema informations * @name:  the attribute name * @def:  the default value * * Get is a bolean property is set * * Returns the default if not found, 0 if found to be false, *         1 if found to be true */static intxmlGetBooleanProp(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node,                  const char *name, int def){    const xmlChar *val;    val = xmlSchemaGetProp(ctxt, node, name);    if (val == NULL)        return (def);    if (xmlStrEqual(val, BAD_CAST "true"))        def = 1;    else if (xmlStrEqual(val, BAD_CAST "false"))        def = 0;    else {        xmlSchemaPErr(ctxt, node, XML_SCHEMAP_INVALID_BOOLEAN,                      "Attribute %s: the value %s is not boolean\n",                      (const xmlChar *) name, val);    }    return (def);}/************************************************************************ * 									* *		Shema extraction from an Infoset			* * 									* ************************************************************************/static xmlSchemaTypePtr xmlSchemaParseSimpleType(xmlSchemaParserCtxtPtr                                                 ctxt, xmlSchemaPtr schema,                                                 xmlNodePtr node);static xmlSchemaTypePtr xmlSchemaParseComplexType(xmlSchemaParserCtxtPtr                                                  ctxt,                                                  xmlSchemaPtr schema,                                                  xmlNodePtr node);static xmlSchemaTypePtr xmlSchemaParseRestriction(xmlSchemaParserCtxtPtr                                                  ctxt,                                                  xmlSchemaPtr schema,                                                  xmlNodePtr node,                                                  int simple);static xmlSchemaTypePtr xmlSchemaParseSequence(xmlSchemaParserCtxtPtr ctxt,                                               xmlSchemaPtr schema,                                               xmlNodePtr node);static xmlSchemaTypePtr xmlSchemaParseAll(xmlSchemaParserCtxtPtr ctxt,                                          xmlSchemaPtr schema,                                          xmlNodePtr node);static xmlSchemaAttributePtr xmlSchemaParseAttribute(xmlSchemaParserCtxtPtr                                                     ctxt,                                                     xmlSchemaPtr schema,                                                     xmlNodePtr node,						     int topLevel);static xmlSchemaAttributeGroupPtrxmlSchemaParseAttributeGroup(xmlSchemaParserCtxtPtr ctxt,                             xmlSchemaPtr schema, xmlNodePtr node);static xmlSchemaTypePtr xmlSchemaParseChoice(xmlSchemaParserCtxtPtr ctxt,                                             xmlSchemaPtr schema,                                             xmlNodePtr node);static xmlSchemaTypePtr xmlSchemaParseList(xmlSchemaParserCtxtPtr ctxt,                                           xmlSchemaPtr schema,                                           xmlNodePtr node);static xmlSchemaAttributePtrxmlSchemaParseAnyAttribute(xmlSchemaParserCtxtPtr ctxt,                           xmlSchemaPtr schema, xmlNodePtr node);/** * xmlSchemaParseAttrDecls: * @ctxt:  a schema validation context * @schema:  the schema being built * @node:  a subtree containing XML Schema informations * @type:  the hosting type * * parse a XML schema attrDecls declaration corresponding to * <!ENTITY % attrDecls   *       '((%attribute;| %attributeGroup;)*,(%anyAttribute;)?)'> */static xmlNodePtrxmlSchemaParseAttrDecls(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,                        xmlNodePtr child, xmlSchemaTypePtr type){    xmlSchemaAttributePtr lastattr, attr;    lastattr = NULL;    while ((IS_SCHEMA(child, "attribute")) ||           (IS_SCHEMA(child, "attributeGroup"))) {        attr = NULL;        if (IS_SCHEMA(child, "attribute")) {            attr = xmlSchemaParseAttribute(ctxt, schema, child, 0);        } else if (IS_SCHEMA(child, "attributeGroup")) {            attr = (xmlSchemaAttributePtr)                xmlSchemaParseAttributeGroup(ctxt, schema, child);        }        if (attr != NULL) {            if (lastattr == NULL) {                type->attributes = attr;                lastattr = attr;            } else {                lastattr->next = attr;                lastattr = attr;            }        }        child = child->next;    }    if (IS_SCHEMA(child, "anyAttribute")) {        attr = xmlSchemaParseAnyAttribute(ctxt, schema, child);        if (attr != NULL) {            if (lastattr == NULL) {                type->attributes = attr;                lastattr = attr;            } else {                lastattr->next = attr;                lastattr = attr;            }        }        child = child->next;    }    return (child);}/** * xmlSchemaParseAnnotation: * @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 -1 in case of error, 0 if the declaration is improper and *         1 in case of success. */static xmlSchemaAnnotPtrxmlSchemaParseAnnotation(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,                         xmlNodePtr node){    xmlSchemaAnnotPtr ret;    if ((ctxt == NULL) || (schema == NULL) || (node == NULL))        return (NULL);    ret = xmlSchemaNewAnnot(ctxt, node);    return (ret);}/** * xmlSchemaParseFacet: * @ctxt:  a schema validation context * @schema:  the schema being built * @node:  a subtree containing XML Schema informations * * parse a XML schema Facet declaration * *WARNING* this interface is highly subject to change * * Returns the new type structure or NULL in case of error */static xmlSchemaFacetPtrxmlSchemaParseFacet(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,                    xmlNodePtr node){    xmlSchemaFacetPtr facet;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -