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

📄 valid.c

📁 libxml,在UNIX/LINUX下非常重要的一个库,为XML相关应用提供方便.目前上载的是最新版本,若要取得最新版本,请参考里面的readme.
💻 C
📖 第 1 页 / 共 5 页
字号:
    if (elem == NULL) return(0);    cur = elem->attributes;    while (cur != NULL) {        if (cur->atype == XML_ATTRIBUTE_ID) {	    ret ++;	    if (ret > 1)		xmlErrValidNode(ctxt, (xmlNodePtr) elem, XML_DTD_MULTIPLE_ID,	       "Element %s has too many ID attributes defined : %s\n",		       elem->name, cur->name, NULL);	}	cur = cur->nexth;    }    return(ret);}#endif /* LIBXML_VALID_ENABLED *//** * xmlFreeAttribute: * @elem:  An attribute * * Deallocate the memory used by an attribute definition */static voidxmlFreeAttribute(xmlAttributePtr attr) {    xmlDictPtr dict;    if (attr == NULL) return;    if (attr->doc != NULL)	dict = attr->doc->dict;    else	dict = NULL;    xmlUnlinkNode((xmlNodePtr) attr);    if (attr->tree != NULL)        xmlFreeEnumeration(attr->tree);    if (dict) {        if ((attr->elem != NULL) && (!xmlDictOwns(dict, attr->elem)))	    xmlFree((xmlChar *) attr->elem);        if ((attr->name != NULL) && (!xmlDictOwns(dict, attr->name)))	    xmlFree((xmlChar *) attr->name);        if ((attr->prefix != NULL) && (!xmlDictOwns(dict, attr->prefix)))	    xmlFree((xmlChar *) attr->prefix);        if ((attr->defaultValue != NULL) &&	    (!xmlDictOwns(dict, attr->defaultValue)))	    xmlFree((xmlChar *) attr->defaultValue);    } else {	if (attr->elem != NULL)	    xmlFree((xmlChar *) attr->elem);	if (attr->name != NULL)	    xmlFree((xmlChar *) attr->name);	if (attr->defaultValue != NULL)	    xmlFree((xmlChar *) attr->defaultValue);	if (attr->prefix != NULL)	    xmlFree((xmlChar *) attr->prefix);    }    xmlFree(attr);}/** * 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 * Note that @tree becomes the ownership of the DTD * * Returns NULL if not new, otherwise the attribute decl */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;    xmlAttributeTablePtr table;    xmlElementPtr elemDef;    xmlDictPtr dict = NULL;    if (dtd == NULL) {	xmlFreeEnumeration(tree);	return(NULL);    }    if (name == NULL) {	xmlFreeEnumeration(tree);	return(NULL);    }    if (elem == NULL) {	xmlFreeEnumeration(tree);	return(NULL);    }    if (dtd->doc != NULL)	dict = dtd->doc->dict;#ifdef LIBXML_VALID_ENABLED    /*     * 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:	    xmlErrValid(ctxt, XML_ERR_INTERNAL_ERROR, 		    "Internal: ATTRIBUTE struct corrupted invalid type\n",		    NULL);	    xmlFreeEnumeration(tree);	    return(NULL);    }    if ((defaultValue != NULL) &&         (!xmlValidateAttributeValue(type, defaultValue))) {	xmlErrValidNode(ctxt, (xmlNodePtr) dtd, XML_DTD_ATTRIBUTE_DEFAULT,	                "Attribute %s of %s: invalid default value\n",	                elem, name, defaultValue);	defaultValue = NULL;	if (ctxt != NULL)	    ctxt->valid = 0;    }#endif /* LIBXML_VALID_ENABLED */    /*     * Check first that an attribute defined in the external subset wasn't     * already defined in the internal subset     */    if ((dtd->doc != NULL) && (dtd->doc->extSubset == dtd) &&	(dtd->doc->intSubset != NULL) &&	(dtd->doc->intSubset->attributes != NULL)) {        ret = xmlHashLookup3(dtd->doc->intSubset->attributes, name, ns, elem);	if (ret != NULL)	    return(NULL);    }    /*     * Create the Attribute table if needed.     */    table = (xmlAttributeTablePtr) dtd->attributes;    if (table == NULL) {        table = xmlHashCreateDict(0, dict);	dtd->attributes = (void *) table;    }    if (table == NULL) {	xmlVErrMemory(ctxt,            "xmlAddAttributeDecl: Table creation failed!\n");        return(NULL);    }    ret = (xmlAttributePtr) xmlMalloc(sizeof(xmlAttribute));    if (ret == NULL) {	xmlVErrMemory(ctxt, "malloc failed");	return(NULL);    }    memset(ret, 0, sizeof(xmlAttribute));    ret->type = XML_ATTRIBUTE_DECL;    /*     * fill the structure.     */    ret->atype = type;    if (dict) {	ret->name = xmlDictLookup(dict, name, -1);	ret->prefix = xmlDictLookup(dict, ns, -1);	ret->elem = xmlDictLookup(dict, elem, -1);    } else {	ret->name = xmlStrdup(name);	ret->prefix = xmlStrdup(ns);	ret->elem = xmlStrdup(elem);    }    ret->def = def;    ret->tree = tree;    if (defaultValue != NULL) {        if (dict)	    ret->defaultValue = xmlDictLookup(dict, defaultValue, -1);	else	    ret->defaultValue = xmlStrdup(defaultValue);    }    /*     * Validity Check:     * Search the DTD for previous declarations of the ATTLIST     */    if (xmlHashAddEntry3(table, ret->name, ret->prefix, ret->elem, ret) < 0) {#ifdef LIBXML_VALID_ENABLED	/*	 * The attribute is already defined in this DTD.	 */	xmlErrValidWarning(ctxt, (xmlNodePtr) dtd, XML_DTD_ATTRIBUTE_REDEFINED,		 "Attribute %s of element %s: already defined\n",		 name, elem, NULL);#endif /* LIBXML_VALID_ENABLED */	xmlFreeAttribute(ret);	return(NULL);    }    /*     * Validity Check:     * Multiple ID per element     */    elemDef = xmlGetDtdElementDesc2(dtd, elem, 1);    if (elemDef != NULL) {#ifdef LIBXML_VALID_ENABLED        if ((type == XML_ATTRIBUTE_ID) &&	    (xmlScanIDAttributeDecl(NULL, elemDef) != 0)) {	    xmlErrValidNode(ctxt, (xmlNodePtr) dtd, XML_DTD_MULTIPLE_ID,	   "Element %s has too may ID attributes defined : %s\n",		   elem, name, NULL);	    if (ctxt != NULL)		ctxt->valid = 0;	}#endif /* LIBXML_VALID_ENABLED */	/*	 * Insert namespace default def first they need to be	 * processed first.	 */	if ((xmlStrEqual(ret->name, BAD_CAST "xmlns")) ||	    ((ret->prefix != NULL &&	     (xmlStrEqual(ret->prefix, BAD_CAST "xmlns"))))) {	    ret->nexth = elemDef->attributes;	    elemDef->attributes = ret;	} else {	    xmlAttributePtr tmp = elemDef->attributes;	    while ((tmp != NULL) &&		   ((xmlStrEqual(tmp->name, BAD_CAST "xmlns")) ||		    ((ret->prefix != NULL &&		     (xmlStrEqual(ret->prefix, BAD_CAST "xmlns")))))) {		if (tmp->nexth == NULL)		    break;		tmp = tmp->nexth;	    }	    if (tmp != NULL) {		ret->nexth = tmp->nexth;	        tmp->nexth = ret;	    } else {		ret->nexth = elemDef->attributes;		elemDef->attributes = ret;	    }	}    }    /*     * 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);}/** * xmlFreeAttributeTable: * @table:  An attribute table * * Deallocate the memory used by an entities hash table. */voidxmlFreeAttributeTable(xmlAttributeTablePtr table) {    xmlHashFree(table, (xmlHashDeallocator) xmlFreeAttribute);}#ifdef LIBXML_TREE_ENABLED/** * xmlCopyAttribute: * @attr:  An attribute * * Build a copy of an attribute. *  * Returns the new xmlAttributePtr or NULL in case of error. */static xmlAttributePtrxmlCopyAttribute(xmlAttributePtr attr) {    xmlAttributePtr cur;    cur = (xmlAttributePtr) xmlMalloc(sizeof(xmlAttribute));    if (cur == NULL) {	xmlVErrMemory(NULL, "malloc failed");	return(NULL);    }    memset(cur, 0, sizeof(xmlAttribute));    cur->type = XML_ATTRIBUTE_DECL;    cur->atype = attr->atype;    cur->def = attr->def;    cur->tree = xmlCopyEnumeration(attr->tree);    if (attr->elem != NULL)	cur->elem = xmlStrdup(attr->elem);    if (attr->name != NULL)	cur->name = xmlStrdup(attr->name);    if (attr->prefix != NULL)	cur->prefix = xmlStrdup(attr->prefix);    if (attr->defaultValue != NULL)	cur->defaultValue = xmlStrdup(attr->defaultValue);    return(cur);}/** * xmlCopyAttributeTable: * @table:  An attribute table * * Build a copy of an attribute table. *  * Returns the new xmlAttributeTablePtr or NULL in case of error. */xmlAttributeTablePtrxmlCopyAttributeTable(xmlAttributeTablePtr table) {    return((xmlAttributeTablePtr) xmlHashCopy(table,				    (xmlHashCopier) xmlCopyAttribute));}#endif /* LIBXML_TREE_ENABLED */#ifdef LIBXML_OUTPUT_ENABLED/** * xmlDumpAttributeDecl: * @buf:  the XML buffer output * @attr:  An attribute declaration * * This will dump the content of the attribute declaration as an XML * DTD definition */voidxmlDumpAttributeDecl(xmlBufferPtr buf, xmlAttributePtr attr) {    if ((buf == NULL) || (attr == NULL))        return;    xmlBufferWriteChar(buf, "<!ATTLIST ");    xmlBufferWriteCHAR(buf, attr->elem);    xmlBufferWriteChar(buf, " ");    if (attr->prefix != NULL) {	xmlBufferWriteCHAR(buf, attr->prefix);	xmlBufferWriteChar(buf, ":");    }    xmlBufferWriteCHAR(buf, attr->name);    switch (attr->atype) {	case XML_ATTRIBUTE_CDATA:	    xmlBufferWriteChar(buf, " CDATA");	    break;	case XML_ATTRIBUTE_ID:	    xmlBufferWriteChar(buf, " ID");	    break;	case XML_ATTRIBUTE_IDREF:	    xmlBufferWriteChar(buf, " IDREF");	    break;	case XML_ATTRIBUTE_IDREFS:	    xmlBufferWriteChar(buf, " IDREFS");	    break;	case XML_ATTRIBUTE_ENTITY:	    xmlBufferWriteChar(buf, " ENTITY");	    break;	case XML_ATTRIBUTE_ENTITIES:	    xmlBufferWriteChar(buf, " ENTITIES");	    break;	case XML_ATTRIBUTE_NMTOKEN:	    xmlBufferWriteChar(buf, " NMTOKEN");	    break;	case XML_ATTRIBUTE_NMTOKENS:	    xmlBufferWriteChar(buf, " NMTOKENS");	    break;	case XML_ATTRIBUTE_ENUMERATION:	    xmlBufferWriteChar(buf, " (");	    xmlDumpEnumeration(buf, attr->tree);	    break;	case XML_ATTRIBUTE_NOTATION:	    xmlBufferWriteChar(buf, " NOTATION (");	    xmlDumpEnumeration(buf, attr->tree);	    break;	default:	    xmlErrValid(NULL, XML_ERR_INTERNAL_ERROR, 		    "Internal: ATTRIBUTE struct corrupted invalid type\n",		    NULL);    }    switch (attr->def) {	case XML_ATTRIBUTE_NONE:	    break;	case XML_ATTRIBUTE_REQUIRED:	    xmlBufferWriteChar(buf, " #REQUIRED");	    break;	case XML_ATTRIBUTE_IMPLIED:	    xmlBufferWriteChar(buf, " #IMPLIED");	    break;	case XML_ATTRIBUTE_FIXED:	    xmlBufferWriteChar(buf, " #FIXED");	    break;	default:	    xmlErrValid(NULL, XML_ERR_INTERNAL_ERROR, 		    "Internal: ATTRIBUTE struct corrupted invalid def\n",		    NULL);    }    if (attr->defaultValue != NULL) {	xmlBufferWriteChar(buf, " ");	xmlBufferWriteQuotedString(buf, attr->defaultValue);    }    xmlBufferWriteChar(buf, ">\n");}/** * xmlDumpAttributeDeclScan: * @attr:  An attribute declaration * @buf:  the XML buffer output * * This is used with the hash scan function - just reverses arguments */static voidxmlDumpAttributeDeclScan(xmlAttributePtr attr, xmlBufferPtr buf) {    xmlDumpAttributeDecl(buf, attr);}/** * xmlDumpAttributeTable: * @buf:  the XML buffer output * @table:  An attribute table * * This will dump the content of the attribute table as an XML DTD definition */voidxmlDumpAttributeTable(xmlBufferPtr buf, xmlAttributeTablePtr table) {    if ((buf == NULL) || (table == NULL))        return;    xmlHashScan(table, (xmlHashScanner) xmlDumpAttributeDeclScan, buf);}#endif /* LIBXML_OUTPUT_ENABLED *//************************************************************************ *									* *				NOTATIONs				* *									* ************************************************************************//** * xmlFreeNotation: * @not:  A notation * * Deallocate the memory used by an notation definition */static voidxmlFreeNotation(xmlNotationPtr nota) {    if (nota == NULL) return;    if (nota->name != NULL)	xmlFree((xmlChar *) nota->name);    if (nota->PublicID != NU

⌨️ 快捷键说明

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