好的,所以你知道如何加载文件:
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("...");
正如我所提到的,您必须解析元素才能到达正确的节点。
在线自述文件还指出:
查找信息。
/* ------ 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 );
}