0

In my project I need append new data to a xml, so I do it like below: the question is the LoadFile() funcation is so slowly when the xml file is large, and high-cpu, the SaveFile() have same problem. So, How should I speed up in my project. Thanks you help:)

        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
        }
    }
TiFang
  • 13
  • 1
  • 5

1 Answers1

0

TinyXML has quite some performance issues. RapidXML and PugiXML are more preferred. I'm not sure how easy would it be to port your code to a new parser, but I had performance issues once with TinyXML and then switched to PugiXML. You might check out a discussion on C++ parsers on: What is the best open XML parser for C++?

Community
  • 1
  • 1
mots_g
  • 637
  • 8
  • 27