2011-12-14 62 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++?