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

📄 sax2.c.svn-base

📁 这是一个用于解析xml文件的类库。使用这个类库
💻 SVN-BASE
📖 第 1 页 / 共 5 页
字号:
 */xmlEntityPtrxmlSAX2GetParameterEntity(void *ctx, const xmlChar *name){    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;    xmlEntityPtr ret;#ifdef DEBUG_SAX    xmlGenericError(xmlGenericErrorContext,	    "SAX.xmlSAX2GetParameterEntity(%s)\n", name);#endif    ret = xmlGetParameterEntity(ctxt->myDoc, name);    return(ret);}/** * xmlSAX2EntityDecl: * @ctx: the user data (XML parser context) * @name:  the entity name  * @type:  the entity type  * @publicId: The public ID of the entity * @systemId: The system ID of the entity * @content: the entity value (without processing). * * An entity definition has been parsed */voidxmlSAX2EntityDecl(void *ctx, const xmlChar *name, int type,          const xmlChar *publicId, const xmlChar *systemId, xmlChar *content){    xmlEntityPtr ent;    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;#ifdef DEBUG_SAX    xmlGenericError(xmlGenericErrorContext,	    "SAX.xmlSAX2EntityDecl(%s, %d, %s, %s, %s)\n",            name, type, publicId, systemId, content);#endif    if (ctxt->inSubset == 1) {	ent = xmlAddDocEntity(ctxt->myDoc, name, type, publicId,		              systemId, content);	if ((ent == NULL) && (ctxt->pedantic) &&	    (ctxt->sax != NULL) && (ctxt->sax->warning != NULL))	    ctxt->sax->warning(ctxt->userData, 	     "Entity(%s) already defined in the internal subset\n", name);	if ((ent != NULL) && (ent->URI == NULL) && (systemId != NULL)) {	    xmlChar *URI;	    const char *base = NULL;	    if (ctxt->input != NULL)		base = ctxt->input->filename;	    if (base == NULL)		base = ctxt->directory;		    URI = xmlBuildURI(systemId, (const xmlChar *) base);	    ent->URI = URI;	}    } else if (ctxt->inSubset == 2) {	ent = xmlAddDtdEntity(ctxt->myDoc, name, type, publicId,		              systemId, content);	if ((ent == NULL) && (ctxt->pedantic) &&	    (ctxt->sax != NULL) && (ctxt->sax->warning != NULL))	    ctxt->sax->warning(ctxt->userData, 	     "Entity(%s) already defined in the external subset\n", name);	if ((ent != NULL) && (ent->URI == NULL) && (systemId != NULL)) {	    xmlChar *URI;	    const char *base = NULL;	    if (ctxt->input != NULL)		base = ctxt->input->filename;	    if (base == NULL)		base = ctxt->directory;		    URI = xmlBuildURI(systemId, (const xmlChar *) base);	    ent->URI = URI;	}    } else {	if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))	    ctxt->sax->error(ctxt->userData, 	     "SAX.xmlSAX2EntityDecl(%s) called while not in subset\n", name);    }}/** * xmlSAX2AttributeDecl: * @ctx: the user data (XML parser context) * @elem:  the name of the element * @fullname:  the attribute name  * @type:  the attribute type  * @def:  the type of default value * @defaultValue: the attribute default value * @tree:  the tree of enumerated value set * * An attribute definition has been parsed */voidxmlSAX2AttributeDecl(void *ctx, const xmlChar *elem, const xmlChar *fullname,              int type, int def, const xmlChar *defaultValue,	      xmlEnumerationPtr tree){    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;    xmlAttributePtr attr;    xmlChar *name = NULL, *prefix = NULL;#ifdef DEBUG_SAX    xmlGenericError(xmlGenericErrorContext,	    "SAX.xmlSAX2AttributeDecl(%s, %s, %d, %d, %s, ...)\n",            elem, fullname, type, def, defaultValue);#endif    if ((xmlStrEqual(fullname, BAD_CAST "xml:id")) &&        (type != XML_ATTRIBUTE_ID)) {	/*	 * Raise the error but keep the validity flag	 */	int tmp = ctxt->valid;	xmlErrValid(ctxt, XML_DTD_XMLID_TYPE,	      "xml:id : attribute type should be ID\n", NULL, NULL);	ctxt->valid = tmp;    }    /* TODO: optimize name/prefix allocation */    name = xmlSplitQName(ctxt, fullname, &prefix);    ctxt->vctxt.valid = 1;    if (ctxt->inSubset == 1)	attr = xmlAddAttributeDecl(&ctxt->vctxt, ctxt->myDoc->intSubset, elem,	       name, prefix, (xmlAttributeType) type,	       (xmlAttributeDefault) def, defaultValue, tree);    else if (ctxt->inSubset == 2)	attr = xmlAddAttributeDecl(&ctxt->vctxt, ctxt->myDoc->extSubset, elem,	   name, prefix, (xmlAttributeType) type, 	   (xmlAttributeDefault) def, defaultValue, tree);    else {	if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))	    ctxt->sax->error(ctxt->userData, 	     "SAX.xmlSAX2AttributeDecl(%s) called while not in subset\n", name);	xmlFreeEnumeration(tree);	return;    }#ifdef LIBXML_VALID_ENABLED    if (ctxt->vctxt.valid == 0)	ctxt->valid = 0;    if ((attr != NULL) && (ctxt->validate) && (ctxt->wellFormed) &&        (ctxt->myDoc != NULL) && (ctxt->myDoc->intSubset != NULL))	ctxt->valid &= xmlValidateAttributeDecl(&ctxt->vctxt, ctxt->myDoc,	                                        attr);#endif /* LIBXML_VALID_ENABLED */    if (prefix != NULL)	xmlFree(prefix);    if (name != NULL)	xmlFree(name);}/** * xmlSAX2ElementDecl: * @ctx: the user data (XML parser context) * @name:  the element name  * @type:  the element type  * @content: the element value tree * * An element definition has been parsed */voidxmlSAX2ElementDecl(void *ctx, const xmlChar * name, int type,            xmlElementContentPtr content){    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;    xmlElementPtr elem = NULL;#ifdef DEBUG_SAX    xmlGenericError(xmlGenericErrorContext,                    "SAX.xmlSAX2ElementDecl(%s, %d, ...)\n", name, type);#endif    if (ctxt->inSubset == 1)        elem = xmlAddElementDecl(&ctxt->vctxt, ctxt->myDoc->intSubset,                                 name, (xmlElementTypeVal) type, content);    else if (ctxt->inSubset == 2)        elem = xmlAddElementDecl(&ctxt->vctxt, ctxt->myDoc->extSubset,                                 name, (xmlElementTypeVal) type, content);    else {        if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))            ctxt->sax->error(ctxt->userData,                             "SAX.xmlSAX2ElementDecl(%s) called while not in subset\n",                             name);        return;    }#ifdef LIBXML_VALID_ENABLED    if (elem == NULL)        ctxt->valid = 0;    if (ctxt->validate && ctxt->wellFormed &&        ctxt->myDoc && ctxt->myDoc->intSubset)        ctxt->valid &=            xmlValidateElementDecl(&ctxt->vctxt, ctxt->myDoc, elem);#endif /* LIBXML_VALID_ENABLED */}/** * xmlSAX2NotationDecl: * @ctx: the user data (XML parser context) * @name: The name of the notation * @publicId: The public ID of the entity * @systemId: The system ID of the entity * * What to do when a notation declaration has been parsed. */voidxmlSAX2NotationDecl(void *ctx, const xmlChar *name,	     const xmlChar *publicId, const xmlChar *systemId){    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;    xmlNotationPtr nota = NULL;#ifdef DEBUG_SAX    xmlGenericError(xmlGenericErrorContext,	    "SAX.xmlSAX2NotationDecl(%s, %s, %s)\n", name, publicId, systemId);#endif    if ((publicId == NULL) && (systemId == NULL)) {	if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))	    ctxt->sax->error(ctxt->userData, 	     "SAX.xmlSAX2NotationDecl(%s) externalID or PublicID missing\n", name);	ctxt->valid = 0;	ctxt->wellFormed = 0;	return;    } else if (ctxt->inSubset == 1)	nota = xmlAddNotationDecl(&ctxt->vctxt, ctxt->myDoc->intSubset, name,                              publicId, systemId);    else if (ctxt->inSubset == 2)	nota = xmlAddNotationDecl(&ctxt->vctxt, ctxt->myDoc->extSubset, name,                              publicId, systemId);    else {	if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))	    ctxt->sax->error(ctxt->userData, 	     "SAX.xmlSAX2NotationDecl(%s) called while not in subset\n", name);	return;    }#ifdef LIBXML_VALID_ENABLED    if (nota == NULL) ctxt->valid = 0;    if (ctxt->validate && ctxt->wellFormed &&        ctxt->myDoc && ctxt->myDoc->intSubset)	ctxt->valid &= xmlValidateNotationDecl(&ctxt->vctxt, ctxt->myDoc,	                                       nota);#endif /* LIBXML_VALID_ENABLED */}/** * xmlSAX2UnparsedEntityDecl: * @ctx: the user data (XML parser context) * @name: The name of the entity * @publicId: The public ID of the entity * @systemId: The system ID of the entity * @notationName: the name of the notation * * What to do when an unparsed entity declaration is parsed */voidxmlSAX2UnparsedEntityDecl(void *ctx, const xmlChar *name,		   const xmlChar *publicId, const xmlChar *systemId,		   const xmlChar *notationName){    xmlEntityPtr ent;    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;#ifdef DEBUG_SAX    xmlGenericError(xmlGenericErrorContext,	    "SAX.xmlSAX2UnparsedEntityDecl(%s, %s, %s, %s)\n",            name, publicId, systemId, notationName);#endif    if (ctxt->inSubset == 1) {	ent = xmlAddDocEntity(ctxt->myDoc, name,			XML_EXTERNAL_GENERAL_UNPARSED_ENTITY,			publicId, systemId, notationName);	if ((ent == NULL) && (ctxt->pedantic) &&	    (ctxt->sax != NULL) && (ctxt->sax->warning != NULL))	    ctxt->sax->warning(ctxt->userData, 	     "Entity(%s) already defined in the internal subset\n", name);	if ((ent != NULL) && (ent->URI == NULL) && (systemId != NULL)) {	    xmlChar *URI;	    const char *base = NULL;	    if (ctxt->input != NULL)		base = ctxt->input->filename;	    if (base == NULL)		base = ctxt->directory;		    URI = xmlBuildURI(systemId, (const xmlChar *) base);	    ent->URI = URI;	}    } else if (ctxt->inSubset == 2) {	ent = xmlAddDtdEntity(ctxt->myDoc, name,			XML_EXTERNAL_GENERAL_UNPARSED_ENTITY,			publicId, systemId, notationName);	if ((ent == NULL) && (ctxt->pedantic) &&	    (ctxt->sax != NULL) && (ctxt->sax->warning != NULL))	    ctxt->sax->warning(ctxt->userData, 	     "Entity(%s) already defined in the external subset\n", name);	if ((ent != NULL) && (ent->URI == NULL) && (systemId != NULL)) {	    xmlChar *URI;	    const char *base = NULL;	    if (ctxt->input != NULL)		base = ctxt->input->filename;	    if (base == NULL)		base = ctxt->directory;		    URI = xmlBuildURI(systemId, (const xmlChar *) base);	    ent->URI = URI;	}    } else {	if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))	    ctxt->sax->error(ctxt->userData, 	     "SAX.xmlSAX2UnparsedEntityDecl(%s) called while not in subset\n", name);    }}/** * xmlSAX2SetDocumentLocator: * @ctx: the user data (XML parser context) * @loc: A SAX Locator * * Receive the document locator at startup, actually xmlDefaultSAXLocator * Everything is available on the context, so this is useless in our case. */voidxmlSAX2SetDocumentLocator(void *ctx ATTRIBUTE_UNUSED, xmlSAXLocatorPtr loc ATTRIBUTE_UNUSED){    /* xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; */#ifdef DEBUG_SAX    xmlGenericError(xmlGenericErrorContext,	    "SAX.xmlSAX2SetDocumentLocator()\n");#endif}/** * xmlSAX2StartDocument: * @ctx: the user data (XML parser context) * * called when the document start being processed. */voidxmlSAX2StartDocument(void *ctx){    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;    xmlDocPtr doc;#ifdef DEBUG_SAX    xmlGenericError(xmlGenericErrorContext,	    "SAX.xmlSAX2StartDocument()\n");#endif    if (ctxt->html) {#ifdef LIBXML_HTML_ENABLED	//if (ctxt->myDoc == NULL)	//    ctxt->myDoc = htmlNewDocNoDtD(NULL, NULL);	//if (ctxt->myDoc == NULL) {	//    if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))	//	ctxt->sax->error(ctxt->userData, 	//	     "SAX.xmlSAX2StartDocument(): out of memory\n");	//    ctxt->errNo = XML_ERR_NO_MEMORY;	//    ctxt->instate = XML_PARSER_EOF;	//    ctxt->disableSAX = 1;	//    return;	//}#else        xmlGenericError(xmlGenericErrorContext,		"libxml2 built without HTML support\n");	ctxt->errNo = XML_ERR_INTERNAL_ERROR;	ctxt->instate = XML_PARSER_EOF;	ctxt->disableSAX = 1;	return;#endif    } else {	doc = ctxt->myDoc = xmlNewDoc(ctxt->version);	if (doc != NULL) {	    if (ctxt->encoding != NULL)		doc->encoding = xmlStrdup(ctxt->encoding);	    else		doc->encoding = NULL;	    doc->standalone = ctxt->standalone;	} else {	    if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))		ctxt->sax->error(ctxt->userData, 		     "SAX.xmlSAX2StartDocument(): out of memory\n");	    ctxt->errNo = XML_ERR_NO_MEMORY;	    ctxt->instate = XML_PARSER_EOF;	    ctxt->disableSAX = 1;	    return;	}	if ((ctxt->dictNames) && (doc != NULL)) {	    doc->dict = ctxt->dict;	    xmlDictReference(doc->dict);	}    }    if ((ctxt->myDoc != NULL) && (ctxt->myDoc->URL == NULL) &&	(ctxt->input != NULL) && (ctxt->input->filename != NULL)) {	ctxt->myDoc->URL = xmlCanonicPath((const xmlChar *) ctxt->input->filename);	if (ctxt->myDoc->URL == NULL)	    ctxt->myDoc->URL = xmlStrdup((const xmlChar *) ctxt->input->filename);    }}/** * xmlSAX2EndDocument: * @ctx: the user data (XML parser context) * * called when the document end has been detected. */voidxmlSAX2EndDocument(void *ctx){    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;#ifdef DEBUG_SAX    xmlGenericError(xmlGenericErrorContext,	    "SAX.xmlSAX2EndDocument()\n");#endif#ifdef LIBXML_VALID_ENABLED    if (ctxt->validate && ctxt->wellFormed &&        ctxt->myDoc && ctxt->myDoc->intSubset)	ctxt->valid &= xmlValidateDocumentFinal(&ctxt->vctxt, ctxt->myDoc);#endif /* LIBXML_VALID_ENABLED */    /*     * Grab the encoding if it was added on-the-fly     */    if ((ctxt->encoding != NULL) && (ctxt->myDoc != NULL) &&	(ctxt->myDoc->encoding == NULL)) {	ctxt->myDoc->encoding = ctxt->encoding;	ctxt->encoding = NULL;    }    if ((ctxt->inputTab[0]->encoding != NULL) && (ctxt->myDoc != NULL) &&	(ctxt->myDoc->encoding == NULL)) {	ctxt->myDoc->encoding = xmlStrdup(ctxt->inputTab[0]->encoding);    }    if ((ctxt->charset != XML_CHAR_ENCODING_NONE) && (ctxt->myDoc != NULL) &&	(ctxt->myDoc->charset == XML_CHAR_ENCODING_NONE)) {	ctxt->myDoc->charset = ctxt->charset;    }}#if defined(LIBXML_SAX1_ENABLED) || defined(LIBXML_HTML_ENABLED)/** * xmlSAX2AttributeInternal: * @ctx: the user data (XML parser context) * @fullname:  The attribute name, including namespace prefix * @value:  The attribute value * @prefix: the prefix on the element node * * Handle an attribute that has been read by the parser. * The default handling is to convert the attribute into an * DOM subtree and past it in a new xmlAttr element added to * the element. */static voidxmlSAX2AttributeInternal(void *ctx, const xmlChar *fullname,             const xmlChar *value, const xmlChar *prefix ATTRIBUTE_UNUSED){    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;    xmlAttrPtr ret;    xmlChar *name;    xmlChar *ns;    xmlChar *nval;    xmlNsPtr namespace;    /*     * Split the full name into a namespace prefix and the tag name

⌨️ 快捷键说明

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