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

📄 sax2.c.svn-base

📁 这是一个用于解析xml文件的类库。使用这个类库
💻 SVN-BASE
📖 第 1 页 / 共 5 页
字号:
     */    name = xmlSplitQName(ctxt, fullname, &ns);    if ((name != NULL) && (name[0] == 0)) {        if (xmlStrEqual(ns, BAD_CAST "xmlns")) {	    if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))		ctxt->sax->error(ctxt->userData, 		     "invalid namespace declaration '%s'\n", fullname);	} else {	    if ((ctxt->sax != NULL) && (ctxt->sax->warning != NULL))		ctxt->sax->warning(ctxt->userData, 		     "Avoid attribute ending with ':' like '%s'\n", fullname);	}	if (ns != NULL)	    xmlFree(ns);	ns = NULL;	xmlFree(name);	name = xmlStrdup(fullname);    }    if (name == NULL) {	if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))	    ctxt->sax->error(ctxt->userData, 		 "SAX.xmlSAX2StartElement(): out of memory\n");	ctxt->errNo = XML_ERR_NO_MEMORY;	ctxt->instate = XML_PARSER_EOF;	ctxt->disableSAX = 1;	if (ns != NULL)	    xmlFree(ns);	return;    }#ifdef LIBXML_VALID_ENABLED    /*     * Do the last stage of the attribute normalization     * Needed for HTML too:     *   http://www.w3.org/TR/html4/types.html#h-6.2     */    ctxt->vctxt.valid = 1;    nval = xmlValidCtxtNormalizeAttributeValue(&ctxt->vctxt,	                                   ctxt->myDoc, ctxt->node,					   fullname, value);    if (ctxt->vctxt.valid != 1) {	ctxt->valid = 0;    }    if (nval != NULL)	value = nval;#else    nval = NULL;#endif /* LIBXML_VALID_ENABLED */    /*     * Check whether it's a namespace definition     */    if ((!ctxt->html) && (ns == NULL) &&        (name[0] == 'x') && (name[1] == 'm') && (name[2] == 'l') &&        (name[3] == 'n') && (name[4] == 's') && (name[5] == 0)) {	xmlNsPtr nsret;	xmlChar *val;        if (!ctxt->replaceEntities) {	    ctxt->depth++;	    val = xmlStringDecodeEntities(ctxt, value, XML_SUBSTITUTE_REF,		                          0,0,0);	    ctxt->depth--;	} else {	    val = (xmlChar *) value;	}	if (val[0] != 0) {	    xmlURIPtr uri;	    uri = xmlParseURI((const char *)val);	    if (uri == NULL) {		if ((ctxt->sax != NULL) && (ctxt->sax->warning != NULL))		    ctxt->sax->warning(ctxt->userData, 			 "xmlns: %s not a valid URI\n", val);	    } else {		if (uri->scheme == NULL) {		    if ((ctxt->sax != NULL) && (ctxt->sax->warning != NULL))			ctxt->sax->warning(ctxt->userData, 			     "xmlns: URI %s is not absolute\n", val);		}		xmlFreeURI(uri);	    }	}	/* a default namespace definition */	nsret = xmlNewNs(ctxt->node, val, NULL);#ifdef LIBXML_VALID_ENABLED	/*	 * Validate also for namespace decls, they are attributes from	 * an XML-1.0 perspective	 */        if (nsret != NULL && ctxt->validate && ctxt->wellFormed &&	    ctxt->myDoc && ctxt->myDoc->intSubset)	    ctxt->valid &= xmlValidateOneNamespace(&ctxt->vctxt, ctxt->myDoc,					   ctxt->node, prefix, nsret, val);#endif /* LIBXML_VALID_ENABLED */	if (name != NULL) 	    xmlFree(name);	if (nval != NULL)	    xmlFree(nval);	if (val != value)	    xmlFree(val);	return;    }    if ((!ctxt->html) &&	(ns != NULL) && (ns[0] == 'x') && (ns[1] == 'm') && (ns[2] == 'l') &&        (ns[3] == 'n') && (ns[4] == 's') && (ns[5] == 0)) {	xmlNsPtr nsret;	xmlChar *val;        if (!ctxt->replaceEntities) {	    ctxt->depth++;	    val = xmlStringDecodeEntities(ctxt, value, XML_SUBSTITUTE_REF,		                          0,0,0);	    ctxt->depth--;	    if (val == NULL) {		if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))		    ctxt->sax->error(ctxt->userData, 			 "SAX.xmlSAX2StartElement(): out of memory\n");		ctxt->errNo = XML_ERR_NO_MEMORY;		ctxt->instate = XML_PARSER_EOF;		ctxt->disableSAX = 1;	        xmlFree(ns);		if (name != NULL) 		    xmlFree(name);		return;	    }	} else {	    val = (xmlChar *) value;	}	if (val[0] == 0) {	    if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))		ctxt->sax->error(ctxt->userData, 		     "Empty namespace name for prefix %s\n", name);	}	if ((ctxt->pedantic != 0) && (val[0] != 0)) {	    xmlURIPtr uri;	    uri = xmlParseURI((const char *)val);	    if (uri == NULL) {		if ((ctxt->sax != NULL) && (ctxt->sax->warning != NULL))		    ctxt->sax->warning(ctxt->userData, 			 "xmlns:%s: %s not a valid URI\n", name, value);	    } else {		if (uri->scheme == NULL) {		    if ((ctxt->sax != NULL) && (ctxt->sax->warning != NULL))			ctxt->sax->warning(ctxt->userData, 			   "xmlns:%s: URI %s is not absolute\n", name, value);		}		xmlFreeURI(uri);	    }	}	/* a standard namespace definition */	nsret = xmlNewNs(ctxt->node, val, name);	xmlFree(ns);#ifdef LIBXML_VALID_ENABLED	/*	 * Validate also for namespace decls, they are attributes from	 * an XML-1.0 perspective	 */        if (nsret != NULL && ctxt->validate && ctxt->wellFormed &&	    ctxt->myDoc && ctxt->myDoc->intSubset)	    ctxt->valid &= xmlValidateOneNamespace(&ctxt->vctxt, ctxt->myDoc,					   ctxt->node, prefix, nsret, value);#endif /* LIBXML_VALID_ENABLED */	if (name != NULL) 	    xmlFree(name);	if (nval != NULL)	    xmlFree(nval);	if (val != value)	    xmlFree(val);	return;    }    if (ns != NULL) {	xmlAttrPtr prop;	namespace = xmlSearchNs(ctxt->myDoc, ctxt->node, ns);	if (namespace == NULL) {	    if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))		ctxt->sax->error(ctxt->userData, 		    "Namespace prefix %s of attribute %s is not defined\n",		             ns, name);	}	prop = ctxt->node->properties;	while (prop != NULL) {	    if (prop->ns != NULL) {		if ((xmlStrEqual(name, prop->name)) &&		    ((namespace == prop->ns) ||		     (xmlStrEqual(namespace->href, prop->ns->href)))) {		    ctxt->errNo = XML_ERR_ATTRIBUTE_REDEFINED;		    if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))			ctxt->sax->error(ctxt->userData,			        "Attribute %s in %s redefined\n",			                 name, namespace->href);		    ctxt->wellFormed = 0;		    if (ctxt->recovery == 0) ctxt->disableSAX = 1;		    goto error;		}	    }	    prop = prop->next;	}    } else {	namespace = NULL;    }    /* !!!!!! <a toto:arg="" xmlns:toto="http://toto.com"> */    ret = xmlNewNsPropEatName(ctxt->node, namespace, name, NULL);    if (ret != NULL) {        if ((ctxt->replaceEntities == 0) && (!ctxt->html)) {	    xmlNodePtr tmp;	    ret->children = xmlStringGetNodeList(ctxt->myDoc, value);	    tmp = ret->children;	    while (tmp != NULL) {		tmp->parent = (xmlNodePtr) ret;		if (tmp->next == NULL)		    ret->last = tmp;		tmp = tmp->next;	    }	} else if (value != NULL) {	    ret->children = xmlNewDocText(ctxt->myDoc, value);	    ret->last = ret->children;	    if (ret->children != NULL)		ret->children->parent = (xmlNodePtr) ret;	}    }#ifdef LIBXML_VALID_ENABLED    if ((!ctxt->html) && ctxt->validate && ctxt->wellFormed &&        ctxt->myDoc && ctxt->myDoc->intSubset) {		/*	 * If we don't substitute entities, the validation should be	 * done on a value with replaced entities anyway.	 */        if (!ctxt->replaceEntities) {	    xmlChar *val;	    ctxt->depth++;	    val = xmlStringDecodeEntities(ctxt, value, XML_SUBSTITUTE_REF,		                          0,0,0);	    ctxt->depth--;	    	    if (val == NULL)		ctxt->valid &= xmlValidateOneAttribute(&ctxt->vctxt,				ctxt->myDoc, ctxt->node, ret, value);	    else {		xmlChar *nvalnorm;		/*		 * Do the last stage of the attribute normalization		 * It need to be done twice ... it's an extra burden related		 * to the ability to keep xmlSAX2References in attributes		 */		nvalnorm = xmlValidNormalizeAttributeValue(ctxt->myDoc,					    ctxt->node, fullname, val);		if (nvalnorm != NULL) {		    xmlFree(val);		    val = nvalnorm;		}		ctxt->valid &= xmlValidateOneAttribute(&ctxt->vctxt,			        ctxt->myDoc, ctxt->node, ret, val);                xmlFree(val);	    }	} else {	    ctxt->valid &= xmlValidateOneAttribute(&ctxt->vctxt, ctxt->myDoc,					       ctxt->node, ret, value);	}    } else#endif /* LIBXML_VALID_ENABLED */           if (((ctxt->loadsubset & XML_SKIP_IDS) == 0) &&	       (((ctxt->replaceEntities == 0) && (ctxt->external != 2)) ||	        ((ctxt->replaceEntities != 0) && (ctxt->inSubset == 0)))) {        /*	 * when validating, the ID registration is done at the attribute	 * validation level. Otherwise we have to do specific handling here.	 */	if (xmlIsID(ctxt->myDoc, ctxt->node, ret))	    xmlAddID(&ctxt->vctxt, ctxt->myDoc, value, ret);	else if (xmlIsRef(ctxt->myDoc, ctxt->node, ret))	    xmlAddRef(&ctxt->vctxt, ctxt->myDoc, value, ret);	else if (xmlStrEqual(fullname, BAD_CAST "xml:id")) {	    /*	     * Add the xml:id value	     *	     * Open issue: normalization of the value.	     */	    if (xmlValidateNCName(value, 1) != 0) {	        xmlErrValid(ctxt, XML_DTD_XMLID_VALUE,		      "xml:id : attribute value %s is not an NCName\n",			    (const char *) value, NULL);	    }	    xmlAddID(&ctxt->vctxt, ctxt->myDoc, value, ret);	}    }error:    if (nval != NULL)	xmlFree(nval);    if (ns != NULL) 	xmlFree(ns);}/* * xmlCheckDefaultedAttributes: * * Check defaulted attributes from the DTD */static voidxmlCheckDefaultedAttributes(xmlParserCtxtPtr ctxt, const xmlChar *name,	const xmlChar *prefix, const xmlChar **atts) {    xmlElementPtr elemDecl;    const xmlChar *att;    int internal = 1;    int i;    elemDecl = xmlGetDtdQElementDesc(ctxt->myDoc->intSubset, name, prefix);    if (elemDecl == NULL) {	elemDecl = xmlGetDtdQElementDesc(ctxt->myDoc->extSubset, name, prefix);	internal = 0;    }process_external_subset:    if (elemDecl != NULL) {	xmlAttributePtr attr = elemDecl->attributes;	/*	 * Check against defaulted attributes from the external subset	 * if the document is stamped as standalone	 */	if ((ctxt->myDoc->standalone == 1) &&	    (ctxt->myDoc->extSubset != NULL) &&	    (ctxt->validate)) {	    while (attr != NULL) {		if ((attr->defaultValue != NULL) &&		    (xmlGetDtdQAttrDesc(ctxt->myDoc->extSubset,					attr->elem, attr->name,					attr->prefix) == attr) &&		    (xmlGetDtdQAttrDesc(ctxt->myDoc->intSubset,					attr->elem, attr->name,					attr->prefix) == NULL)) {		    xmlChar *fulln;		    if (attr->prefix != NULL) {			fulln = xmlStrdup(attr->prefix);			fulln = xmlStrcat(fulln, BAD_CAST ":");			fulln = xmlStrcat(fulln, attr->name);		    } else {			fulln = xmlStrdup(attr->name);		    }		    /*		     * Check that the attribute is not declared in the		     * serialization		     */		    att = NULL;		    if (atts != NULL) {			i = 0;			att = atts[i];			while (att != NULL) {			    if (xmlStrEqual(att, fulln))				break;			    i += 2;			    att = atts[i];			}		    }		    if (att == NULL) {		        xmlErrValid(ctxt, XML_DTD_STANDALONE_DEFAULTED,      "standalone: attribute %s on %s defaulted from external subset\n",				    (const char *)fulln,				    (const char *)attr->elem);		    }		}		attr = attr->nexth;	    }	}	/*	 * Actually insert defaulted values when needed	 */	attr = elemDecl->attributes;	while (attr != NULL) {	    /*	     * Make sure that attributes redefinition occuring in the	     * internal subset are not overriden by definitions in the	     * external subset.	     */	    if (attr->defaultValue != NULL) {		/*		 * the element should be instantiated in the tree if:		 *  - this is a namespace prefix		 *  - the user required for completion in the tree		 *    like XSLT		 *  - there isn't already an attribute definition 		 *    in the internal subset overriding it.		 */		if (((attr->prefix != NULL) &&		     (xmlStrEqual(attr->prefix, BAD_CAST "xmlns"))) ||		    ((attr->prefix == NULL) &&		     (xmlStrEqual(attr->name, BAD_CAST "xmlns"))) ||		    (ctxt->loadsubset & XML_COMPLETE_ATTRS)) {		    xmlAttributePtr tst;		    tst = xmlGetDtdQAttrDesc(ctxt->myDoc->intSubset,					     attr->elem, attr->name,					     attr->prefix);		    if ((tst == attr) || (tst == NULL)) {		        xmlChar fn[50];			xmlChar *fulln;                        fulln = xmlBuildQName(attr->name, attr->prefix, fn, 50);			if (fulln == NULL) {			    if ((ctxt->sax != NULL) &&			        (ctxt->sax->error != NULL))				ctxt->sax->error(ctxt->userData, 				     "SAX.xmlSAX2StartElement(): out of memory\n");			    ctxt->errNo = XML_ERR_NO_MEMORY;			    ctxt->instate = XML_PARSER_EOF;			    ctxt->disableSAX = 1;			    return;			}			/*			 * Check that the attribute is not declared in the			 * serialization			 */			att = NULL;			if (atts != NULL) {			    i = 0;			    att = atts[i];			    while (att != NULL) {				if (xmlStrEqual(att, fulln))				    break;				i += 2;				att = atts[i];			    }			}			if (att == NULL) {			    xmlSAX2AttributeInternal(ctxt, fulln,						 attr->defaultValue, prefix);			}			if ((fulln != fn) && (fulln != attr->name))			    xmlFree(fulln);		    }		}	    }	    attr = attr->nexth;	}	if (internal == 1) {	    elemDecl = xmlGetDtdQElementDesc(ctxt->myDoc->extSubset,		                             name, prefix);	    internal = 0;	    goto process_external_subset;	}    }}

⌨️ 快捷键说明

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