4
我想用TinyXML2创建一个XML文件。虽然有很多关于加载的示例和教程,但在保存方面似乎很少。 我基本上要直到结束:在tinyxml2中添加文本
<node>text</node>
我知道我可以通过添加elment获得“节点”的部分,但我如何设置文本的一部分?元素有一个“GetText”,但我不能找到“SetText”。还有一个XMLText类,但没有设置文本的方法!
我想用TinyXML2创建一个XML文件。虽然有很多关于加载的示例和教程,但在保存方面似乎很少。 我基本上要直到结束:在tinyxml2中添加文本
<node>text</node>
我知道我可以通过添加elment获得“节点”的部分,但我如何设置文本的一部分?元素有一个“GetText”,但我不能找到“SetText”。还有一个XMLText类,但没有设置文本的方法!
我在OS X 10.6上用G ++ 4.2.1构建,运行良好。输出是<Version>1.0.0</Version>
。
#include "tinyxml2.h"
using namespace tinyxml2;
int main(int argc, char* argv[])
{
tinyxml2::XMLDocument doc;
tinyxml2::XMLElement* versionNode = doc.NewElement("Version");
tinyxml2::XMLText* versionText = doc.NewText("1.0.0");
versionNode->InsertEndChild(versionText);
doc.InsertEndChild(versionNode);
XMLPrinter printer;
doc.Print();
return 0;
}