From d0f553d573a269abc7eef70564141557015cc230 Mon Sep 17 00:00:00 2001 From: Silvan Jegen Date: Tue, 13 Sep 2016 19:28:25 +0200 Subject: Fix mxml program Now I figured out how to print all text fragments. --- mxml.c | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/mxml.c b/mxml.c index df49af4..dd99ad9 100644 --- a/mxml.c +++ b/mxml.c @@ -23,46 +23,48 @@ mxml_type_t type_cb(mxml_node_t *node) { int process(FILE *f) { mxml_node_t *root, *node, *next; const char* elename; + int space = 0; root = mxmlLoadFile(NULL, f, MXML_TEXT_CALLBACK); - elename = mxmlGetElement(root); - if (elename) - printf("%s\n", elename); node = mxmlFindElement(root, root, "title-group", NULL, NULL, MXML_DESCEND); - elename = mxmlGetElement(node); - if (elename) - printf("%s\n", elename); - while ((next = mxmlWalkNext(node, root, MXML_DESCEND))) { elename = mxmlGetElement(next); - if (elename) { - printf("%s\n", elename); - if (!strcmp(elename, "article-title")) { - next = mxmlWalkNext(next, root, MXML_DESCEND); - mxml_type_t t = mxmlGetType(next); - printf("T %d\n", t); - if (t == MXML_TEXT) { - printf("IS TEXT %d\n", t); - } - const char* txt = mxmlGetText(next, NULL); - if (txt) - printf("article-title txt: %s\n", txt); + + if (!elename) { + node = next; + continue; + } + + if (!strcmp(elename, "article-title")) { + printf("article title:"); + for (mxml_node_t *txt = next->child; txt; txt = mxmlGetNextSibling(txt)) { + + // https://github.com/younix/sj/blob/master/messaged.c#L237 + const char* text = mxmlGetText(txt, &space); + //if (space) { + printf(" %s", text); + //} + } + printf("\n"); + break; } node = next; } + mxmlDelete(root); + return 0; } int main(int argc, char *argv[]) { FILE *f; - for (int i = 0; i < argc; i++) { + for (int i = 1; i < argc; i++) { f = fopen(argv[i], "r"); process(f); fclose(f); -- cgit v1.2.3