This stage is very busy, often busy, and people catch a cold again. I reported to the driving school two days ago, so I went home from work and tried to take the test next week. In other words, our driving school registration fee is six thousand. Is there any other place in China that is so high?
--------------------------------
Someone asked me how to read the xml document in beta2 the day before yesterday. I just wanted to use the array interface to read it, so I remembered that there was no array after beta.
So since arry was used to read data, can it be read by containers now?
Finally, I found two function interfaces:
ValueVector p_vec = FileUtils::getInstance()->getValueVectorFromFile("label.plist");ValueMap p_map = FileUtils::getInstance()->getValueMapFromFile("label.xml");
So, how to use it. I have written a blog that reads Chinese characters from xml documents,
Next, we will port the Blog Code to the 3.0 beta. I use the ValueVector method.
Transport: http://blog.csdn.net/start530/article/details/18740733
Suppose there is a document named label. xml with the following content:
Id
10
Info
Windy male paper
Id
20
Info
Destined to be lonely
The procedure is as follows:
1. Read the xml document and put the read content on the ValueVector.
2. Get the content in info by id;
3. display the content in info to the label.
Code implementation:
1. Read
ValueVector txt_vec = FileUtils::getInstance()->getValueVectorFromFile("label.xml");
There are two key points: ValueVector. What is this? I can only answer that there is such a line of code in CCValue. h:
typedef std::vector
ValueVector;
Well, the hacker will not be split;
The second key point is to use getValueVectorFromFile (FileName) to read the xml document...
2. extract data
First, extract IDs. Because IDs and their corresponding values are a pair of key values, you can use Map to store them:
auto txt_map = txt_vec.at(0).asValueMap();
Put it in Map and you can use the Map method to read the value of the key "id:
int id_int = txt_map.at("id").asInt();
Finally, make a judgment. If the id value is 10, extract the corresponding key value of info:
if(id_int == 10){auto label_str = txt_map.at("info").asString();}
Well, the process is like this;
3. paste the compiled code
ValueVector txt_vec = FileUtils: getInstance ()-> getValueVectorFromFile ("label. xml "); // read the xml document and put it in ValueVector for (auto & e: txt_vec) {auto txt_map = e. asValueMap (); // convert the key value to the Map format and put it in txt_map. int id_int = txt_map.at ("id "). asInt (); // obtain idif (10 = id_int) {auto label_str = txt_map.at ("info "). asString (); // get the info value auto label1 = LabelTTF: create (label_str, "Arial", 25); label1-> setPosition (Point (160,425 )); this-> addChild (label1, 2);} else if (20 = id_int) {auto label_str = txt_map.at ("info "). asString (); auto label1 = LabelTTF: create (label_str, "Arial", 25); label1-> setPosition (Point (160,400); this-> addChild (label1, 2 );}}
If you are not familiar with Vector and Map, refer to my previous blog:
Vector: Http://blog.csdn.net/start530/article/details/19170853
Map: Http://blog.csdn.net/start530/article/details/19284301
Well, it's the sauce.