summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sxmlc.c31
1 files changed, 8 insertions, 23 deletions
diff --git a/sxmlc.c b/sxmlc.c
index 995ac8e..eee2f26 100644
--- a/sxmlc.c
+++ b/sxmlc.c
@@ -40,7 +40,7 @@ int process(char *fn) {
return 0;
}
-XMLNode* find_child_node(XMLNode *node, char* tagname) {
+XMLNode* find_child_node(XMLNode *node, const char* tagname) {
XMLNode** children = node->children;
XMLNode* next = NULL;
@@ -55,30 +55,15 @@ XMLNode* find_child_node(XMLNode *node, char* tagname) {
}
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;
- }
+ XMLNode* next = root;
+ const char *path[] = {"front", "article-meta", "title-group", "article-title", NULL};
- 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");
+ for (int i = 0; path[i]; i++) {
+ next = find_child_node(next, path[i]);
+ if (!next) {
+ fprintf(stderr, "Could not find '%s' tag.\n", path[i]);
return;
+ }
}
printf("article-title: %s\n", next->text);