12#include <TDOMParser.h>
14#include <TXMLDocument.h>
20 fChildren.SetOwner(kTRUE);
21 fAttrib.SetOwner(kTRUE);
25 for (
int i = 0; i < other.fChildren.GetEntries(); i++) {
28 for (
int i = 0; i < other.fAttrib.GetEntries(); i++) {
34 if (&other ==
this)
return *
this;
35 SetName(other.GetName());
39 for (
int i = 0; i < other.fChildren.GetEntries(); i++) {
42 for (
int i = 0; i < other.fAttrib.GetEntries(); i++) {
51 SetName(node->GetNodeName());
52 SetTitle(node->GetText());
53 if (node->HasChildren()) {
54 TXMLNode* child = node->GetChildren();
56 if (child ==
nullptr)
break;
57 TString name = child->GetNodeName();
60 tempnode->
Copy(child);
61 fChildren.Add(tempnode);
63 if (child->HasNextNode()) 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 XMLAttrib(atrib->GetName(), atrib->GetValue()));
76 TString new_atr = attrib->GetName();
78 std::cout <<
"XMLNode::AddAttrib Can't have two attributes with the same name!" << std::endl;
81 fAttrib.AddLast(attrib);
87 TString name_temp =
GetChild(i)->GetName();
88 if (name_temp == name) { counter++; }
94 Int_t control_index = 0;
95 for (
int i = 0; i < fChildren.GetEntries(); i++) {
97 TString temp = node->GetName();
98 if (temp == name) { control_index++; }
99 if (control_index > count)
return node;
110 XMLNode::~XMLNode() {}
115 if (mode ==
"read" || mode ==
"READ") {
118 Parser.SetValidate(kFALSE);
119 Parser.ParseFile(name);
120 TXMLNode* MainNode = Parser.GetXMLDocument()->GetRootNode();
121 fRootNode.reset(
new XMLNode());
122 fRootNode->Copy(MainNode);
135 std::cout <<
"HalXMLFile::Close() No root node!" << std::endl;
139 XMLNodePointer_t mainnode = engine.NewChild(0, 0, fRootNode->GetName());
140 ExportNode(mainnode, engine, *fRootNode.get());
141 XMLDocPointer_t xmldoc = engine.NewDoc();
142 engine.DocSetRootElement(xmldoc, mainnode);
143 engine.SaveDoc(xmldoc, fName);
144 engine.FreeDoc(xmldoc);
148 void XMLFile::ExportNode(XMLNodePointer_t& nodePointer, TXMLEngine& engine,
const XMLNode& node)
const {
150 XMLNodePointer_t child = engine.NewChild(nodePointer, 0, node.
GetChild(i)->GetName(), node.
GetChild(i)->
GetValue());
151 for (
int j = 0; j < node.
GetChild(i)->GetNAttributes(); j++) {
154 ExportNode(child, engine, *node.
GetChild(i));
159 if (fRootNode && fOverwrite)
Close();
void CreateRootNode(TString name)
XMLFile(TString name="", TString mode="read")
void SetRootNode(XMLNode *node)
void Copy(TXMLNode *node)
Int_t GetNChildren() const
void SetValue(TString value)
XMLNode * GetChild(TString name, Int_t count=0) const
XMLAttrib * GetAttrib(TString name) const
XMLNode(const XMLNode &other)
XMLNode & operator=(const XMLNode &other)
void AddAttrib(XMLAttrib *attrib)