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 35 36 37 38 39 40 41 42
| static int nb_wp = 0;
typedef struct
{
char wp_nom[5];
int wp_x;
int wp_y;
} s_waypoint;
s_waypoint *waypoints;
void import_wp()
{
xmlDoc *doc = xmlReadFile("basic.xml", NULL, 0);
if (doc == NULL)
{
g_print("Le fichier xml n'existe pas.\n");
} else
{
xmlNode *xmlroot = xmlDocGetRootElement(doc)->children;
xmlNode *current = NULL;
int i = 0;
for (current=xmlroot; current != NULL; current=current->next)
{
if (strcmp((char*)current->name, "targetpoint") == 0)
{
nb_wp++;
}
}
waypoints = malloc(nb_wp*sizeof(s_waypoint));
for (current=xmlroot; current != NULL; current=current->next)
{
printf("%s\n", (const char*) xmlGetProp(current, (const xmlChar*)"label"));
strcpy(waypoints[i].wp_nom, (const char*) xmlGetProp(current, (const xmlChar*)"label"));
i++;
}
xmlFreeDoc(doc);
xmlCleanupParser();
}
} |