diff options
| -rw-r--r-- | sxmlc.c | 31 | 
1 files changed, 8 insertions, 23 deletions
| @@ -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); | 
