#include "tinyxml.h"
#include <iostream>
int main()
{
TiXmlDocument doc("example.xml");
bool loadOkay = doc.LoadFile();
if (!loadOkay)
{
std::cout << "Could not load file 'example.xml'. Error='" << doc.ErrorDesc() << "'. Exiting.\n";
return 1;
}
TiXmlElement* root = doc.FirstChildElement("root");
if (!root)
{
std::cout << "Failed to load root element. Exiting.\n";
doc.Clear();
return 1;
}
TiXmlElement* chsetpara = root->FirstChildElement("CHSetPara");
while (chsetpara)
{
const char* ch_attr = chsetpara->Attribute("CH");
if (ch_attr && std::stoi(ch_attr) == 2) // find CHSetPara element with CH attribute equal to 2
{
TiXmlElement* current = chsetpara->FirstChildElement("current");
if (current)
{
current->SetText("2000"); // set the text value of <current> to "2000"
break;
}
}
chsetpara = chsetpara->NextSiblingElement("CHSetPara");
}
doc.SaveFile("example.xml");
return 0;
}