#include #include #include mxml_type_t type_cb(mxml_node_t *node) { const char *type; type = mxmlElementGetAttr(node, "type"); if (type == NULL) type = mxmlGetElement(node); if (!strcmp(type, "integer")) return (MXML_INTEGER); else if (!strcmp(type, "opaque")) return (MXML_OPAQUE) ; else if (!strcmp(type, "real")) return (MXML_REAL); else return (MXML_TEXT); } int process(FILE *f) { mxml_node_t *root, *node, *next; const char* elename; int space = 0; root = mxmlLoadFile(NULL, f, MXML_TEXT_CALLBACK); node = mxmlFindElement(root, root, "title-group", NULL, NULL, MXML_DESCEND); while ((next = mxmlWalkNext(node, root, MXML_DESCEND))) { elename = mxmlGetElement(next); 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 = 1; i < argc; i++) { f = fopen(argv[i], "r"); process(f); fclose(f); } return 0; }