I was able to follow example code to change 1 element value but dont know how to proceed changing other elements text.
void setXML(unsigned short voltage_value, unsigned int current_value){
XMLError eresult = xmlDoc.LoadFile("SavedData.xml");
if (eresult != XML_SUCCESS){
printf("Error: %i\n", eresult);
}
XMLNode * pRoot = xmlDoc.FirstChild();
XMLElement * pElement = pRoot->FirstChildElement("Voltage");
if (pElement == 0) {
printf("Error");
}
else{
pElement->SetText(voltage_value);
//xmlDoc.SaveFile("/var/www/html/SavedData.xml");
}
pElement = pElement->NextSiblingElement("Current");
if (pElement == 0) {
printf("Error");
}
else{
pElement->SetText(current_value);
}
xmlDoc.SaveFile("/var/www/html/SavedData.xml");
}
<Battery_1>
<Voltage>13.5</Voltage>
<Current>1.5</Current>
<Watt>22.5</Watt>
<AmpHr>3.5</AmpHr>
<Time>79345</Time>
<Date day="11" month="7" year="2019"/>
</Battery_1>
<Battery_2>
<Voltage>13.8</Voltage>
<Current>1.4</Current>
<Watt>20.5</Watt>
<AmpHr>3.1</AmpHr>
<Time>79345</Time>
<Date day="11" month="7" year="2019"/>
</Battery_2>
Actually I will want to update all values other than the battery tag.
FirstChildElement("Voltage")
always found and I can change its text, can't figure out how to go to next element or just randomly for example to the 4th "AmpHr"
and change its value/text.
2nd pElement
always 0 so its just print error;
Looking to make it simple as possible, readable and easy to understand, I'm new to this.