diff options
author | Silvan Jegen <s.jegen@gmail.com> | 2016-09-13 19:28:25 +0200 |
---|---|---|
committer | Silvan Jegen <s.jegen@gmail.com> | 2016-09-13 19:28:25 +0200 |
commit | d0f553d573a269abc7eef70564141557015cc230 (patch) | |
tree | 1a3d8a6c247c0a39e651bfe5d858431ad14764ac | |
parent | 88872e990a1fa226cca5521d6b89640bea0dfb88 (diff) |
Fix mxml program
Now I figured out how to print all text fragments.
-rw-r--r-- | mxml.c | 42 |
1 files changed, 22 insertions, 20 deletions
@@ -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); |