Dear Root People,
I’m trying to use the XML Parser inserted in Root, but I’m experiencing some troubles.
I try to explain you what I would like to do. I am describing the
geometry of a telescope with a xml file. My telescope is defined by a
set of modules.
In my main file, when i build the Telescope, I have these lines:
TDOMParser *domParser = new TDOMParser();
domParser->SetValidate(false);
Int_t parsecode = domParser->ParseFile(inTelfile);
if (parsecode < 0) {
cerr << domParser->GetParseCodeMessage(parsecode) << endl;
return -1;
}
TXMLNode *xTelescope = domParser->GetXMLDocument()->GetRootNode();
Telescope MyTelescope(xTelescope);
Then the Telescope class has a constructor that call a function called
ParseTelescope that reads the xml file. Here is the function I wrote:
void ParseTelescope(TXMLNode *XMLin) {
if (strcmp(XMLin->GetNodeName(), "TELESCOPE") == 0) {
TList *attrList = XMLin->GetAttributes();
TXMLAttr *attr = 0;
TIter next(attrList);
while ((attr=(TXMLAttr*)next())) {
if (strcmp(attr->GetName(), "No_OM") == 0) {
NumberOfModules = atoi(attr->GetValue());
cout<<"Reading The Telescope: No of OM = "<<NumberOfModules<<endl;
break;
}
if(strcmp(XMLin->GetChildren()->GetNodeName(), "MOD") == 0 ){
for (int i=0; i < NumberOfModules; i++) {
push_back(new Abstract_Module(XMLin->GetChildren()));
}
}
}
}
}
The first part is working fine, but what it doesn’t work and I cannot
understand why, it the GetChildren().
I want to read what is in the “MOD” node. But if I call
XMLin->GetChildren()->GetNodeName() it returns the string “text”, and I
don’t understand why. What should I do to pass from “TELESCOPE” to “MOD”?
Please, help!
First lines of the xml file:
[code]<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
30 4.705 -0.525 453.863 -0.78028 0 [/code]