11#include "TDOMParser.h"
12#include "TXMLEngine.h"
17 fChildren.SetOwner(kTRUE);
18 fAttrib.SetOwner(kTRUE);
23 for(
int i=0;
i<other.fChildren.GetEntries();
i++){
26 for(
int i=0;
i<other.fAttrib.GetEntries();
i++){
34 SetName(other.GetName());
38 for(
int i=0;
i<other.fChildren.GetEntries();
i++){
41 for(
int i=0;
i<other.fAttrib.GetEntries();
i++){
50 SetName(node->GetNodeName());
51 SetTitle(node->GetText());
52 if(node->HasChildren()){
53 TXMLNode *child = node->GetChildren();
55 if(child==NULL)
break;
56 TString name = child->GetNodeName();
59 tempnode->
Copy(child);
60 fChildren.Add(tempnode);
62 if(child->HasNextNode())
63 child=child->GetNextNode();
64 }
while(child->HasNextNode());
66 if(node->HasAttributes()){
67 TList *atr_list = node->GetAttributes();
68 for(
int i=0;
i<atr_list->GetEntries();
i++){
69 TXMLAttr *atrib = (TXMLAttr*)atr_list->At(
i);
70 fAttrib.Add(
new MpdXMLAttrib(atrib->GetName(),atrib->GetValue()));
76 TString new_atr = attrib->GetName();
78 std::cout<<
"MpdXMLNode::AddAttrib Can't have two attributes with the same name!"<<std::endl;
81 fAttrib.AddLast(attrib);
87 TString name_temp =
GetChild(
i)->GetName();
96 Int_t control_index = 0;
97 for(
int i=0;
i<fChildren.GetEntries();
i++){
99 TString temp = node->GetName();
103 if(control_index>count)
110 return static_cast<MpdXMLAttrib*
>(fAttrib.FindObject(name));
114 return static_cast<MpdXMLNode*
>(fChildren.At(index));
127 if(mode==
"read"||mode==
"READ"){
130 Parser.SetValidate(kFALSE);
131 Parser.ParseFile(name);
132 TXMLNode *MainNode = Parser.GetXMLDocument()->GetRootNode();
134 fRootNode->Copy(MainNode);
145 fRootNode.reset(node);
151 std::cout<<
"MpdXMLFile::Close() No root node!"<<std::endl;
155 XMLNodePointer_t mainnode = engine.NewChild(0, 0, fRootNode->GetName());
156 ExportNode(mainnode,engine,*fRootNode.get());
157 XMLDocPointer_t xmldoc = engine.NewDoc();
158 engine.DocSetRootElement(xmldoc,mainnode);
159 engine.SaveDoc(xmldoc,fName);
160 engine.FreeDoc(xmldoc);
161 fRootNode.reset(
nullptr);
165void MpdXMLFile::ExportNode(XMLNodePointer_t& nodePointer,
166 TXMLEngine &engine,
const MpdXMLNode &node)
const {
169 for(
int j=0;j<node.
GetChild(
i)->GetNAttributes();j++){
172 ExportNode(child,engine,*node.
GetChild(
i));
177 if(fRootNode&&fOverwrite)
void CreateRootNode(TString name)
MpdXMLFile(TString name="", TString mode="read")
void SetRootNode(MpdXMLNode *node)
void AddAttrib(MpdXMLAttrib *attrib)
void Copy(TXMLNode *node)
MpdXMLNode & operator=(const MpdXMLNode &other)
MpdXMLNode * GetChild(TString name, Int_t count=0) const
MpdXMLAttrib * GetAttrib(TString name) const
Int_t GetNChildren() const
MpdXMLNode(const MpdXMLNode &other)
void SetValue(TString value)