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

📄 valid.c.svn-base

📁 这是一个用于解析xml文件的类库。使用这个类库
💻 SVN-BASE
📖 第 1 页 / 共 5 页
字号:
/** * xmlFreeElementContent: * @cur:  the element content tree to free * * Free an element content structure. This is a recursive call ! */voidxmlFreeElementContent(xmlElementContentPtr cur) {    if (cur == NULL) return;    switch (cur->type) {	case XML_ELEMENT_CONTENT_PCDATA:	case XML_ELEMENT_CONTENT_ELEMENT:	case XML_ELEMENT_CONTENT_SEQ:	case XML_ELEMENT_CONTENT_OR:	    break;	default:	    xmlErrValid(NULL, XML_ERR_INTERNAL_ERROR, 		    "Internal: ELEMENT content corrupted invalid type\n",		    NULL);	    return;    }    if (cur->c1 != NULL) xmlFreeElementContent(cur->c1);    if (cur->c2 != NULL) xmlFreeElementContent(cur->c2);    if (cur->name != NULL) xmlFree((xmlChar *) cur->name);    if (cur->prefix != NULL) xmlFree((xmlChar *) cur->prefix);    xmlFree(cur);}#ifdef LIBXML_OUTPUT_ENABLED/** * xmlDumpElementContent: * @buf:  An XML buffer * @content:  An element table * @glob: 1 if one must print the englobing parenthesis, 0 otherwise * * This will dump the content of the element table as an XML DTD definition */static voidxmlDumpElementContent(xmlBufferPtr buf, xmlElementContentPtr content, int glob) {    if (content == NULL) return;    if (glob) xmlBufferWriteChar(buf, "(");    switch (content->type) {        case XML_ELEMENT_CONTENT_PCDATA:            xmlBufferWriteChar(buf, "#PCDATA");	    break;	case XML_ELEMENT_CONTENT_ELEMENT:	    if (content->prefix != NULL) {		xmlBufferWriteCHAR(buf, content->prefix);		xmlBufferWriteChar(buf, ":");	    }	    xmlBufferWriteCHAR(buf, content->name);	    break;	case XML_ELEMENT_CONTENT_SEQ:	    if ((content->c1->type == XML_ELEMENT_CONTENT_OR) ||	        (content->c1->type == XML_ELEMENT_CONTENT_SEQ))		xmlDumpElementContent(buf, content->c1, 1);	    else		xmlDumpElementContent(buf, content->c1, 0);            xmlBufferWriteChar(buf, " , ");	    if (content->c2->type == XML_ELEMENT_CONTENT_OR)		xmlDumpElementContent(buf, content->c2, 1);	    else		xmlDumpElementContent(buf, content->c2, 0);	    break;	case XML_ELEMENT_CONTENT_OR:	    if ((content->c1->type == XML_ELEMENT_CONTENT_OR) ||	        (content->c1->type == XML_ELEMENT_CONTENT_SEQ))		xmlDumpElementContent(buf, content->c1, 1);	    else		xmlDumpElementContent(buf, content->c1, 0);            xmlBufferWriteChar(buf, " | ");	    if (content->c2->type == XML_ELEMENT_CONTENT_SEQ)		xmlDumpElementContent(buf, content->c2, 1);	    else		xmlDumpElementContent(buf, content->c2, 0);	    break;	default:	    xmlErrValid(NULL, XML_ERR_INTERNAL_ERROR, 		    "Internal: ELEMENT content corrupted invalid type\n",		    NULL);    }    if (glob)        xmlBufferWriteChar(buf, ")");    switch (content->ocur) {        case XML_ELEMENT_CONTENT_ONCE:	    break;        case XML_ELEMENT_CONTENT_OPT:	    xmlBufferWriteChar(buf, "?");	    break;        case XML_ELEMENT_CONTENT_MULT:	    xmlBufferWriteChar(buf, "*");	    break;        case XML_ELEMENT_CONTENT_PLUS:	    xmlBufferWriteChar(buf, "+");	    break;    }}/** * xmlSprintfElementContent: * @buf:  an output buffer * @content:  An element table * @glob: 1 if one must print the englobing parenthesis, 0 otherwise * * Deprecated, unsafe, use xml_snprintfElementContent */voidxmlSprintfElementContent(char *buf ATTRIBUTE_UNUSED,	                 xmlElementContentPtr content ATTRIBUTE_UNUSED,			 int glob ATTRIBUTE_UNUSED) {}#endif /* LIBXML_OUTPUT_ENABLED *//** * xml_snprintfElementContent: * @buf:  an output buffer * @size:  the buffer size * @content:  An element table * @glob: 1 if one must print the englobing parenthesis, 0 otherwise * * This will dump the content of the element content definition * Intended just for the debug routine */voidxml_snprintfElementContent(char *buf, int size, xmlElementContentPtr content, int glob) {    int len;    if (content == NULL) return;    len = strlen(buf);    if (size - len < 50) {	if ((size - len > 4) && (buf[len - 1] != '.'))	    strcat(buf, " ...");	return;    }    if (glob) strcat(buf, "(");    switch (content->type) {        case XML_ELEMENT_CONTENT_PCDATA:            strcat(buf, "#PCDATA");	    break;	case XML_ELEMENT_CONTENT_ELEMENT:	    if (content->prefix != NULL) {		if (size - len < xmlStrlen(content->prefix) + 10) {		    strcat(buf, " ...");		    return;		}		strcat(buf, (char *) content->prefix);		strcat(buf, ":");	    }	    if (size - len < xmlStrlen(content->name) + 10) {		strcat(buf, " ...");		return;	    }	    if (content->name != NULL)		strcat(buf, (char *) content->name);	    break;	case XML_ELEMENT_CONTENT_SEQ:	    if ((content->c1->type == XML_ELEMENT_CONTENT_OR) ||	        (content->c1->type == XML_ELEMENT_CONTENT_SEQ))		xml_snprintfElementContent(buf, size, content->c1, 1);	    else		xml_snprintfElementContent(buf, size, content->c1, 0);	    len = strlen(buf);	    if (size - len < 50) {		if ((size - len > 4) && (buf[len - 1] != '.'))		    strcat(buf, " ...");		return;	    }            strcat(buf, " , ");	    if (((content->c2->type == XML_ELEMENT_CONTENT_OR) ||		 (content->c2->ocur != XML_ELEMENT_CONTENT_ONCE)) &&		(content->c2->type != XML_ELEMENT_CONTENT_ELEMENT))		xml_snprintfElementContent(buf, size, content->c2, 1);	    else		xml_snprintfElementContent(buf, size, content->c2, 0);	    break;	case XML_ELEMENT_CONTENT_OR:	    if ((content->c1->type == XML_ELEMENT_CONTENT_OR) ||	        (content->c1->type == XML_ELEMENT_CONTENT_SEQ))		xml_snprintfElementContent(buf, size, content->c1, 1);	    else		xml_snprintfElementContent(buf, size, content->c1, 0);	    len = strlen(buf);	    if (size - len < 50) {		if ((size - len > 4) && (buf[len - 1] != '.'))		    strcat(buf, " ...");		return;	    }            strcat(buf, " | ");	    if (((content->c2->type == XML_ELEMENT_CONTENT_SEQ) ||		 (content->c2->ocur != XML_ELEMENT_CONTENT_ONCE)) &&		(content->c2->type != XML_ELEMENT_CONTENT_ELEMENT))		xml_snprintfElementContent(buf, size, content->c2, 1);	    else		xml_snprintfElementContent(buf, size, content->c2, 0);	    break;    }    if (glob)        strcat(buf, ")");    switch (content->ocur) {        case XML_ELEMENT_CONTENT_ONCE:	    break;        case XML_ELEMENT_CONTENT_OPT:	    strcat(buf, "?");	    break;        case XML_ELEMENT_CONTENT_MULT:	    strcat(buf, "*");	    break;        case XML_ELEMENT_CONTENT_PLUS:	    strcat(buf, "+");	    break;    }}/**************************************************************** *								* *	Registration of DTD declarations			* *								* ****************************************************************//** * xmlCreateElementTable: * * create and initialize an empty element hash table. * * Returns the xmlElementTablePtr just created or NULL in case of error. */static xmlElementTablePtrxmlCreateElementTable(void) {    return(xmlHashCreate(0));}/** * xmlFreeElement: * @elem:  An element * * Deallocate the memory used by an element definition */static voidxmlFreeElement(xmlElementPtr elem) {    if (elem == NULL) return;    xmlUnlinkNode((xmlNodePtr) elem);    xmlFreeElementContent(elem->content);    if (elem->name != NULL)	xmlFree((xmlChar *) elem->name);    if (elem->prefix != NULL)	xmlFree((xmlChar *) elem->prefix);#ifdef LIBXML_REGEXP_ENABLED    if (elem->contModel != NULL)	xmlRegFreeRegexp(elem->contModel);#endif    xmlFree(elem);}/** * xmlAddElementDecl: * @ctxt:  the validation context * @dtd:  pointer to the DTD * @name:  the entity name * @type:  the element type * @content:  the element content tree or NULL * * Register a new element declaration * * Returns NULL if not, otherwise the entity */xmlElementPtrxmlAddElementDecl(xmlValidCtxtPtr ctxt,                  xmlDtdPtr dtd, const xmlChar *name,                  xmlElementTypeVal type,		  xmlElementContentPtr content) {    xmlElementPtr ret;    xmlElementTablePtr table;    xmlAttributePtr oldAttributes = NULL;    xmlChar *ns, *uqname;    if (dtd == NULL) {	return(NULL);    }    if (name == NULL) {	return(NULL);    }    switch (type) {        case XML_ELEMENT_TYPE_EMPTY:	    if (content != NULL) {		xmlErrValid(ctxt, XML_ERR_INTERNAL_ERROR, 		        "xmlAddElementDecl: content != NULL for EMPTY\n",			NULL);		return(NULL);	    }	    break;	case XML_ELEMENT_TYPE_ANY:	    if (content != NULL) {		xmlErrValid(ctxt, XML_ERR_INTERNAL_ERROR, 		        "xmlAddElementDecl: content != NULL for ANY\n",			NULL);		return(NULL);	    }	    break;	case XML_ELEMENT_TYPE_MIXED:	    if (content == NULL) {		xmlErrValid(ctxt, XML_ERR_INTERNAL_ERROR, 		        "xmlAddElementDecl: content == NULL for MIXED\n",			NULL);		return(NULL);	    }	    break;	case XML_ELEMENT_TYPE_ELEMENT:	    if (content == NULL) {		xmlErrValid(ctxt, XML_ERR_INTERNAL_ERROR, 		        "xmlAddElementDecl: content == NULL for ELEMENT\n",			NULL);		return(NULL);	    }	    break;	default:	    xmlErrValid(ctxt, XML_ERR_INTERNAL_ERROR, 		    "Internal: ELEMENT decl corrupted invalid type\n",		    NULL);	    return(NULL);    }    /*     * check if name is a QName     */    uqname = xmlSplitQName2(name, &ns);    if (uqname != NULL)	name = uqname;    /*     * Create the Element table if needed.     */    table = (xmlElementTablePtr) dtd->elements;    if (table == NULL) {        table = xmlCreateElementTable();	dtd->elements = (void *) table;    }    if (table == NULL) {	xmlVErrMemory(ctxt,            "xmlAddElementDecl: Table creation failed!\n");	if (uqname != NULL)	    xmlFree(uqname);	if (ns != NULL)	    xmlFree(ns);        return(NULL);    }    /*     * lookup old attributes inserted on an undefined element in the     * internal subset.     */    if ((dtd->doc != NULL) && (dtd->doc->intSubset != NULL)) {	ret = xmlHashLookup2(dtd->doc->intSubset->elements, name, ns);	if ((ret != NULL) && (ret->etype == XML_ELEMENT_TYPE_UNDEFINED)) {	    oldAttributes = ret->attributes;	    ret->attributes = NULL;	    xmlHashRemoveEntry2(dtd->doc->intSubset->elements, name, ns, NULL);	    xmlFreeElement(ret);	}    }    /*     * The element may already be present if one of its attribute     * was registered first     */    ret = xmlHashLookup2(table, name, ns);    if (ret != NULL) {	if (ret->etype != XML_ELEMENT_TYPE_UNDEFINED) {#ifdef LIBXML_VALID_ENABLED	    /*	     * The element is already defined in this DTD.	     */	    xmlErrValidNode(ctxt, (xmlNodePtr) dtd, XML_DTD_ELEM_REDEFINED,	                    "Redefinition of element %s\n",			    name, NULL, NULL);#endif /* LIBXML_VALID_ENABLED */	    if (uqname != NULL)		xmlFree(uqname);            if (ns != NULL)	        xmlFree(ns);	    return(NULL);	}    } else {	ret = (xmlElementPtr) xmlMalloc(sizeof(xmlElement));	if (ret == NULL) {	    xmlVErrMemory(ctxt, "malloc failed");	    if (uqname != NULL)		xmlFree(uqname);            if (ns != NULL)	        xmlFree(ns);	    return(NULL);	}	memset(ret, 0, sizeof(xmlElement));	ret->type = XML_ELEMENT_DECL;	/*	 * fill the structure.	 */	ret->name = xmlStrdup(name);	if (ret->name == NULL) {	    xmlVErrMemory(ctxt, "malloc failed");	    if (uqname != NULL)		xmlFree(uqname);            if (ns != NULL)	        xmlFree(ns);	    xmlFree(ret);	    return(NULL);	}	ret->prefix = ns;	/*	 * Validity Check:	 * Insertion must not fail	 */	if (xmlHashAddEntry2(table, name, ns, ret)) {#ifdef LIBXML_VALID_ENABLED	    /*	     * The element is already defined in this DTD.	     */	    xmlErrValidNode(ctxt, (xmlNodePtr) dtd, XML_DTD_ELEM_REDEFINED,	                    "Redefinition of element %s\n",			    name, NULL, NULL);#endif /* LIBXML_VALID_ENABLED */	    xmlFreeElement(ret);	    if (uqname != NULL)		xmlFree(uqname);	    return(NULL);	}	/*	 * For new element, may have attributes from earlier	 * definition in internal subset	 */	ret->attributes = oldAttributes;    }    /*     * Finish to fill the structure.     */    ret->etype = type;    ret->content = xmlCopyElementContent(content);    /*     * 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;    }    if (uqname != NULL)	xmlFree(uqname);    return(ret);}/** * xmlFreeElementTable: * @table:  An element table * * Deallocate the memory used by an element hash table. */voidxmlFreeElementTable(xmlElementTablePtr table) {    xmlHashFree(table, (xmlHashDeallocator) xmlFreeElement);}#ifdef LIBXML_TREE_ENABLED/** * xmlCopyElement: * @elem:  An element * * Build a copy of an element. * 

⌨️ 快捷键说明

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