我想这样做:
<dog colour="brown">
<dog colour="brown">Baow!</dog>
到<dog colour="brown">Waow!</dog>
。
所有这一切都必须使用TinyXML2完成。到目前为止,我只能打开文件:
XMLDocument file;
file.LoadFile("file.xml");
如果你能帮助我会很棒。
答案 0 :(得分:0)
好的,所以你知道如何加载文件:
XMLDocument file;
file.LoadFile("file.xml");
我们不知道您的XML文件的语法。但你必须走下去扔掉元素。
XMLElement *pDog = file.FirstChildElement("dog");
if(pDog != null)
{
if(pDog->Attribute("colour") == "brown)
{
pDog->SetText("Waow!");
}
}
file.SaveFile("...");
正如我所提到的,你必须解析元素才能到达正确的节点。
在线readme file还声明:
查找信息。
/* ------ Example 2: Lookup information. ---- */ { XMLDocument doc; doc.LoadFile( "dream.xml" ); // Structure of the XML file: // - Element "PLAY" the root Element, which is the // FirstChildElement of the Document // - - Element "TITLE" child of the root PLAY Element // - - - Text child of the TITLE Element // Navigate to the title, using the convenience function, // with a dangerous lack of error checking. const char* title = doc.FirstChildElement( "PLAY" )->FirstChildElement( "TITLE" )->GetText(); printf( "Name of play (1): %s\n", title ); // Text is just another Node to TinyXML-2. The more // general way to get to the XMLText: XMLText* textNode = doc.FirstChildElement( "PLAY" )->FirstChildElement( "TITLE" )->FirstChild()->ToText(); title = textNode->Value(); printf( "Name of play (2): %s\n", title ); }