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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
|
#include <stdlib.h>
#include <string.h>
#include <libxml/parser.h>
#pragma comment(lib,"libxml2.lib")
#define MAX 10
#define END -1
typedef struct {
int Object_Ref[MAX];
int Attribute_Ref[MAX];
int Concept_Ref[MAX];
} _Concept;
typedef struct {
int id;
_Concept *concept;
} Concept;
enum ElmtType { ID, OBJ_REF, ATTR_REF, CONCPT_REF, AUTRE };
enum ElmtType cur_elmt = AUTRE;
_Concept *p_concept;
int cpt = 0;
int nbIntent = 0;
char *balise;
void debut_element(void *user_data, const xmlChar *name, const xmlChar **attrs) {
if (!xmlStrcmp(name, "Lattice")) {
if(attrs != NULL)
nbIntent = atoi(attrs[5]);
}
if(!xmlStrcmp(name, "Intent"))
cpt++;
if(!xmlStrcmp(name,"Attribute_Ref")) {
balise = (char *) malloc( sizeof(char)*(strlen("Attribute_Ref") + 1));
strcpy(balise,name);
}
}
void caracteres(void *user_data, const xmlChar *ch, int len) {
if(cpt == nbIntent && strcmp(balise, "Attribute_Ref"))
printf(" Attribute_REf : %s\n",ch);
}
void fin_element(void *user_data, const xmlChar *name)
{
cur_elmt = AUTRE;
}
Concept* Concept_Load(const char *path, Concept *c)
{
xmlSAXHandler sh = { 0 };
sh.startElement = debut_element;
sh.characters = caracteres;
sh.endElement = fin_element;
if (xmlSAXUserParseFile(&sh, c, path) != 0)
return NULL;
return c;
}
int main(void)
{
int i;
Concept c[] = { {11,NULL}, {6,NULL}, {78,NULL}, {END,NULL} };
Concept_Load("essai.xml",c);
for (i=0; c[i].id != END; i++)
{
printf("-- Concept --\n");
printf("ID = %d\n",c[i].id);
if (c[i].concept != NULL)
{
int j=0;
printf("Object Ref : ");
while (c[i].concept->Object_Ref[j] != END)
printf("%d ",c[i].concept->Object_Ref[j++]);
printf("\n");
j=0;
printf("Attribute Ref : ");
while (c[i].concept->Attribute_Ref[j] != END)
printf("%c ",c[i].concept->Attribute_Ref[j++]);
printf("\n");
j=0;
printf("Concept Ref : ");
while (c[i].concept->Concept_Ref[j] != END)
printf("%d ",c[i].concept->Concept_Ref[j++]);
printf("\n\n");
}
else
printf("pas trouve.\n");
}
return 0;
} |