QXmlParser.c
上传用户:fy98168
上传日期:2015-06-26
资源大小:13771k
文件大小:18k
源码类别:

DVD

开发平台:

C/C++

  1. #include <assert.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5. #include <unistd.h>
  6. #include "QXmlParser.h"
  7. #include "XmlStbInfo.h" 
  8. char *xmlHeader = "<?xml";
  9. char *commentHeader = "<!--";
  10. char *commentEnd = "-->";
  11. char *cdataHeader = "<![CDATA[";
  12. char *cdataEnd = "]]>";
  13. QXmlEntity entity[] = 
  14. {
  15.    {"&amp;",  '&' },
  16.    {"&lt;",   '<' },
  17.    {"&gt;",   '>' },
  18.    {"&quot;", '"' },
  19.    {"&apos;", ''' }
  20. };
  21. QXmlParser   NewQXmlParser()
  22. {
  23.    QXmlParser self;
  24.    self.Parse = QXmlParserParse;
  25.    self.Worker = QXmlParserWorker;
  26.    self.FromFile = QXmlParserFromFile;
  27.    self.FromBuff = QXmlParserFromBuff;
  28.    self.ParseDeclaration = QXmlParserDeclaration;
  29.    self.ParseCommentText = QXmlParserCommentText;
  30.    self.ParseNode = QXmlParserNode;
  31.    self.ParseAttrib = QXmlParserAttrib;
  32.    self.ReadName = QXmlParserReadName;
  33.    self.ReadValue = QXmlParserReadValue;
  34.    self.ReadText = QXmlParserReadText;
  35.    self.GetEntity = QXmlParserGetEntity;
  36.    self.Release = QXmlParserRelease;
  37.    self.xml = NULL;
  38.    self.m_ioXML = NewQXmlIO();
  39.    self.m_nodeCurr = NULL;
  40.    return self;
  41. }
  42. QXmlParser   *MallocQXmlParser()
  43. {
  44.    QXmlParser *self = (QXmlParser *)KB_OSPMalloc(sizeof(QXmlParser));
  45.    if(!self) return NULL;
  46.    self->Parse = QXmlParserParse;
  47.    self->Worker = QXmlParserWorker;
  48.    self->FromFile = QXmlParserFromFile;
  49.    self->FromBuff = QXmlParserFromBuff;
  50.    self->ParseDeclaration = QXmlParserDeclaration;
  51.    self->ParseCommentText = QXmlParserCommentText;
  52.    self->ParseNode = QXmlParserNode;
  53.    self->ParseAttrib = QXmlParserAttrib;
  54.    self->ReadName = QXmlParserReadName;
  55.    self->ReadValue = QXmlParserReadValue;
  56.    self->ReadText = QXmlParserReadText;
  57.    self->GetEntity = QXmlParserGetEntity;
  58.    self->Release = QXmlParserRelease;
  59.    self->xml = NULL;
  60.    self->m_ioXML = NewQXmlIO();
  61.    self->m_nodeCurr = NULL;
  62.    return self;
  63. }
  64. int      QXmlParserParse (QXmlParser *self,QXml *xml)
  65. {
  66.    QXmlNode *node ;//= MallocQXmlNode();
  67.    assert(self);
  68.    assert(xml);
  69.    
  70.    self->xml = xml;
  71.    self->m_ioXML.SkipWhiteSpace(&self->m_ioXML);
  72.    if ( self->m_ioXML.IsEmpty(&self->m_ioXML) )
  73.    {
  74.       xml->m_nErrorCode = XML_DATA_EMPTY;
  75.       return XML_DATA_EMPTY;
  76.    }
  77.    self->m_nodeCurr = xml->m_nodeRoot;
  78.    while ( !self->m_ioXML.IsEmpty(&self->m_ioXML) )
  79.    {
  80.       self->m_ioXML.SkipWhiteSpace(&self->m_ioXML);
  81.       //执行解析工作
  82.       if(self->Worker(self) != XML_OK ) 
  83.       {
  84.          self->xml->m_nCol = self->m_ioXML.m_nCol;
  85.          self->xml->m_nRow = self->m_ioXML.m_nRow;
  86.          break;
  87.       }else
  88.       {
  89.          if(self->m_nodeCurr->m_nType != DECLARE && 
  90.          !self->m_nodeCurr->m_szName.IsEmpty(&self->m_nodeCurr->m_szName))
  91.          {
  92.             node = MallocQXmlNode();
  93.             if(node == NULL)
  94.             {
  95.                self->xml->m_nErrorCode =  XML_OUT_MEMORY;
  96.                break;
  97.             }
  98.             node->m_nodeParent = self->m_nodeCurr->m_nodeParent;
  99.             node->m_nodePrev = self->m_nodeCurr;
  100.             self->m_nodeCurr->m_nodeNext = node;
  101.             self->m_nodeCurr = node;
  102.          }
  103.  
  104.       }
  105.    }
  106.    if ( xml->m_nErrorCode == XML_OK)
  107.    {
  108.       if(self->m_nodeCurr->m_nodePrev) 
  109.  self->m_nodeCurr->m_nodePrev->m_nodeNext = NULL;
  110.       self->m_nodeCurr->Release(self->m_nodeCurr);
  111.       KB_OSPFree(self->m_nodeCurr);
  112.       self->m_nodeCurr = NULL;
  113.    }
  114.    return xml->m_nErrorCode;
  115. }
  116. int      QXmlParserWorker (QXmlParser *self)
  117. {
  118.    QString szHeader = NewQString();
  119.    assert(self);
  120.    szHeader.AllocBuffer(&szHeader,5);
  121.    szHeader.m_nDataLength = self->m_ioXML.GetBuff(&self->m_ioXML,
  122.                               szHeader.m_dataBuff,
  123.                               5);
  124.    if(strncmp(szHeader.m_dataBuff,
  125.          xmlHeader,
  126.          strlen(xmlHeader)) == 0)
  127.    {
  128.       //解析XML宣告
  129.       self->ParseDeclaration(self);
  130.    }else if (strncmp(szHeader.m_dataBuff,
  131.          commentHeader,
  132.          strlen(commentHeader)) == 0)
  133.    {
  134.       //解析一个注释   
  135.       self->ParseCommentText(self);
  136.    }else if ( isalpha( *(szHeader.m_dataBuff+1) ) || 
  137.       *(szHeader.m_dataBuff+1) == '_' )
  138.    {
  139.       //解析一个节点
  140.       self->ParseNode(self);
  141.    }else
  142.    {
  143.       if(!self->m_ioXML.IsEmpty(&self->m_ioXML))
  144.       {
  145.          //出现了不认识的部分,应该出错
  146.          self->xml->m_nErrorCode = XML_UNKNOW_FORMAT;
  147.       }
  148.       
  149.    }
  150.    //TODO: :) 加入解析头部为 <? 的'处理'类型
  151.    szHeader.Release(&szHeader);
  152.    return self->xml->m_nErrorCode;
  153. }
  154. int      QXmlParserFromFile (QXmlParser *self,int fd)
  155. {
  156.    self->m_ioXML.FromFile(&self->m_ioXML,fd);
  157.    return XML_OK;
  158. }
  159. int      QXmlParserFromBuff (QXmlParser *self,char *buff)
  160. {
  161.    assert(self);
  162.    if(buff == NULL) return XML_DATA_EMPTY;
  163.    self->m_ioXML.FromBuff(&self->m_ioXML,buff);
  164.    return XML_OK;
  165. }
  166. void   QXmlParserDeclaration (QXmlParser *self)
  167. {
  168.    QField *field;
  169.    QString szHeader = NewQString();
  170.    szHeader.AllocBuffer(&szHeader,2);
  171.    assert(self);
  172.    self->m_nodeCurr->m_nType = DECLARE;
  173.    self->m_ioXML.SkipChar(&self->m_ioXML, 5);
  174.    
  175.    if(self->m_ioXML.IsEmpty(&self->m_ioXML))
  176.    {
  177.       self->xml->m_nErrorCode = XML_DECLARE_ERROR;
  178.       szHeader.Release(&szHeader);
  179.       return ;
  180.    }
  181.    while ( !self->m_ioXML.IsEmpty(&self->m_ioXML))
  182.    {
  183.       self->m_ioXML.SkipWhiteSpace(&self->m_ioXML);
  184.       
  185.       szHeader.m_nDataLength = self->m_ioXML.GetBuff(&self->m_ioXML,szHeader.m_dataBuff,2);
  186.       if(self->m_ioXML.IsEmpty(&self->m_ioXML)) 
  187.       {
  188.          self->xml->m_nErrorCode = XML_DECLARE_ERROR;
  189.          szHeader.Release(&szHeader);
  190.          return ;   
  191.       }
  192.       if(szHeader.Equal(&szHeader,"?>"))
  193.       {
  194.          self->m_ioXML.SkipChar(&self->m_ioXML, 2);
  195.          szHeader.Release(&szHeader);
  196.          return ;
  197.       }
  198.       
  199.       field = self->ParseAttrib(self);
  200.       if(field)
  201.       {
  202.          //接受任意的字段
  203.          printf("[%s]:[%s]n",field->name.m_dataBuff,field->value.m_dataBuff);
  204.          self->xml->m_listDeclare.m_listField.Add(&self->xml->m_listDeclare.m_listField,
  205.             field);
  206.       }else
  207.       {
  208.          if(self->xml->m_nErrorCode != XML_OK)
  209.          {
  210.             // 解析属性时出错
  211.             break;
  212.          }
  213.       }
  214.    }
  215.    szHeader.Release(&szHeader);
  216. }
  217. void   QXmlParserCommentText (QXmlParser *self)
  218. {
  219.    QXmlNode *node ;//= MallocQXmlNode();
  220.    int endlen = strlen(commentHeader);
  221.    node = self->m_nodeCurr;
  222.    
  223.    assert(self);
  224.    assert(node);
  225.    self->m_ioXML.SkipChar(&self->m_ioXML,strlen(commentHeader));
  226.    node->m_nType = COMMENT;
  227.    if(self->ReadValue(self,&node->m_szName,commentEnd,TRUE) != XML_OK)
  228.    {
  229.       self->xml->m_nErrorCode = XML_COMMENT_ERROR;
  230.    }
  231.    else
  232.    {
  233.       self->m_ioXML.SkipChar(&self->m_ioXML,endlen);
  234.       //printf("注释:[%s]n",node->m_szName->m_dataBuff);
  235.    }
  236. }
  237. void   QXmlParserNode (QXmlParser *self)
  238. {
  239.    
  240.    QXmlNode *node = NULL;
  241.    QString endTag ;
  242.    QString szHeader;
  243.    QField *field;
  244.    void        *pStbInfo=NULL;
  245.    KB_DC_TYPE  DcType = DC_TYPE_MAX;
  246.    char c;
  247.    
  248.    assert(self);
  249.    
  250.    self->m_ioXML.SkipWhiteSpace(&self->m_ioXML);
  251.    self->m_ioXML.GetBuff(&self->m_ioXML,&c,1);
  252.    if(c != '<')
  253.    {
  254.       self->xml->m_nErrorCode = XML_NODE_START_ERROR;
  255.       return ; 
  256.    }
  257.    self->m_ioXML.SkipChar(&self->m_ioXML,1);
  258.    node = self->m_nodeCurr;
  259.    node->m_nType = NODE;
  260.    
  261.    if(!node)
  262.    {
  263.       self->xml->m_nErrorCode = XML_OUT_MEMORY;
  264.       return; 
  265.    }
  266.    if(self->ReadName(self,&node->m_szName) != XML_OK)
  267.    {
  268.       return;
  269.    }
  270.    //printf("字段[%s]n",node->m_szName.m_dataBuff);
  271.    //added by whale 07/06/13
  272.    pStbInfo = LinkNewXmlInfoNode(node->m_szName.m_dataBuff, &DcType);
  273.    endTag = NewQString();
  274.    
  275.    endTag.AppendString(&endTag,"</");
  276.    endTag.AppendString(&endTag,node->m_szName.m_dataBuff);
  277.    endTag.AppendString(&endTag,">");
  278.    
  279.    self->m_ioXML.SkipWhiteSpace(&self->m_ioXML);
  280.    // 读出属性.并检查是不是一个空的节点.或是结束的节点  
  281.    szHeader = NewQString();
  282.    
  283.    szHeader.AllocBuffer(&szHeader,endTag.m_nDataLength);
  284.    
  285.    self->m_ioXML.GetBuff(&self->m_ioXML,&c,1);
  286.    while(!self->m_ioXML.IsEmpty(&self->m_ioXML))
  287.    {
  288.       self->m_ioXML.SkipWhiteSpace(&self->m_ioXML);
  289.       
  290.       if ( self->m_ioXML.IsEmpty(&self->m_ioXML) )
  291.       {
  292.          self->xml->m_nErrorCode = XML_DATA_EMPTY;         
  293.          endTag.Release(&endTag);
  294.          szHeader.Release(&szHeader);
  295.          return ;    
  296.       }
  297.       if ( c == '/' )
  298.       {
  299.          self->m_ioXML.SkipChar(&self->m_ioXML,1);
  300.          self->m_ioXML.GetBuff(&self->m_ioXML,&c,1);
  301.          if ( c  != '>')
  302.          {
  303.             // 不允许出现 '/ >' 这样的结尾节点  
  304.             self->xml->m_nErrorCode = XML_NODE_END_ERROR;
  305.             endTag.Release(&endTag);
  306.             szHeader.Release(&szHeader);
  307.             return ;
  308.          }
  309.          self->m_ioXML.SkipChar(&self->m_ioXML,1);
  310.          endTag.Release(&endTag);
  311.          szHeader.Release(&szHeader);
  312.          //printf("NODE[%s]n",node->m_szName.m_dataBuff);
  313.    
  314.          return ;         
  315.       }
  316.       else if ( c == '>' )
  317.       {   
  318.          // 节点的属性读完(无属性),并且有节点的值,或有子节点. 
  319.          self->m_ioXML.SkipChar(&self->m_ioXML,1);
  320.          if(self->ReadText(self,&node->m_szValue) != XML_OK)
  321.          {
  322.             endTag.Release(&endTag);
  323.             szHeader.Release(&szHeader);
  324.             return ;
  325.          }
  326.          // 去掉 </TAG>这样的结尾
  327.          self->m_ioXML.SkipChar(&self->m_ioXML,endTag.m_nDataLength);
  328.          endTag.Release(&endTag);
  329.          szHeader.Release(&szHeader);
  330.          break;
  331.       }
  332.       else
  333.       {
  334.          // 这里是解析属性的
  335.          
  336.          field = self->ParseAttrib(self);
  337.          if(field)
  338.   {
  339. //added by whale 07/06/13
  340. AddXmlNodeValue(field->name.m_dataBuff, field->value.m_dataBuff, pStbInfo, DcType);
  341.             //printf("[%s]:[%s]n",field->name.m_dataBuff,field->value.m_dataBuff);
  342.             node->SetAttrib(node,field->name.m_dataBuff,field->value.m_dataBuff);
  343.             field->Release(field);
  344. KB_OSPFree(field);
  345.             field = NULL;
  346.          }
  347.  else
  348.          {
  349.             if(self->xml->m_nErrorCode != XML_OK)
  350.             {
  351.                // 解析属性时出错
  352.                break;
  353.             }
  354.          }
  355.       }
  356.        self->m_ioXML.GetBuff(&self->m_ioXML,&c,1);
  357.    }
  358.    endTag.Release(&endTag);
  359.    szHeader.Release(&szHeader);
  360.    //printf("NODE[%s]n",node->m_szName.m_dataBuff);
  361. }
  362. //解析属性
  363.  
  364. QField   *QXmlParserAttrib (QXmlParser *self)
  365. {
  366.    QField *field;
  367.    QString  endText;
  368.    char c;
  369.    assert(self);
  370.    if((field = MallocQField()) == NULL)
  371.    {
  372.       self->xml->m_nErrorCode = XML_OUT_MEMORY;
  373.       return NULL;
  374.    }
  375.    if(self->ReadName(self,&(field->name)) == XML_OK)
  376.    {
  377.       self->m_ioXML.SkipWhiteSpace(&self->m_ioXML);
  378.       //根据 '='得到得到单引号或双引号
  379.       self->m_ioXML.GetBuff(&self->m_ioXML,&c,1);   
  380.       if(c != '=' || self->m_ioXML.IsEmpty(&self->m_ioXML))
  381.       {
  382.          self->xml->m_nErrorCode = XML_ATTRIB_ERROR;   
  383.          field->Release(field);
  384.          KB_OSPFree(field);
  385.          return NULL;
  386.       }
  387.       self->m_ioXML.SkipChar(&self->m_ioXML,1);
  388.       self->m_ioXML.SkipWhiteSpace(&self->m_ioXML);
  389.       
  390.       endText = NewQString();
  391.       self->m_ioXML.GetBuff(&self->m_ioXML,&c,1);   
  392.       if ( c == ''' )
  393.       {
  394.          endText.AppendString(&endText,"'");
  395.       }else if ( c == '"')
  396.       {
  397.          endText.AppendString(&endText,""");
  398.       }else
  399.       {
  400.          // 没有引号 
  401.          self->xml->m_nErrorCode = XML_NO_QUOTA;
  402.          endText.Release(&endText);
  403.          return NULL;
  404.       }
  405.       self->m_ioXML.SkipChar(&self->m_ioXML,1);
  406.       if(self->ReadValue(self,
  407.          &(field->value),
  408.          endText.m_dataBuff,
  409.          TRUE) != XML_OK)
  410.       {
  411.          field->Release(field);
  412.          KB_OSPFree(field);
  413.          field = NULL;
  414.       }
  415.       self->m_ioXML.SkipChar(&self->m_ioXML,endText.m_nDataLength);
  416.       endText.Release(&endText);
  417.       return field;
  418.    }
  419.    return NULL;   
  420. }
  421. int      QXmlParserReadName (QXmlParser *self , QString *Name)
  422. {
  423.    char c;
  424.    assert(self);
  425.    self->m_ioXML.SkipWhiteSpace(&self->m_ioXML);
  426.    // 读出一个字段名.或一个属性名 
  427.    
  428.    self->m_ioXML.GetBuff(&self->m_ioXML,&c,1);
  429.    if ( !self->m_ioXML.IsEmpty(&self->m_ioXML) &&
  430.       ( isalpha( c ) || c == '_') )
  431.    {
  432.       while(   !self->m_ioXML.IsEmpty(&self->m_ioXML)
  433.          &&   (isalnum( c ) 
  434.          || c == '_'
  435.          || c == '-'
  436.          || c == '.'
  437.          || c == ':')){
  438.          Name->AppendChar(Name,c);
  439.          self->m_ioXML.SkipChar(&self->m_ioXML,1);
  440.          self->m_ioXML.GetBuff(&self->m_ioXML,&c,1);      
  441.       }
  442.    }
  443.    return XML_OK;
  444. }
  445. int      QXmlParserReadValue (QXmlParser *self ,                   
  446.                   QString *Value,
  447.                   char *endTag, //以什么结束
  448.                   BOOL conv )   //是否进行 '&' 的转换
  449. {
  450.    char c;
  451.    int endlen = 0;
  452.    QString szHeader;
  453.    QString szConvHeader;
  454.    assert(self);
  455.    if(endTag == NULL)
  456.    {
  457.       self->xml->m_nErrorCode = XML_DATA_EMPTY;
  458.       return self->xml->m_nErrorCode ;
  459.    }
  460.    endlen = strlen(endTag);
  461.    self->m_ioXML.SkipWhiteSpace(&self->m_ioXML);
  462.    self->m_ioXML.GetBuff(&self->m_ioXML,&c,1);   
  463.    szHeader = NewQString();
  464.    szConvHeader = NewQString();
  465.    szHeader.AllocBuffer(&szHeader,endlen);
  466.    while( !self->m_ioXML.IsEmpty(&self->m_ioXML))
  467.    {
  468.       
  469.       szHeader.m_nDataLength = self->m_ioXML.GetBuff(&self->m_ioXML,
  470.          szHeader.m_dataBuff,
  471.          endlen);
  472.       if(szHeader.Equal(&szHeader,endTag))
  473.       {
  474.          //读取结束
  475.          break;
  476.       }
  477.       else
  478.       {
  479.          if(c == '&' && conv)// 需要进行特殊字符转义            
  480.          {
  481.             char tempConv;
  482.             szConvHeader.Release(&szConvHeader);
  483.             while(c != ';' && szConvHeader.m_nDataLength <= 6)
  484.             {
  485.                szHeader.AppendChar(&szConvHeader,c);
  486.                self->m_ioXML.SkipChar(&self->m_ioXML,1);
  487.                self->m_ioXML.GetBuff(&self->m_ioXML,&c,1);   
  488.             }
  489.             
  490.             szConvHeader.AppendChar(&szConvHeader,c);
  491.             
  492.             self->m_ioXML.SkipChar(&self->m_ioXML,1);
  493.             
  494.             tempConv = self->GetEntity(self,szConvHeader.m_dataBuff);
  495.             if(tempConv != '')
  496.                Value->AppendChar(Value,tempConv);   
  497.             else
  498.                Value->AppendString(Value,szConvHeader.m_dataBuff);   
  499.             szConvHeader.Release(&szConvHeader);
  500.          }
  501.          else
  502.          {
  503.             Value->AppendChar(Value,c);   
  504.             self->m_ioXML.SkipChar(&self->m_ioXML,1);
  505.          }
  506.       }
  507.       self->m_ioXML.GetBuff(&self->m_ioXML,&c,1);
  508.    }
  509.    szHeader.Release(&szHeader);
  510.    
  511.    return self->xml->m_nErrorCode;
  512. }
  513. int      QXmlParserReadText (QXmlParser *self , QString *Text)
  514. {
  515.    char c;
  516.    int endLen = strlen(cdataHeader);
  517.    QString szHeader ;
  518.    
  519.    assert(self);
  520.    
  521.    self->m_ioXML.SkipWhiteSpace(&self->m_ioXML);
  522.    
  523.    szHeader = NewQString();
  524.    szHeader.AllocBuffer(&szHeader,endLen);
  525.    szHeader.m_nDataLength = self->m_ioXML.GetBuff(&self->m_ioXML,
  526.                               szHeader.m_dataBuff,
  527.                               endLen);
  528.    if(szHeader.Equal(&szHeader,cdataHeader))
  529.    {
  530.       //<![CDATA[ 除了]]> 其他所有的字符全部正常接收   
  531.       self->m_ioXML.SkipChar(&self->m_ioXML, endLen);
  532.       endLen = strlen(cdataEnd);
  533.       szHeader.Release(&szHeader);
  534.       szHeader.AllocBuffer(&szHeader,endLen);
  535.       self->m_ioXML.GetBuff(&self->m_ioXML,&c,1);
  536.       while(!self->m_ioXML.IsEmpty(&self->m_ioXML))
  537.       {
  538.          self->m_ioXML.GetBuff(&self->m_ioXML,szHeader.m_dataBuff,endLen);
  539.          if(self->m_ioXML.IsEmpty(&self->m_ioXML))
  540.          {
  541.             szHeader.Release(&szHeader);
  542.             self->xml->m_nErrorCode = XML_NO_CDATA_END;
  543.             return self->xml->m_nErrorCode;
  544.          }
  545.       
  546.          if(szHeader.Equal(&szHeader,cdataEnd))
  547.          {
  548.             self->m_ioXML.SkipChar(&self->m_ioXML, endLen);
  549.             szHeader.Release(&szHeader);
  550.             self->m_ioXML.SkipWhiteSpace(&self->m_ioXML);
  551.             break;
  552.          }
  553.          Text->AppendChar(Text,c);
  554.          self->m_ioXML.SkipChar(&self->m_ioXML, 1);
  555.          self->m_ioXML.GetBuff(&self->m_ioXML,&c,1);
  556.       }      
  557.       self->m_nodeCurr->m_nType = HOLD;
  558.    }
  559.    szHeader.Release(&szHeader);
  560.    szHeader.AllocBuffer(&szHeader,2);
  561.    self->m_ioXML.GetBuff(&self->m_ioXML,&c,1);
  562.    while ( !self->m_ioXML.IsEmpty(&self->m_ioXML) )
  563.    {
  564.       self->m_ioXML.SkipWhiteSpace(&self->m_ioXML);
  565.       self->m_ioXML.GetBuff(&self->m_ioXML,&c,1);
  566.       if ( c != '<' )
  567.       {
  568.          // 如果有值的话.先解析值 
  569.          if(self->ReadValue(self,Text,"<",TRUE) != XML_OK)
  570.          {
  571.             szHeader.Release(&szHeader);
  572.             return self->xml->m_nErrorCode;
  573.          }
  574.          else
  575.          {            
  576.             self->m_ioXML.GetBuff(&self->m_ioXML,&c,1);
  577.          //   printf("值[%s]n",Text->m_dataBuff);   
  578.             continue;
  579.          }
  580.       } 
  581.       else 
  582.       {
  583.          // 检查是否还有子节点 
  584.          szHeader.m_nDataLength = self->m_ioXML.GetBuff(&self->m_ioXML,
  585.                               szHeader.m_dataBuff,
  586.                               2);      
  587.          if ( szHeader.Equal(&szHeader, "</") )
  588.          {
  589.             szHeader.Release(&szHeader);
  590.             return XML_OK;
  591.          }
  592.          else
  593.          {
  594.             QXmlNode *node  = MallocQXmlNode();         
  595.             QXmlNode *nodeParent;         
  596.             
  597.             if(!node)
  598.             {
  599.                self->xml->m_nErrorCode = XML_OUT_MEMORY;
  600.                szHeader.Release(&szHeader);
  601.                return self->xml->m_nErrorCode; 
  602.             }
  603.             node->m_nodeParent = self->m_nodeCurr;
  604.             
  605.             nodeParent = node->m_nodeParent;
  606.             self->m_nodeCurr->AddNodeToChild(self->m_nodeCurr,node);
  607.             self->m_nodeCurr = node;
  608.             self->m_ioXML.SkipWhiteSpace(&self->m_ioXML);
  609.             
  610.             if(self->Worker(self) != XML_OK)
  611.             {
  612.                szHeader.Release(&szHeader);
  613.                return self->xml->m_nErrorCode;
  614.             }
  615.             else
  616.             {
  617.                self->m_nodeCurr = nodeParent;   
  618.                continue;
  619.             }
  620.          }
  621.       }
  622.    }
  623.    self->xml->m_nErrorCode = XML_READ_NODE_VALUE;
  624.    szHeader.Release(&szHeader);
  625.    return self->xml->m_nErrorCode;
  626. }
  627. char    QXmlParserGetEntity(QXmlParser *self , char * p)
  628. {
  629.    int i ;
  630.    for( i=0; i<sizeof(entity)/8; i++ )
  631.    {
  632.       if(strcmp(entity[i].str,p) == 0)
  633.       {
  634.          return entity[i].chr;
  635.       }
  636.    }
  637.    return '';
  638. }
  639. void   QXmlParserRelease ( QXmlParser *self)
  640. {
  641.    assert(self);
  642.    self->m_ioXML.Release(&self->m_ioXML);   
  643. }