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

📄 valid.c

📁 SIP 1.5.0源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
    ret = (xmlElementPtr) xmlMalloc(sizeof(xmlElement));    if (ret == NULL) {	fprintf(stderr, "xmlAddElementDecl: out of memory\n");	return(NULL);    }    memset(ret, 0, sizeof(xmlElement));    ret->type = XML_ELEMENT_DECL;    table->table[table->nb_elements] = ret;    /*     * fill the structure.     */    ret->etype = type;    ret->name = xmlStrdup(name);    ret->content = xmlCopyElementContent(content);    ret->attributes = xmlScanAttributeDecl(dtd, name);    table->nb_elements++;    /*     * Link it to the Dtd     */    ret->parent = dtd;    ret->doc = dtd->doc;    if (dtd->last == NULL) {	dtd->children = dtd->last = (xmlNodePtr) ret;    } else {        dtd->last->next = (xmlNodePtr) ret;	ret->prev = dtd->last;	dtd->last = (xmlNodePtr) ret;    }    return(ret);}/** * xmlFreeElement: * @elem:  An element * * Deallocate the memory used by an element definition */voidxmlFreeElement(xmlElementPtr elem) {    if (elem == NULL) return;    xmlUnlinkNode((xmlNodePtr) elem);    xmlFreeElementContent(elem->content);    if (elem->name != NULL)	xmlFree((xmlChar *) elem->name);    memset(elem, -1, sizeof(xmlElement));    xmlFree(elem);}/** * xmlFreeElementTable: * @table:  An element table * * Deallocate the memory used by an element hash table. */voidxmlFreeElementTable(xmlElementTablePtr table) {    int i;    if (table == NULL) return;    for (i = 0;i < table->nb_elements;i++) {        xmlFreeElement(table->table[i]);    }    xmlFree(table->table);    xmlFree(table);}/** * xmlCopyElementTable: * @table:  An element table * * Build a copy of an element table. *  * Returns the new xmlElementTablePtr or NULL in case of error. */xmlElementTablePtrxmlCopyElementTable(xmlElementTablePtr table) {    xmlElementTablePtr ret;    xmlElementPtr cur, ent;    int i;    ret = (xmlElementTablePtr) xmlMalloc(sizeof(xmlElementTable));    if (ret == NULL) {        fprintf(stderr, "xmlCopyElementTable: out of memory !\n");	return(NULL);    }    ret->table = (xmlElementPtr *) xmlMalloc(table->max_elements *                                         sizeof(xmlElementPtr));    if (ret->table == NULL) {        fprintf(stderr, "xmlCopyElementTable: out of memory !\n");	xmlFree(ret);	return(NULL);    }    ret->max_elements = table->max_elements;    ret->nb_elements = table->nb_elements;    for (i = 0;i < ret->nb_elements;i++) {	cur = (xmlElementPtr) xmlMalloc(sizeof(xmlElement));	if (cur == NULL) {	    fprintf(stderr, "xmlCopyElementTable: out of memory !\n");	    xmlFree(ret);	    xmlFree(ret->table);	    return(NULL);	}	memset(cur, 0, sizeof(xmlElement));	cur->type = XML_ELEMENT_DECL;	ret->table[i] = cur;	ent = table->table[i];	cur->etype = ent->etype;	if (ent->name != NULL)	    cur->name = xmlStrdup(ent->name);	else	    cur->name = NULL;	cur->content = xmlCopyElementContent(ent->content);	/* TODO : rebuild the attribute list on the copy */	cur->attributes = NULL;    }    return(ret);}/** * xmlDumpElementDecl: * @buf:  the XML buffer output * @elem:  An element table * * This will dump the content of the element declaration as an XML * DTD definition */voidxmlDumpElementDecl(xmlBufferPtr buf, xmlElementPtr elem) {    switch (elem->etype) {	case XML_ELEMENT_TYPE_EMPTY:	    xmlBufferWriteChar(buf, "<!ELEMENT ");	    xmlBufferWriteCHAR(buf, elem->name);	    xmlBufferWriteChar(buf, " EMPTY>\n");	    break;	case XML_ELEMENT_TYPE_ANY:	    xmlBufferWriteChar(buf, "<!ELEMENT ");	    xmlBufferWriteCHAR(buf, elem->name);	    xmlBufferWriteChar(buf, " ANY>\n");	    break;	case XML_ELEMENT_TYPE_MIXED:	    xmlBufferWriteChar(buf, "<!ELEMENT ");	    xmlBufferWriteCHAR(buf, elem->name);	    xmlBufferWriteChar(buf, " ");	    xmlDumpElementContent(buf, elem->content, 1);	    xmlBufferWriteChar(buf, ">\n");	    break;	case XML_ELEMENT_TYPE_ELEMENT:	    xmlBufferWriteChar(buf, "<!ELEMENT ");	    xmlBufferWriteCHAR(buf, elem->name);	    xmlBufferWriteChar(buf, " ");	    xmlDumpElementContent(buf, elem->content, 1);	    xmlBufferWriteChar(buf, ">\n");	    break;	default:	    fprintf(stderr,		"xmlDumpElementDecl: internal: unknown type %d\n",		    elem->etype);    }}/** * xmlDumpElementTable: * @buf:  the XML buffer output * @table:  An element table * * This will dump the content of the element table as an XML DTD definition */voidxmlDumpElementTable(xmlBufferPtr buf, xmlElementTablePtr table) {    int i;    xmlElementPtr cur;    if (table == NULL) return;    for (i = 0;i < table->nb_elements;i++) {        cur = table->table[i];	xmlDumpElementDecl(buf, cur);    }}/** * xmlCreateEnumeration: * @name:  the enumeration name or NULL * * create and initialize an enumeration attribute node. * * Returns the xmlEnumerationPtr just created or NULL in case *                of error. */xmlEnumerationPtrxmlCreateEnumeration(xmlChar *name) {    xmlEnumerationPtr ret;    ret = (xmlEnumerationPtr) xmlMalloc(sizeof(xmlEnumeration));    if (ret == NULL) {        fprintf(stderr, "xmlCreateEnumeration : xmlMalloc(%ld) failed\n",	        (long)sizeof(xmlEnumeration));        return(NULL);    }    memset(ret, 0, sizeof(xmlEnumeration));    if (name != NULL)        ret->name = xmlStrdup(name);    return(ret);}/** * xmlFreeEnumeration: * @cur:  the tree to free. * * free an enumeration attribute node (recursive). */voidxmlFreeEnumeration(xmlEnumerationPtr cur) {    if (cur == NULL) return;    if (cur->next != NULL) xmlFreeEnumeration(cur->next);    if (cur->name != NULL) xmlFree((xmlChar *) cur->name);    memset(cur, -1, sizeof(xmlEnumeration));    xmlFree(cur);}/** * xmlCopyEnumeration: * @cur:  the tree to copy. * * Copy an enumeration attribute node (recursive). * * Returns the xmlEnumerationPtr just created or NULL in case *                of error. */xmlEnumerationPtrxmlCopyEnumeration(xmlEnumerationPtr cur) {    xmlEnumerationPtr ret;    if (cur == NULL) return(NULL);    ret = xmlCreateEnumeration((xmlChar *) cur->name);    if (cur->next != NULL) ret->next = xmlCopyEnumeration(cur->next);    else ret->next = NULL;    return(ret);}/** * xmlDumpEnumeration: * @buf:  the XML buffer output * @enum:  An enumeration * * This will dump the content of the enumeration */voidxmlDumpEnumeration(xmlBufferPtr buf, xmlEnumerationPtr cur) {    if (cur == NULL)  return;        xmlBufferWriteCHAR(buf, cur->name);    if (cur->next == NULL)	xmlBufferWriteChar(buf, ")");    else {	xmlBufferWriteChar(buf, " | ");	xmlDumpEnumeration(buf, cur->next);    }}/** * xmlCreateAttributeTable: * * create and initialize an empty attribute hash table. * * Returns the xmlAttributeTablePtr just created or NULL in case *                of error. */xmlAttributeTablePtrxmlCreateAttributeTable(void) {    xmlAttributeTablePtr ret;    ret = (xmlAttributeTablePtr)          xmlMalloc(sizeof(xmlAttributeTable));    if (ret == NULL) {        fprintf(stderr, "xmlCreateAttributeTable : xmlMalloc(%ld) failed\n",	        (long)sizeof(xmlAttributeTable));        return(NULL);    }    ret->max_attributes = XML_MIN_ATTRIBUTE_TABLE;    ret->nb_attributes = 0;    ret->table = (xmlAttributePtr *)          xmlMalloc(ret->max_attributes * sizeof(xmlAttributePtr));    if (ret == NULL) {        fprintf(stderr, "xmlCreateAttributeTable : xmlMalloc(%ld) failed\n",	        ret->max_attributes * (long)sizeof(xmlAttributePtr));	xmlFree(ret);        return(NULL);    }    return(ret);}/** * xmlScanAttributeDecl: * @dtd:  pointer to the DTD * @elem:  the element name * * When inserting a new element scan the DtD for existing attributes * for taht element and initialize the Attribute chain * * Returns the pointer to the first attribute decl in the chain, *         possibly NULL. */xmlAttributePtrxmlScanAttributeDecl(xmlDtdPtr dtd, const xmlChar *elem) {    xmlAttributePtr ret = NULL;    xmlAttributeTablePtr table;    int i;    if (dtd == NULL) {        fprintf(stderr, "xmlScanAttributeDecl: dtd == NULL\n");	return(NULL);    }    if (elem == NULL) {        fprintf(stderr, "xmlScanAttributeDecl: elem == NULL\n");	return(NULL);    }    table = dtd->attributes;    if (table == NULL)         return(NULL);    for (i = 0;i < table->nb_attributes;i++) {        if (!xmlStrcmp(table->table[i]->elem, elem)) {	    table->table[i]->nexth = ret;	    ret = table->table[i];	}    }    return(ret);}/** * xmlScanIDAttributeDecl: * @ctxt:  the validation context * @elem:  the element name * * Verify that the element don't have too many ID attributes * declared. * * Returns the number of ID attributes found. */intxmlScanIDAttributeDecl(xmlValidCtxtPtr ctxt, xmlElementPtr elem) {    xmlAttributePtr cur;    int ret = 0;    if (elem == NULL) return(0);    cur = elem->attributes;    while (cur != NULL) {        if (cur->atype == XML_ATTRIBUTE_ID) {	    ret ++;	    if (ret > 1)		VERROR(ctxt->userData, 	       "Element %s has too may ID attributes defined : %s\n",		       elem->name, cur->name);	}	cur = cur->nexth;    }    return(ret);}/** * xmlAddAttributeDecl: * @ctxt:  the validation context * @dtd:  pointer to the DTD * @elem:  the element name * @name:  the attribute name * @ns:  the attribute namespace prefix * @type:  the attribute type * @def:  the attribute default type * @defaultValue:  the attribute default value * @tree:  if it's an enumeration, the associated list * * Register a new attribute declaration * * Returns NULL if not, othervise the entity */xmlAttributePtrxmlAddAttributeDecl(xmlValidCtxtPtr ctxt, xmlDtdPtr dtd, const xmlChar *elem,                    const xmlChar *name, const xmlChar *ns,		    xmlAttributeType type, xmlAttributeDefault def,		    const xmlChar *defaultValue, xmlEnumerationPtr tree) {    xmlAttributePtr ret, cur;    xmlAttributeTablePtr table;    xmlElementPtr elemDef;    int i;    if (dtd == NULL) {        fprintf(stderr, "xmlAddAttributeDecl: dtd == NULL\n");	return(NULL);    }    if (name == NULL) {        fprintf(stderr, "xmlAddAttributeDecl: name == NULL\n");	return(NULL);    }    if (elem == NULL) {        fprintf(stderr, "xmlAddAttributeDecl: elem == NULL\n");	return(NULL);    }    /*     * Check the type and possibly the default value.     */    switch (type) {        case XML_ATTRIBUTE_CDATA:	    break;        case XML_ATTRIBUTE_ID:	    break;        case XML_ATTRIBUTE_IDREF:	    break;        case XML_ATTRIBUTE_IDREFS:	    break;        case XML_ATTRIBUTE_ENTITY:	    break;        case XML_ATTRIBUTE_ENTITIES:	    break;        case XML_ATTRIBUTE_NMTOKEN:	    break;        case XML_ATTRIBUTE_NMTOKENS:	    break;        case XML_ATTRIBUTE_ENUMERATION:	    break;        case XML_ATTRIBUTE_NOTATION:	    break;	default:	    fprintf(stderr, "xmlAddAttributeDecl: unknown type %d\n", type);	    return(NULL);    }    if ((defaultValue != NULL) &&         (!xmlValidateAttributeValue(type, defaultValue))) {	VERROR(ctxt->userData, "Attribute %s on %s: invalid default value\n",	       elem, name, defaultValue);	defaultValue = NULL;    }    /*     * Create the Attribute table if needed.     */    table = dtd->attributes;    if (table == NULL)         table = dtd->attributes = xmlCreateAttributeTable();    if (table == NULL) {	fprintf(stderr, "xmlAddAttributeDecl: Table creation failed!\n");        return(NULL);    }    /*     * Validity Check:     * Search the DTD for previous declarations of the ATTLIST     */    for (i = 0;i < table->nb_attributes;i++) {        cur = table->table[i];	if ((ns != NULL) && (cur->prefix == NULL)) continue;	if ((ns == NULL) && (cur->prefix != NULL)) continue;	if ((!xmlStrcmp(cur->name, name)) && (!xmlStrcmp(cur->elem, elem)) &&	    ((ns == NULL) || (!xmlStrcmp(cur->prefix, ns)))) {	    /*	     * The attribute is already defined in this Dtd.	     */	    VWARNING(ctxt->userData, "Attribute %s on %s: already defined\n",		   elem, name);	}    }    /*     * Grow the table, if needed.     */    if (table->nb_attributes >= table->max_attributes) {        /*	 * need more attributes.	 */	table->max_attributes *= 2;	table->table = (xmlAttributePtr *) 	    xmlRealloc(table->table, table->max_attributes * 	            sizeof(xmlAttributePtr));	if (table->table == NULL) {	    fprintf(stderr, "xmlAddAttributeDecl: out of memory\n");	    return(NULL);	}    }    ret = (xmlAttributePtr) xmlMalloc(sizeof(xmlAttribute));    if (ret == NULL) {	fprintf(stderr, "xmlAddAttributeDecl: out of memory\n");	return(NULL);    }    memset(ret, 0, sizeof(xmlAttribute));    ret->type = XML_ATTRIBUTE_DECL;    table->table[table->nb_attributes] = ret;    /*     * fill the structure.     */    ret->atype = type;    ret->name = xmlStrdup(name);    ret->prefix = xmlStrdup(ns);    ret->elem = xmlStrdup(elem);    ret->def = def;    ret->tree = tree;    if (defaultValue != NULL)	ret->defaultValue = xmlStrdup(defaultValue);    elemDef = xmlGetDtdElementDesc(dtd, elem);    if (elemDef != NULL) {        if ((type == XML_ATTRIBUTE_ID) &&	    (xmlScanIDAttributeDecl(NULL, elemDef) != 0))	    VERROR(ctxt->userData, 	   "Element %s has too may ID attributes defined : %s\n",		   elem, name);        ret->nexth = elemDef->attributes;        elemDef->attributes = ret;

⌨️ 快捷键说明

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