Lire un fichier xml à l'aide de tinyxml2 en C++

Je ne sais pas comment lire ce fichier xml à l'aide tinyxml2 en C++

<?xml version="1.0" encoding="utf-8"?>
<empleados>
 <cantidad>UnaCantidad</cantidad>
 <empleado>
  <idEmpleado>1</idEmpleado>
  <nombre>UnNombre1</nombre>
  <apellidos>UnosApellidos1</apellidos>
 </empleado>
 <empleado>
  <idEmpleado>2</idEmpleado>
  <nombre>UnNombre2</nombre>
  <apellidos>UnosApellidos2</apellidos>
 </empleado>
</empleados> 

C'est ce que je fais aujourd'hui, ne fonctionne pas:

tinyxml2::XMLDocument xml_doc;

tinyxml2::XMLError eResult = xml_doc.LoadFile(xml_path);
XMLCheckResult(eResult);

tinyxml2::XMLNode* root = xml_doc.FirstChild();
if (root == nullptr) return tinyxml2::XML_ERROR_FILE_READ_ERROR;

tinyxml2::XMLElement* element = root->FirstChildElement("cantidad");
if (element == nullptr) return tinyxml2::XML_ERROR_PARSING_ELEMENT;

int xml_count;
eResult = element->QueryIntText(&xml_count);
XMLCheckResult(eResult);

Empleado* empleados= Empleado[xml_count];

element = root->FirstChildElement("empleado");
Empleado e;
int i = 0;

while (element != nullptr && i < xml_count)
{
    tinyxml2::XMLElement* item = element->FirstChildElement("idEmpleado");
    int id;
    eResult = item->QueryIntText(&id);
    XMLCheckResult(eResult);

    item = element->FirstChildElement("nombre");
    string nombre = item->Gettext();

    item = element->FirstChildElement("apellidos");
    string apellidos = item->Gettext(); 

    e = Empleado();
    e.id = id;
    e.nombre = nombre;
    e.apellidos = apellidos;
    empleados[i] = e;

    element = element->NextSiblingElement("empleado");
    i++;
}

Lorsque j'essaie d'obtenir le premier XMLElement (cantidad) - je obtenir un nullptr. Qu'est ce que je fais mal, s'il vous plaît aidez-moi...

InformationsquelleAutor fbr | 2015-04-03