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

📄 parserinternals.c.svn-base

📁 这是一个用于解析xml文件的类库。使用这个类库
💻 SVN-BASE
📖 第 1 页 / 共 4 页
字号:
	return(-1);    }    else        xmlSAXVersion(ctxt->sax, 2);    ctxt->maxatts = 0;    ctxt->atts = NULL;    /* Allocate the Input stack */    ctxt->inputTab = (xmlParserInputPtr *)	        xmlMalloc(5 * sizeof(xmlParserInputPtr));    if (ctxt->inputTab == NULL) {        xmlErrMemory(NULL, "cannot initialize parser context\n");	ctxt->inputNr = 0;	ctxt->inputMax = 0;	ctxt->input = NULL;	return(-1);    }    ctxt->inputNr = 0;    ctxt->inputMax = 5;    ctxt->input = NULL;    ctxt->version = NULL;    ctxt->encoding = NULL;    ctxt->standalone = -1;    ctxt->hasExternalSubset = 0;    ctxt->hasPErefs = 0;    ctxt->html = 0;    ctxt->external = 0;    ctxt->instate = XML_PARSER_START;    ctxt->token = 0;    ctxt->directory = NULL;    /* Allocate the Node stack */    ctxt->nodeTab = (xmlNodePtr *) xmlMalloc(10 * sizeof(xmlNodePtr));    if (ctxt->nodeTab == NULL) {        xmlErrMemory(NULL, "cannot initialize parser context\n");	ctxt->nodeNr = 0;	ctxt->nodeMax = 0;	ctxt->node = NULL;	ctxt->inputNr = 0;	ctxt->inputMax = 0;	ctxt->input = NULL;	return(-1);    }    ctxt->nodeNr = 0;    ctxt->nodeMax = 10;    ctxt->node = NULL;    /* Allocate the Name stack */    ctxt->nameTab = (const xmlChar **) xmlMalloc(10 * sizeof(xmlChar *));    if (ctxt->nameTab == NULL) {        xmlErrMemory(NULL, "cannot initialize parser context\n");	ctxt->nodeNr = 0;	ctxt->nodeMax = 0;	ctxt->node = NULL;	ctxt->inputNr = 0;	ctxt->inputMax = 0;	ctxt->input = NULL;	ctxt->nameNr = 0;	ctxt->nameMax = 0;	ctxt->name = NULL;	return(-1);    }    ctxt->nameNr = 0;    ctxt->nameMax = 10;    ctxt->name = NULL;    /* Allocate the space stack */    ctxt->spaceTab = (int *) xmlMalloc(10 * sizeof(int));    if (ctxt->spaceTab == NULL) {        xmlErrMemory(NULL, "cannot initialize parser context\n");	ctxt->nodeNr = 0;	ctxt->nodeMax = 0;	ctxt->node = NULL;	ctxt->inputNr = 0;	ctxt->inputMax = 0;	ctxt->input = NULL;	ctxt->nameNr = 0;	ctxt->nameMax = 0;	ctxt->name = NULL;	ctxt->spaceNr = 0;	ctxt->spaceMax = 0;	ctxt->space = NULL;	return(-1);    }    ctxt->spaceNr = 1;    ctxt->spaceMax = 10;    ctxt->spaceTab[0] = -1;    ctxt->space = &ctxt->spaceTab[0];    ctxt->userData = ctxt;    ctxt->myDoc = NULL;    ctxt->wellFormed = 1;    ctxt->nsWellFormed = 1;    ctxt->valid = 1;    ctxt->loadsubset = xmlLoadExtDtdDefaultValue;    ctxt->validate = xmlDoValidityCheckingDefaultValue;    ctxt->pedantic = xmlPedanticParserDefaultValue;    ctxt->linenumbers = xmlLineNumbersDefaultValue;    ctxt->keepBlanks = xmlKeepBlanksDefaultValue;    if (ctxt->keepBlanks == 0)	ctxt->sax->ignorableWhitespace = xmlSAX2IgnorableWhitespace;    ctxt->vctxt.userData = ctxt;    ctxt->vctxt.error = xmlParserValidityError;    ctxt->vctxt.warning = xmlParserValidityWarning;    if (ctxt->validate) {	if (xmlGetWarningsDefaultValue == 0)	    ctxt->vctxt.warning = NULL;	else	    ctxt->vctxt.warning = xmlParserValidityWarning;	ctxt->vctxt.nodeMax = 0;    }    ctxt->replaceEntities = xmlSubstituteEntitiesDefaultValue;    ctxt->record_info = 0;    ctxt->nbChars = 0;    ctxt->checkIndex = 0;    ctxt->inSubset = 0;    ctxt->errNo = XML_ERR_OK;    ctxt->depth = 0;    ctxt->charset = XML_CHAR_ENCODING_UTF8;    ctxt->catalogs = NULL;    xmlInitNodeInfoSeq(&ctxt->node_seq);    return(0);}/** * xmlFreeParserCtxt: * @ctxt:  an XML parser context * * Free all the memory used by a parser context. However the parsed * document in ctxt->myDoc is not freed. */voidxmlFreeParserCtxt(xmlParserCtxtPtr ctxt){    xmlParserInputPtr input;    if (ctxt == NULL) return;    while ((input = inputPop(ctxt)) != NULL) { /* Non consuming */        xmlFreeInputStream(input);    }    if (ctxt->spaceTab != NULL) xmlFree(ctxt->spaceTab);    if (ctxt->nameTab != NULL) xmlFree((xmlChar * *)ctxt->nameTab);    if (ctxt->nodeTab != NULL) xmlFree(ctxt->nodeTab);    if (ctxt->inputTab != NULL) xmlFree(ctxt->inputTab);    if (ctxt->version != NULL) xmlFree((char *) ctxt->version);    if (ctxt->encoding != NULL) xmlFree((char *) ctxt->encoding);    if (ctxt->extSubURI != NULL) xmlFree((char *) ctxt->extSubURI);    if (ctxt->extSubSystem != NULL) xmlFree((char *) ctxt->extSubSystem);#ifdef LIBXML_SAX1_ENABLED    if ((ctxt->sax != NULL) &&        (ctxt->sax != (xmlSAXHandlerPtr) &xmlDefaultSAXHandler))#else    if (ctxt->sax != NULL)#endif /* LIBXML_SAX1_ENABLED */        xmlFree(ctxt->sax);    if (ctxt->directory != NULL) xmlFree((char *) ctxt->directory);    if (ctxt->vctxt.nodeTab != NULL) xmlFree(ctxt->vctxt.nodeTab);    if (ctxt->atts != NULL) xmlFree((xmlChar * *)ctxt->atts);    if (ctxt->dict != NULL) xmlDictFree(ctxt->dict);    if (ctxt->nsTab != NULL) xmlFree((char *) ctxt->nsTab);    if (ctxt->pushTab != NULL) xmlFree(ctxt->pushTab);    if (ctxt->attallocs != NULL) xmlFree(ctxt->attallocs);    if (ctxt->attsDefault != NULL)         xmlHashFree(ctxt->attsDefault, (xmlHashDeallocator) xmlFree);    if (ctxt->attsSpecial != NULL)        xmlHashFree(ctxt->attsSpecial, NULL);    if (ctxt->freeElems != NULL) {        xmlNodePtr cur, next;	cur = ctxt->freeElems;	while (cur != NULL) {	    next = cur->next;	    xmlFree(cur);	    cur = next;	}    }    if (ctxt->freeAttrs != NULL) {        xmlAttrPtr cur, next;	cur = ctxt->freeAttrs;	while (cur != NULL) {	    next = cur->next;	    xmlFree(cur);	    cur = next;	}    }    /*     * cleanup the error strings     */    if (ctxt->lastError.message != NULL)        xmlFree(ctxt->lastError.message);    if (ctxt->lastError.file != NULL)        xmlFree(ctxt->lastError.file);    if (ctxt->lastError.str1 != NULL)        xmlFree(ctxt->lastError.str1);    if (ctxt->lastError.str2 != NULL)        xmlFree(ctxt->lastError.str2);    if (ctxt->lastError.str3 != NULL)        xmlFree(ctxt->lastError.str3);#if 0 // def  LIBXML_CATALOG_ENABLED    if (ctxt->catalogs != NULL)	xmlCatalogFreeLocal(ctxt->catalogs);#endif    xmlFree(ctxt);}/** * xmlNewParserCtxt: * * Allocate and initialize a new parser context. * * Returns the xmlParserCtxtPtr or NULL */xmlParserCtxtPtrxmlNewParserCtxt(){    xmlParserCtxtPtr ctxt;    ctxt = (xmlParserCtxtPtr) xmlMalloc(sizeof(xmlParserCtxt));    if (ctxt == NULL) {	xmlErrMemory(NULL, "cannot allocate parser context\n");	return(NULL);    }    memset(ctxt, 0, sizeof(xmlParserCtxt));    if (xmlInitParserCtxt(ctxt) < 0) {        xmlFreeParserCtxt(ctxt);	return(NULL);    }    return(ctxt);}/************************************************************************ *									* *		Handling of node informations				* *									* ************************************************************************//** * xmlClearParserCtxt: * @ctxt:  an XML parser context * * Clear (release owned resources) and reinitialize a parser context */voidxmlClearParserCtxt(xmlParserCtxtPtr ctxt){  if (ctxt==NULL)    return;  xmlClearNodeInfoSeq(&ctxt->node_seq);  xmlInitParserCtxt(ctxt);}/** * xmlParserFindNodeInfo: * @ctx:  an XML parser context * @node:  an XML node within the tree * * Find the parser node info struct for a given node *  * Returns an xmlParserNodeInfo block pointer or NULL */const xmlParserNodeInfo* xmlParserFindNodeInfo(const xmlParserCtxtPtr ctx,                                               const xmlNodePtr node){  unsigned long pos;  /* Find position where node should be at */  pos = xmlParserFindNodeInfoIndex(&ctx->node_seq, node);  if (pos < ctx->node_seq.length && ctx->node_seq.buffer[pos].node == node)    return &ctx->node_seq.buffer[pos];  else    return NULL;}/** * xmlInitNodeInfoSeq: * @seq:  a node info sequence pointer * * -- Initialize (set to initial state) node info sequence */voidxmlInitNodeInfoSeq(xmlParserNodeInfoSeqPtr seq){  seq->length = 0;  seq->maximum = 0;  seq->buffer = NULL;}/** * xmlClearNodeInfoSeq: * @seq:  a node info sequence pointer * * -- Clear (release memory and reinitialize) node *   info sequence */voidxmlClearNodeInfoSeq(xmlParserNodeInfoSeqPtr seq){  if ( seq->buffer != NULL )    xmlFree(seq->buffer);  xmlInitNodeInfoSeq(seq);}/** * xmlParserFindNodeInfoIndex: * @seq:  a node info sequence pointer * @node:  an XML node pointer * *  * xmlParserFindNodeInfoIndex : Find the index that the info record for *   the given node is or should be at in a sorted sequence * * Returns a long indicating the position of the record */unsigned long xmlParserFindNodeInfoIndex(const xmlParserNodeInfoSeqPtr seq,                                         const xmlNodePtr node){  unsigned long upper, lower, middle;  int found = 0;  /* Do a binary search for the key */  lower = 1;  upper = seq->length;  middle = 0;  while ( lower <= upper && !found) {    middle = lower + (upper - lower) / 2;    if ( node == seq->buffer[middle - 1].node )      found = 1;    else if ( node < seq->buffer[middle - 1].node )      upper = middle - 1;    else      lower = middle + 1;  }  /* Return position */  if ( middle == 0 || seq->buffer[middle - 1].node < node )    return middle;  else     return middle - 1;}/** * xmlParserAddNodeInfo: * @ctxt:  an XML parser context * @info:  a node info sequence pointer * * Insert node info record into the sorted sequence */voidxmlParserAddNodeInfo(xmlParserCtxtPtr ctxt,                     const xmlParserNodeInfoPtr info){    unsigned long pos;    /* Find pos and check to see if node is already in the sequence */    pos = xmlParserFindNodeInfoIndex(&ctxt->node_seq, (xmlNodePtr)                                     info->node);    if (pos < ctxt->node_seq.length        && ctxt->node_seq.buffer[pos].node == info->node) {        ctxt->node_seq.buffer[pos] = *info;    }    /* Otherwise, we need to add new node to buffer */    else {        if (ctxt->node_seq.length + 1 > ctxt->node_seq.maximum) {            xmlParserNodeInfo *tmp_buffer;            unsigned int byte_size;            if (ctxt->node_seq.maximum == 0)                ctxt->node_seq.maximum = 2;            byte_size = (sizeof(*ctxt->node_seq.buffer) *			(2 * ctxt->node_seq.maximum));            if (ctxt->node_seq.buffer == NULL)                tmp_buffer = (xmlParserNodeInfo *) xmlMalloc(byte_size);            else                tmp_buffer =                    (xmlParserNodeInfo *) xmlRealloc(ctxt->node_seq.buffer,                                                     byte_size);            if (tmp_buffer == NULL) {		xmlErrMemory(ctxt, "failed to allocate buffer\n");                return;            }            ctxt->node_seq.buffer = tmp_buffer;            ctxt->node_seq.maximum *= 2;        }        /* If position is not at end, move elements out of the way */        if (pos != ctxt->node_seq.length) {            unsigned long i;            for (i = ctxt->node_seq.length; i > pos; i--)                ctxt->node_seq.buffer[i] = ctxt->node_seq.buffer[i - 1];        }        /* Copy element and increase length */        ctxt->node_seq.buffer[pos] = *info;        ctxt->node_seq.length++;    }}/************************************************************************ *									* *		Defaults settings					* *									* ************************************************************************//** * xmlPedanticParserDefault: * @val:  int 0 or 1  * * Set and return the previous value for enabling pedantic warnings. * * Returns the last value for 0 for no substitution, 1 for substitution. */intxmlPedanticParserDefault(int val) {    int old = xmlPedanticParserDefaultValue;    xmlPedanticParserDefaultValue = val;    return(old);}/** * xmlLineNumbersDefault: * @val:  int 0 or 1  * * Set and return the previous value for enabling line numbers in elements * contents. This may break on old application and is turned off by default. * * Returns the last value for 0 for no substitution, 1 for substitution. */intxmlLineNumbersDefault(int val) {    int old = xmlLineNumbersDefaultValue;    xmlLineNumbersDefaultValue = val;    return(old);}/** * xmlSubstituteEntitiesDefault: * @val:  int 0 or 1  * * Set and return the previous value for default entity support. * Initially the parser always keep entity references instead of substituting * entity values in the output. This function has to be used to change the * default parser behavior * SAX::substituteEntities() has to be used for changing that on a file by * file basis. * * Returns the last value for 0 for no substitution, 1 for substitution. */intxmlSubstituteEntitiesDefault(int val) {    int old = xmlSubstituteEntitiesDefaultValue;    xmlSubstituteEntitiesDefaultValue = val;    return(old);}/** * xmlKeepBlanksDefault: * @val:  int 0 or 1  * * Set and return the previous value for default blanks text nodes support. * The 1.x version of the parser used an heuristic to try to detect * ignorable white spaces. As a result the SAX callback was generating * xmlSAX2IgnorableWhitespace() callbacks instead of characters() one, and when * using the DOM output text nodes containing those blanks were not generated. * The 2.x and later version will switch to the XML standard way and * ignorableWhitespace() are only generated when running the parser in * validating mode and when the current element doesn't allow CDATA or * mixed content. * This function is provided as a way to force the standard behavior  * on 1.X libs and to switch back to the old mode for compatibility when * running 1.X client code on 2.X . Upgrade of 1.X code should be done * by using xmlIsBlankNode() commodity function to detect the "empty" * nodes generated. * This value also affect autogeneration of indentation when saving code * if blanks sections are kept, indentation is not generated. * * Returns the last value for 0 for no substitution, 1 for substitution. */intxmlKeepBlanksDefault(int val) {    int old = xmlKeepBlanksDefaultValue;    xmlKeepBlanksDefaultValue = val;    xmlIndentTreeOutput = !val;    return(old);}

⌨️ 快捷键说明

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