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

📄 valid.c.svn-base

📁 这是一个用于解析xml文件的类库。使用这个类库
💻 SVN-BASE
📖 第 1 页 / 共 5 页
字号:
    /*     * 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);	    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) {    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) {    xmlHashScan(table, (xmlHashScanner) xmlDumpAttributeDeclScan, buf);}#endif /* LIBXML_OUTPUT_ENABLED *//************************************************************************ *									* *				NOTATIONs				* *									* ************************************************************************//** * xmlCreateNotationTable: * * create and initialize an empty notation hash table. * * Returns the xmlNotationTablePtr just created or NULL in case *                of error. */static xmlNotationTablePtrxmlCreateNotationTable(void) {    return(xmlHashCreate(0));}/** * 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 != NULL)	xmlFree((xmlChar *) nota->PublicID);    if (nota->SystemID != NULL)	xmlFree((xmlChar *) nota->SystemID);    xmlFree(nota);}/** * xmlAddNotationDecl: * @dtd:  pointer to the DTD * @ctxt:  the validation context * @name:  the entity name * @PublicID:  the public identifier or NULL * @SystemID:  the system identifier or NULL * * Register a new notation declaration * * Returns NULL if not, otherwise the entity */xmlNotationPtrxmlAddNotationDecl(xmlValidCtxtPtr ctxt, xmlDtdPtr dtd,	           const xmlChar *name,                   const xmlChar *PublicID, const xmlChar *SystemID) {    xmlNotationPtr ret;    xmlNotationTablePtr table;    if (dtd == NULL) {	return(NULL);    }    if (name == NULL) {	return(NULL);    }    if ((PublicID == NULL) && (SystemID == NULL)) {	return(NULL);    }    /*     * Create the Notation table if needed.     */    table = (xmlNotationTablePtr) dtd->notations;    if (table == NULL)         dtd->notations = table = xmlCreateNotationTable();    if (table == NULL) {	xmlVErrMemory(ctxt,		"xmlAddNotationDecl: Table creation failed!\n");        return(NULL);    }    ret = (xmlNotationPtr) xmlMalloc(sizeof(xmlNotation));    if (ret == NULL) {	xmlVErrMemory(ctxt, "malloc failed");	return(NULL);    }    memset(ret, 0, sizeof(xmlNotation));    /*     * fill the structure.     */    ret->name = xmlStrdup(name);    if (SystemID != NULL)        ret->SystemID = xmlStrdup(SystemID);    if (PublicID != NULL)        ret->PublicID = xmlStrdup(PublicID);    /*     * Validity Check:     * Check the DTD for previous declarations of the ATTLIST     */    if (xmlHashAddEntry(table, name, ret)) {#ifdef LIBXML_VALID_ENABLED	xmlErrValid(NULL, XML_DTD_NOTATION_REDEFINED, 		    "xmlAddNotationDecl: %s already defined\n",		    (const char *) name);#endif /* LIBXML_VALID_ENABLED */	xmlFreeNotation(ret);	return(NULL);    }    return(ret);}/** * xmlFreeNotationTable: * @table:  An notation table * * Deallocate the memory used by an entities hash table. */voidxmlFreeNotationTable(xmlNotationTablePtr table) {    xmlHashFree(table, (xmlHashDeallocator) xmlFreeNotation);}#ifdef LIBXML_TREE_ENABLED/** * xmlCopyNotation: * @nota:  A notation * * Build a copy of a notation. *  * Returns the new xmlNotationPtr or NULL in case of error. */static xmlNotationPtrxmlCopyNotation(xmlNotationPtr nota) {    xmlNotationPtr cur;    cur = (xmlNotationPtr) xmlMalloc(sizeof(xmlNotation));    if (cur == NULL) {	xmlVErrMemory(NULL, "malloc failed");	return(NULL);    }    if (nota->name != NULL)	cur->name = xmlStrdup(nota->name);    else	cur->name = NULL;    if (nota->PublicID != NULL)	cur->PublicID = xmlStrdup(nota->PublicID);    else	cur->PublicID = NULL;    if (nota->SystemID != NULL)	cur->SystemID = xmlStrdup(nota->SystemID);    else	cur->SystemID = NULL;    return(cur);}/** * xmlCopyNotationTable: * @table:  A notation table * * Build a copy of a notation table. *  * Returns the new xmlNotationTablePtr or NULL in case of error. */xmlNotationTablePtrxmlCopyNotationTable(xmlNotationTablePtr table) {    return((xmlNotationTablePtr) xmlHashCopy(table,				    (xmlHashCopier) xmlCopyNotation));}#endif /* LIBXML_TREE_ENABLED */#ifdef LIBXML_OUTPUT_ENABLED/** * xmlDumpNotationDecl: * @buf:  the XML buffer output * @nota:  A notation declaration * * This will dump the content the notation declaration as an XML DTD definition */voidxmlDumpNotationDecl(xmlBufferPtr buf, xmlNotationPtr nota) {    xmlBufferWriteChar(buf, "<!NOTATION ");    xmlBufferWriteCHAR(buf, nota->name);    if (nota->PublicID != NULL) {	xmlBufferWriteChar(buf, " PUBLIC ");	xmlBufferWriteQuotedString(buf, nota->PublicID);	if (nota->SystemID != NULL) {	    xmlBufferWriteChar(buf, " ");	    xmlBufferWriteCHAR(buf, nota->SystemID);	}    } else {	xmlBufferWriteChar(buf, " SYSTEM ");	xmlBufferWriteCHAR(buf, nota->SystemID);    }    xmlBufferWriteChar(buf, " >\n");}/** * xmlDumpNotationDeclScan: * @nota:  A notation declaration * @buf:  the XML buffer output * * This is called with the hash scan function, and just reverses args */static voidxmlDumpNotationDeclScan(xmlNotationPtr nota, xmlBufferPtr buf) {    xmlDumpNotationDecl(buf, nota);}/** * xmlDumpNotationTable: * @buf:  the XML buffer output * @table:  A notation table * * This will dump the content of the notation table as an XML DTD definition */voidxmlDumpNotationTable(xmlBufferPtr buf, xmlNotationTablePtr table) {    xmlHashScan(table, (xmlHashScanner) xmlDumpNotationDeclScan, buf);}#endif /* LIBXML_OUTPUT_ENABLED *//************************************************************************ *									* *				IDs					* *									* ************************************************************************//** * DICT_FREE: * @str:  a string * * Free a string if it is not owned by the "dict" dictionnary in the * current scope */#define DICT_FREE(str)						\	if ((str) && ((!dict) || 				\	    (xmlDictOwns(dict, (const xmlChar *)(str)) == 0)))	\	    xmlFree((char *)(str));/** * xmlCreateIDTable: * * create and initialize an empty id hash table. * * Returns the xmlIDTablePtr just created or NULL in case *                of error. */static xmlIDTablePtrxmlCreateIDTable(void) {    return(xmlHashCr

⌨️ 快捷键说明

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