1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-07-13 09:01:53 +03:00
Files
libxml2/doc/tutorial/includekeyword.c
MDT 2002 John Fleck 598f6ebb94 apa.html apb.html apc.html apd.html ar01s02.html ar01s03.html ar01s04.html
Tue Jun  4 09:09:18 MDT 2002 John Fleck <jfleck@inkstain.net>

	* added doc/tutorial, including:
	apa.html
	apb.html
	apc.html
	apd.html
	ar01s02.html
	ar01s03.html
	ar01s04.html
	ar01s05.html
	ar01s06.html
	includeaddattribute.c
	includeaddkeyword.c
	includekeyword.c
	includestory.xml
	index.html
	xmltutorial.xml
	libxml tutorial, including generated html
2002-06-04 15:10:36 +00:00

75 lines
1.2 KiB
C

<![CDATA[
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <libxml/xmlmemory.h>
#include <libxml/parser.h>
void
parseStory (xmlDocPtr doc, xmlNodePtr cur) {
cur = cur->xmlChildrenNode;
while (cur != NULL) {
if ((!xmlStrcmp(cur->name, (const xmlChar *)"keyword"))) {
printf("keyword: %s\n", xmlNodeListGetString(doc, cur->xmlChildrenNode, 1));
}
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;
}
}
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);
}
]]>