耐心吗,细心吗,有执行力吗
tingXml
下载:https://sourceforge.net/projects/tinyxml/
读 (解析XML)
try
{
//TiXmlDocument *myDocument = new TiXmlDocument(fullPath.c_str());//这样最后要delete myDocument
//myDocument->LoadFile();
TiXmlDocument doc;
//doc.LoadFile("info.xml");
string str("<Persons>\
<Person ID = '1' other = 'info'>\
<name>Michael</name>\
<age>23</age>\
</Person>\
</Persons>");
doc.Parse(str.c_str());//解析xml字符串
TiXmlElement *RootElement = doc.RootElement();
string root = RootElement->Value();
TiXmlElement *FirstPerson = RootElement->FirstChildElement();
TiXmlElement *NameElement = FirstPerson->FirstChildElement();
TiXmlElement *AgeElement = NameElement->NextSiblingElement();
TiXmlAttribute *IDAttribute = FirstPerson->FirstAttribute();
string name = NameElement->FirstChild()->Value();//或NameElement->GetText()
string age = AgeElement->FirstChild()->Value();//或AgeElement->GetText()
string attrName = IDAttribute->Name(); //"ID"
string attrValue = IDAttribute->Value(); //"1"
attrName = IDAttribute->Next()->Name(); //"other"
attrValue = IDAttribute->Next()->Value();//"info"
//delete myDocument;
}
catch (string& e)
{
return false;
}
return true;
写(生成XML)
try
{
TiXmlDocument *myDocument