场景说明:创建一个空的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" />
居然少了最后的一句!!!!
tinyxml是否存在内存泄露
代码如下:
TiXmlDeclaration * xmlDec = new TiXmlDeclaration("1.0", "UTF-8", "yes");
TiXmlDocument * xmlDocs = new TiXmlDocument();
xmlDocs->LinkEndChild(xmlDec);
TiXmlElement * element = new TiXmlElement("disk");
xmlDocs->LinkEndChild(element);
xmlDocs->SaveFile("myfile.xml");
delete xmlDocs;
动态生成的xmlDec和elemnet没有释放,是否导致内存泄露???
但是释放内粗,导致运行时候程序出现段错误,看来需要查看源代码!!
TiXmlDeclaration * xmlDec = new TiXmlDeclaration("1.0", "UTF-8", "yes");
TiXmlDocument * xmlDocs = new TiXmlDocument();
xmlDocs->LinkEndChild(xmlDec);
TiXmlElement * element = new TiXmlElement("disk");
xmlDocs->LinkEndChild(element);
xmlDocs->SaveFile("myfile.xml");
delete xmlDocs;
delete xmlDec;
delete element;
tinyxml:Could not load test file Error='Error reading Attributes.'. Exiting.
描述:
使用windows写字板编辑任何的xml文件,保存成为纯文本文件导致的问题,是下面
属性完全消失
Could not load test file 'test.xml'.Error='Error reading Attributes.'. Exiting.