31 Date() : day(0), month(0), year(0) { }
33 Int_t GetDay()
const {
return day; }
34 Int_t GetMonth()
const {
return month; }
35 Int_t GetYear()
const {
return year; }
37 void SetMonth(
Int_t m) { month=
m;}
38 void SetYear(
Int_t y) { year=
y;}
48 Address(TString s, TString p, TString
c) :
49 street(s), postalCode(p), country(
c) { }
50 TString GetStreet()
const {
return street; }
51 TString GetPostalCode()
const {
return postalCode; }
52 TString GetCountry()
const {
return country; }
53 void SetStreet(
const TString &s) { street = s; }
54 void SetPostalCode(
const TString &p) { postalCode = p; }
55 void SetCountry(
const TString &
c) { country =
c; }
66 id(i), firstName(
f), lastName(
l), gender(
g), dateOfBirth(
d), address(
a){ }
73 TString GetFirstName()
const {
return firstName; }
74 TString GetLastName()
const {
return lastName; }
75 Char_t GetGender()
const {
return gender; }
76 Date *GetDate()
const {
return dateOfBirth; }
77 Address *
GetAddress()
const {
return address; }
78 Int_t GetID()
const {
return id; }
80 friend ostream &
operator << (ostream& out,
const Person& p) {
81 out <<
"ID: " << p.id << endl;
82 out <<
"First name: " << p.firstName << endl;
83 out <<
"Last name: " << p.lastName << endl;
84 out <<
"Sex: " << p.gender << endl;
85 out <<
"Date of birth: " << p.dateOfBirth->GetDay() <<
"/"
86 << p.dateOfBirth->GetMonth() <<
"/"
87 << p.dateOfBirth->GetYear() << endl;
88 out <<
"Address: " << p.address->GetStreet() << endl;
89 out <<
"\t" << p.address->GetPostalCode() << endl;
90 out <<
"\t" << p.address->GetCountry() << endl;
107 listOfPerson =
new TList();
110 Int_t ParseFile(TString filename) {
111 TDOMParser *domParser =
new TDOMParser();
121 ParsePersonList(node);
126 void ParsePersonList(TXMLNode *node) {
134 TIter next(attrList);
135 while ((attr=(TXMLAttr*)next())) {
136 if (strcmp(attr->
GetName(),
"ID") == 0) {
142 listOfPerson->Add(ParsePerson(node->
GetChildren(),
id));
149 Date *ParseDate(TXMLNode *node) {
164 return new Date(
d,
m,
y);
167 Address *ParseAddress(TXMLNode *node) {
174 if (strcmp(node->
GetNodeName(),
"PostalCode") == 0) {
182 return new Address(s, p,
c);
185 Person *ParsePerson(TXMLNode *node,
Int_t id) {
186 TString firstName, lastName;
199 if (strcmp(node->
GetNodeName(),
"DateOfBirth") == 0)
206 return new Person(
id, firstName, lastName, gender, date, address);
209 friend ostream&
operator << (ostream& out,
const PersonList & pl) {
210 TIter next(pl.listOfPerson);
212 while ((p =(Person*)next())){
219 TIter next(listOfPerson);
221 while ((p =(Person*)next())) {
227 Int_t numberOfPersons;
234 PersonList personlist;
235 gROOT->ProcessLine(
".O 0");
237 if (personlist.ParseFile(dir+
"/xml/person.xml") == 0)
238 cout << personlist << endl;
int Int_t
Signed integer 4 bytes (int).
char Char_t
Character 1 byte (char).
TBuffer & operator<<(TBuffer &buf, const Tmpl *obj)
virtual TXMLDocument * GetXMLDocument() const
Returns the TXMLDocument.
Int_t ParseFile(const char *filename) override
Parse the XML file where filename is the XML file name.
Mother of all ROOT objects.
const char * GetValue() const
const char * GetName() const override
Returns name of object.
TXMLNode * GetRootNode() const
Returns the root element node.
TList * GetAttributes()
Returns a list of node's attribute if any, returns 0 if no attribute.
const char * GetText() const
Returns the content of a Text node if node is a TextNode, 0 otherwise.
TXMLNode * GetNextNode()
Returns the next sibling XMLNode in the DOM tree, if any return 0 if no next node.
TXMLNode * GetChildren()
Returns the node's child if any, returns 0 if no child.
const char * GetNodeName() const
Returns the node's name.
Bool_t HasAttributes() const
Returns true if Element node has attribute.
EXMLElementType GetNodeType() const
Returns the node's type.
const char * GetParseCodeMessage(Int_t parseCode) const
Returns the parse code message.
ULong64_t GetAddress(std::vector< std::string > &p)