tinyxml的文件创建

场景说明:创建一个空的xml文件,要求格式如下:

<?xml version="1.0" encoding="UTF-8" ?>

<MyGUI type="Resource" version="1.1">

</MyGUI>

代码如下:

TiXmlElement *RootElement = NULL;    

TiXmlDocument *pDoc = NULL;   

pDoc = new TiXmlDocument();   

TiXmlDeclaration *pDeclaration = new TiXmlDeclaration(("1.0"),("UTF-8"),(""));   

pDoc->LinkEndChild(pDeclaration);    

RootElement = new TiXmlElement(("MyGUI"));   

RootElement->SetAttribute("type","Resource");   

RootElement->SetAttribute("version","1.1");   

pDoc->LinkEndChild(RootElement);    

pDoc->SaveFile("myfile.xml");

delete pDeclaration;

delete pDoc;

结果如下:

<?xml version="1.0" encoding="UTF-8" ?>

<MyGUI type="Resource" version="1.1" />

居然少了最后的一句!!!!



你可能感兴趣的:(version,文件创建)