12 #include <TDOMParser.h>
14 #include <TXMLDocument.h>
16 #include <fairlogger/Logger.h>
22 fChildren.SetOwner(kTRUE);
23 fAttrib.SetOwner(kTRUE);
29 for (
int i = 0; i < other.fChildren.GetEntries(); i++) {
32 for (
int i = 0; i < other.fAttrib.GetEntries(); i++) {
41 SetName(other.GetName());
45 for (
int i = 0; i < other.fChildren.GetEntries(); i++) {
48 for (
int i = 0; i < other.fAttrib.GetEntries(); i++) {
58 SetName(node->GetNodeName());
59 SetTitle(node->GetText());
60 if (node->HasChildren()) {
61 TXMLNode* child = node->GetChildren();
65 TString name = child->GetNodeName();
68 tempnode->
Copy(child);
69 fChildren.Add(tempnode);
71 if (child->HasNextNode())
72 child = child->GetNextNode();
73 }
while (child->HasNextNode());
75 if (node->HasAttributes()) {
76 TList* atr_list = node->GetAttributes();
77 for (
int i = 0; i < atr_list->GetEntries(); i++) {
78 TXMLAttr* atrib = (TXMLAttr*)atr_list->At(i);
79 fAttrib.Add(
new FairXMLAttrib(atrib->GetName(), atrib->GetValue()));
86 TString new_atr = attrib->GetName();
88 LOG(error) <<
"FairXMLNode::AddAttrib Can't have two attributes with the same name!";
91 fAttrib.AddLast(attrib);
98 TString name_temp =
GetChild(i)->GetName();
99 if (name_temp == name) {
108 Int_t control_index = 0;
109 for (
int i = 0; i < fChildren.GetEntries(); i++) {
111 TString temp = node->GetName();
115 if (control_index > count)
123 return static_cast<FairXMLAttrib*
>(fAttrib.FindObject(name));
137 if (mode ==
"read" || mode ==
"READ") {
140 Parser.SetValidate(kFALSE);
141 Parser.ParseFile(name);
142 TXMLNode* MainNode = Parser.GetXMLDocument()->GetRootNode();
144 fRootNode->Copy(MainNode);
158 LOG(error) <<
"FairXMLFile::Close() No root node!";
162 XMLNodePointer_t mainnode = engine.NewChild(0, 0, fRootNode->GetName());
163 ExportNode(mainnode, engine, *fRootNode.get());
164 XMLDocPointer_t xmldoc = engine.NewDoc();
165 engine.DocSetRootElement(xmldoc, mainnode);
166 engine.SaveDoc(xmldoc, fName);
167 engine.FreeDoc(xmldoc);
168 fRootNode.reset(
nullptr);
172 void FairXMLFile::ExportNode(XMLNodePointer_t& nodePointer, TXMLEngine& engine,
const FairXMLNode& node)
const
175 XMLNodePointer_t child =
181 ExportNode(child, engine, *node.
GetChild(i));
187 if (fRootNode && fOverwrite)
Int_t GetNChildren() const
Int_t GetNAttributes() const
FairXMLFile(TString name="", TString mode="read")
FairXMLNode(const FairXMLNode &other)
FairXMLAttrib * GetAttrib(TString name) const
void Copy(TXMLNode *node)
FairXMLNode & operator=(const FairXMLNode &other)
void SetRootNode(FairXMLNode *node)
FairXMLNode * GetChild(TString name, Int_t count=0) const
void SetValue(TString value)
void CreateRootNode(TString name)
void AddAttrib(FairXMLAttrib *attrib)