diff options
-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); |