I know that reading and creating XML files is available in ROOT with TXMLEngine. But what if I want to edit the existing XML file? Particularly, I want to add a child to the existing node. How one could reach this?
I tried the following code:
//some code above
XMLNodePointer_t generalInfo = findChild( "GeneralInfo", mainNode, xml );
XMLNodePointer_t info = xml->NewChild( generalInfo, 0, "Info" );
xml->NewAttr( info, 0, "name", "TrainingSignalEvents");
xml->NewIntAttr( info, "value", 1000 );
xml->SaveDoc( xmldoc, fileName );
xml->FreeDoc( xmldoc );
delete xml;
Where findChild
is function that I wrote to simplify finding of child by name. It worked in this way:
<Info name="TMVA Release" value="4.2.1 [262657]"/>
<Info name="ROOT Release" value="6.08/02 [395266]"/>
<Info name="Creator" value="wolfgang"/>
<Info name="Date" value="Fri Nov 24 23:49:39 2017"/>
<Info name="Host" value="Linux wolfgang-IdeaPad-Z585 4.4.0-81-generic #104~14.04.1-Ubuntu SMP Wed Jun 14 12:45:52 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux"/>
<Info name="Dir" value="/home/wolfgang/BINP/Diploma/Analysis/omega_pi0/Algorithm"/>
<Info name="Training events" value="28324"/>
<Info name="TrainingTime" value="1.15905461e+01"/>
<Info name="AnalysisType" value="Classification"/>
<Info name="TrainingSignalEvents" value="1000"/>
</GeneralInfo>
You see that new child Info
has been added. But I have two questions here. Is it possible to specify where to place new child? And is it a proper way to add new child in the existing file? I mean just SaveDoc
in the end?
UPDATE: One more question. Is it possible to remove single child from the node? If yes, how?
Thanks in advance.