2011-12-14 34 views
0

在我的项目中,我需要将新数据附加到xml,所以我这样做如下: 问题是LoadFile()函数是如此之慢xml文件很大,而high-cpu,SaveFile()也有同样的问题。所以,我应该如何加快我的项目。 感谢您的帮助:)加载大文件时如何加速使用Tinyxml中的Loadfile()

 TiXmlDocument doc(m_filePath.c_str()); 
    (void)doc.LoadFile(); //here is slowly 
    if (doc.Error() && (doc.ErrorId()==TiXmlBase::TIXML_ERROR_OPENING_FILE)) 
    { 
     ATS_LOG(ERROR, "Can not open the file:%s", m_filePath.c_str()); 
     result = false; 
    } 
    else 
    { 
     const TiXmlHandle docH(&doc); 
     TiXmlElement* const element = docH.FirstChildElement("HistoryMsgs").Element(); 
     TiXmlNode* const pNode=element->ToElement(); 
     if (pNode!=NULL) 
     { 
          //do something that insert new node; 
      (void)doc.SaveFile(m_filePath.c_str());//here is slowly too 
     } 
    } 

回答

0

TinyXML的有相当一些性能问题。 RapidXML和PugiXML更受欢迎。我不确定将代码移植到新的解析器是多么容易,但是我在使用TinyXML后遇到了性能问题,然后切换到了PugiXML。您可以查看关于C++解析器的讨论: What is the best open XML parser for C++?

相关问题