summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSilvan Jegen <s.jegen@gmail.com>2016-09-12 18:28:09 +0200
committerSilvan Jegen <s.jegen@gmail.com>2016-09-12 18:45:33 +0200
commit933d3f31965010d90cb09759a00f86618097f0a4 (patch)
tree53aa5f3bcd9f460d0f9bda8b3b4d68d81579e70f
parent7136cf7c9198f6ffb9e693e029143fea460cf760 (diff)
Make sure we are printing the right tag
We have to check that we are in the title-group tag before getting the tag's contents.
-rw-r--r--yxml.c26
1 files changed, 15 insertions, 11 deletions
diff --git a/yxml.c b/yxml.c
index 1fd0f51..d16d070 100644
--- a/yxml.c
+++ b/yxml.c
@@ -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);
}