test_read.c (1103B)
1 /* 2 * Copy me if you can. 3 * by 20h 4 */ 5 6 #ifndef PLAN9 7 #include <stdio.h> 8 #include <stdlib.h> 9 #include <fcntl.h> 10 #endif 11 #ifdef PLAN9 12 #include <u.h> 13 #include <libc.h> 14 #endif 15 #include "xmlpull.h" 16 17 void 18 main(int argc, char *argv[]) 19 { 20 xmlpull *ret, *b; 21 int fd; 22 23 if(argc < 2){ 24 print("usage: filename\n"); 25 exits(0); 26 } 27 28 fd = open(argv[1], 29 #ifndef PLAN9 30 O_RDONLY); 31 #endif 32 #ifdef PLAN9 33 OREAD); 34 #endif 35 if(fd < 0){ 36 perror("open"); 37 exits(0); 38 } 39 40 ret = openxmlpull(fd); 41 while((b = nextxmlpull(ret)) != nil){ 42 switch(b->ev){ 43 case START_DOCUMENT: 44 print("Document started.\n"); 45 break; 46 case START_TAG: 47 print("Tag starts: %s\n", b->na); 48 break; 49 case START_END_TAG: 50 print("Startend tag: %s\n", b->na); 51 break; 52 case TEXT: 53 print("Text: %s\n", b->na); 54 break; 55 case ATTR: 56 print("Attr: %s=%s\n", b->na, (b->va == nil) ? "none" : b->va); 57 break; 58 case END_TAG: 59 print("Tag ends: %s\n", b->na); 60 break; 61 case END_DOCUMENT: 62 print("Document ends.\n"); 63 break; 64 default: 65 print("Undocumented: %x\n", b->ev); 66 break; 67 } 68 } 69 70 freexmlpull(ret); 71 exits(0); 72 } 73