/usr/share/doc/libxml2-devel/tutorial
NameSizeModeActions
images/-0755rm
apa.html21140644editdlrm
apb.html20260644editdlrm
apc.html30940644editdlrm
apd.html32320644editdlrm
ape.html30960644editdlrm
apf.html29490644editdlrm
apg.html30220644editdlrm
aph.html36000644editdlrm
api.html18990644editdlrm
ar01s02.html32980644editdlrm
ar01s03.html57180644editdlrm
ar01s04.html62230644editdlrm
ar01s05.html74220644editdlrm
ar01s06.html38490644editdlrm
ar01s07.html38660644editdlrm
ar01s08.html38940644editdlrm
ar01s09.html76030644editdlrm
includeaddattribute.c11360644editdlrm
includeaddkeyword.c13200644editdlrm
includeconvert.c18080644editdlrm
includegetattribute.c11710644editdlrm
includekeyword.c13510644editdlrm
includexpath.c14910644editdlrm
index.html59300644editdlrm
ix01.html25450644editdlrm
xmltutorial.pdf517090644editdlrm
Edit: /usr/share/doc/libxml2-devel/tutorial/apc.html (3094B)
C. Code for Keyword Example

C. Code for Keyword Example

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <libxml/xmlmemory.h>
#include <libxml/parser.h>

void
parseStory (xmlDocPtr doc, xmlNodePtr cur) {

	xmlChar *key;
	cur = cur->xmlChildrenNode;
	while (cur != NULL) {
	    if ((!xmlStrcmp(cur->name, (const xmlChar *)"keyword"))) {
		    key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
		    printf("keyword: %s\n", key);
		    xmlFree(key);
 	    }
	cur = cur->next;
	}
    return;
}

static void
parseDoc(char *docname) {

	xmlDocPtr doc;
	xmlNodePtr cur;

	doc = xmlParseFile(docname);
	
	if (doc == NULL ) {
		fprintf(stderr,"Document not parsed successfully. \n");
		return;
	}
	
	cur = xmlDocGetRootElement(doc);
	
	if (cur == NULL) {
		fprintf(stderr,"empty document\n");
		xmlFreeDoc(doc);
		return;
	}
	
	if (xmlStrcmp(cur->name, (const xmlChar *) "story")) {
		fprintf(stderr,"document of the wrong type, root node != story");
		xmlFreeDoc(doc);
		return;
	}
	
	cur = cur->xmlChildrenNode;
	while (cur != NULL) {
		if ((!xmlStrcmp(cur->name, (const xmlChar *)"storyinfo"))){
			parseStory (doc, cur);
		}
		 
	cur = cur->next;
	}
	
	xmlFreeDoc(doc);
	return;
}

int
main(int argc, char **argv) {

	char *docname;
		
	if (argc <= 1) {
		printf("Usage: %s docname\n", argv[0]);
		return(0);
	}

	docname = argv[1];
	parseDoc (docname);

	return (1);
}