how to write data TINYXML2 on IOS cocos2d-x

My test.xml like this:

    5
    1
    2

My Code here:

std::string fullPath = CCFileUtils::sharedFileUtils()->fullPathFromRelativePath("text.xml"); tinyxml2::XMLDocument doc;

    doc.LoadFile(fullPath.c_str());


tinyxml2::XMLElement* ele =  doc.FirstChildElement("data")->FirstChildElement("BestScoreLV2")->ToElement();
    ele->SetAttribute("value", 10);
    doc.SaveFile(fullPath.c_str());

    const char* title1 =  doc.FirstChildElement("data")->FirstChildElement("BestScoreLV2")->GetText();
    int level1  = atoi(title1);
    CCLOG("result is: %d",level1);

But value of BestScoreLV2 when output is also 2. How can I change and write data to XML?

You can refer to cocos2dx/support/user_default/CCUserDefault.cpp.

dear minggo Zhang,
In my game, i want to save current level, and when out game, data still saved. Maybe CCUserDefault cannot save data when game out

CCUserDefault can save data when game out.

do i call flush() when change?

Yep, you can call flush when all data are saved.

yeah, i did it, any change must call flush_, before i don’t know it