diff options
-rw-r--r-- | yxml.c | 26 |
1 files changed, 15 insertions, 11 deletions
@@ -43,7 +43,7 @@ buffer *buffer_append(buffer *buf, char *data) { int process(char *fn, yxml_t *state) { size_t filelen; char *parsebuffer; - int inelement; + int intitlegroup, inarticletitle; buffer *contentbuf; FILE* f = fopen(fn, "rb"); @@ -74,7 +74,9 @@ int process(char *fn, yxml_t *state) { fclose(f); - inelement = 0; + intitlegroup = 0; + inarticletitle = 0; + contentbuf = buffer_new(); yxml_init(state, state+1, BUFSIZE); @@ -82,8 +84,6 @@ int process(char *fn, yxml_t *state) { for (; *parsebuffer; parsebuffer++) { yxml_ret_t r = yxml_parse(state, *parsebuffer); - //fprintf(stderr, "parse_state: %d\n", r); - if(r < 0) { printf("Parsing error at %s: line %u, byte %lu, offset %lu\n", fn, state->line, state->byte, state->total); @@ -92,22 +92,26 @@ int process(char *fn, yxml_t *state) { switch(r) { case YXML_ELEMSTART: - if (!strcmp(state->elem, "article-title")) { - printf("start: %s\n", state->elem); - inelement = 1; + if (!strcmp(state->elem, "title-group")) { + intitlegroup = 1; + } else if (!strcmp(state->elem, "article-title") && intitlegroup) { + printf("%s: ", state->elem); + inarticletitle = 1; } break; case YXML_CONTENT: - if (inelement) { + if (inarticletitle) { buffer_append(contentbuf, state->data); } break; case YXML_ELEMEND: - printf("elementend: %s\n", state->elem); - if (inelement) { - inelement = 0; + // Since article-title should not be nested, + // we don't have to check the element name here. + if (inarticletitle && intitlegroup) { + inarticletitle = 0; + intitlegroup = 0; printf("%s\n", contentbuf->buffer); buffer_reset(contentbuf); } |