Create FUNDING.yml
[wdl/wdl-ol.git] / WDL / xmlparse_test.cpp
blobd461918c0fae19310ebcf17e9a9fc9a07b41de7f
1 #include <string.h>
2 #include <stdlib.h>
3 #include <stdio.h>
4 #include "xmlparse.h"
6 void indent(int depth) { while (depth--) printf(" "); }
8 void dump_element(int depth, wdl_xml_element *elem)
10 if (!elem) return;
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");
15 int x;
16 for(x=0;x<elem->attributes.GetSize();x++)
18 const char *key=NULL;
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");
30 int x;
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)
40 if (argc != 2)
42 printf("Usage: xmlparse_test filename.xml\n");
43 return 1;
45 FILE *fp = fopen(argv[1],"r");
46 wdl_xml_fileread fr(fp);
47 const char *err = fr.parse();
48 if (err)
50 printf("parse error line %d, col %d: %s\n", fr.getLine(),fr.getCol(), err);
51 return 1;
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);
56 return 0;