1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| #include <tinyxml.h>
using namespace std;
TiXmlDocument doc("users.xml");
if(!doc.LoadFile()){
cerr << "erreur lors du chargement" << endl;
cerr << "error #" << doc.ErrorId() << " : " << doc.ErrorDesc() << endl;
return 1;
}
class user{
public:
string name, pass;
int droits;
};
list<user> user_list;
TiXmlElement *elem = doc.FirstChildElement()->FirstChildElement();
TiXmlHandle hdl(&doc);
TiXmlElement *elem = hdl.FirstChildElement().FirstChildElement().Element();
user cl;
if(!elem){
cerr << "le noeud à atteindre n'existe pas" << endl;
return 2;
}
while (elem){
cl.name = elem->Attribute("name");
cl.pass = elem->Attribute("pass");
elem->QueryIntAttribute("indice", &cl.droits);
user_list.push_back(cl);
elem = elem->NextSiblingElement(); // iteration
}
list<user>::iterator i;
for(i=user_list.begin(); i!=user_list.end(); i++)
cout << i->name << " " << i->pass << " " << i->droits << endl; |