6 void indent(int depth
) { while (depth
--) printf(" "); }
8 void dump_element(int depth
, wdl_xml_element
*elem
)
11 indent(depth
); printf("element: %s (line %d col %d)\n",elem
->name
,elem
->line
,elem
->col
);
12 if (elem
->attributes
.GetSize())
14 indent(depth
+1); printf("attributes:\n");
16 for(x
=0;x
<elem
->attributes
.GetSize();x
++)
19 const char *value
=elem
->attributes
.Enumerate(x
,(char **)&key
);
20 indent(depth
+2); printf("%s=%s\n",key
,value
);
23 if (elem
->value
.GetLength())
25 indent(depth
+1); printf("value: %s\n",elem
->value
.Get());
27 if (elem
->elements
.GetSize())
29 indent(depth
+1); printf("elements:\n");
31 for(x
=0;x
<elem
->elements
.GetSize();x
++)
33 dump_element(depth
+2,elem
->elements
.Get(x
));
38 int main(int argc
, const char **argv
)
42 printf("Usage: xmlparse_test filename.xml\n");
45 FILE *fp
= fopen(argv
[1],"r");
46 wdl_xml_fileread
fr(fp
);
47 const char *err
= fr
.parse();
50 printf("parse error line %d, col %d: %s\n", fr
.getLine(),fr
.getCol(), err
);
53 printf("doctype: %s\n",fr
.element_doctype_tokens
.Get(0));
54 dump_element(0, fr
.element_xml
);
55 dump_element(0, fr
.element_root
);