summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sxmlc.c60
1 files changed, 54 insertions, 6 deletions
diff --git a/sxmlc.c b/sxmlc.c
index 6272a22..f56811a 100644
--- a/sxmlc.c
+++ b/sxmlc.c
@@ -1,8 +1,11 @@
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include "sxmlclib.h"
+void print_article_title(XMLNode *root);
+
int process(char *fn) {
XMLDoc *doc = malloc(sizeof(XMLDoc));
if (!doc) {
@@ -18,6 +21,8 @@ int process(char *fn) {
return 1;
}
+ // Apparently ill-formed XML is not an error but the library
+ // can't find the root node afterwards...
if (doc->i_root < 0) {
fprintf(stderr, "i_root was negative. Skipping file '%s'.\n", fn);
return 1;
@@ -28,19 +33,62 @@ int process(char *fn) {
fprintf(stderr, "Root was NULL. Exiting.\n");
return 1;
}
- //get_article_title(root);
-
- fprintf(stderr, "root is '%s'.\n", root->tag);
-
+ print_article_title(root);
XMLDoc_free(doc);
return 0;
}
-XMLNode* get_article_title(XMLNode *root) {
+XMLNode* find_child_node(XMLNode *node, char* tagname) {
+ XMLNode** children = node->children;
+ XMLNode* next = NULL;
+
+ for (int i = 0; i < node->n_children; i++) {
+ if (!strcmp(children[i]->tag, tagname)) {
+ next = children[i];
+ break;
+ }
+ }
+
+ return next;
+}
+
+void print_article_title(XMLNode *root) {
+ XMLNode* next = NULL;
+
+ next = find_child_node(root, "front");
+ if (!next) {
+ fprintf(stderr, "Could not find front tag.\n");
+ return;
+ }
+
+ next = find_child_node(next, "article-meta");
+ if (!next) {
+ fprintf(stderr, "Could not find article-meta tag.\n");
+ return;
+ }
+
+ next = find_child_node(next, "title-group");
+ if (!next) {
+ fprintf(stderr, "Could not find title-group tag.\n");
+ return;
+ }
+
+ next = find_child_node(next, "article-title");
+ if (!next) {
+ fprintf(stderr, "Could not find article-title tag.\n");
+ return;
+ }
+
+ printf("article-title: %s\n", next->text);
- return root;
+ // XMLNode** children = next->children;
+ // for (int i = 0; i < next->n_children; i++) {
+ // if (children[i]->tag_type == TAG_TEXT) {
+ // printf("printing piecewise: %s", children[i]->text);
+ // }
+ // }
}
int main(int argc, char *argv[]) {