c++ - how to write data TINYXML2 on IOS -
my test.xml this:
<?xml version="1.0"?> <!doctype play system "play.dtd"> <data> <currentlevel>5</currentlevel> <bestscorelv1>1</bestscorelv1> <bestscorelv2>2</bestscorelv2> </data> <dict/>
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 2. how can change , write data xml?
in tinyxml2 text represented xmltext
class child of xmlnode
class. xmlnode
have methods value()
, setvalue()
have different meanings different xml nodes. text nodes value()
read node's text , setvalue()
write it. need code this:
tinyxml2::xmlnode* value = doc.firstchildelement("data")-> firstchildelement("bestscorelv2")->firstchild(); value->setvalue("10");
the first child of bestscorelv2
element xmltext
value 2
. change value 10
calling setvalue(10)
.
Comments
Post a Comment