mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-07-19 05:43:19 +03:00
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
This commit is contained in:
committed by
John Fleck
parent
6f4e5e7697
commit
598f6ebb94
74
doc/tutorial/includekeyword.c
Normal file
74
doc/tutorial/includekeyword.c
Normal file
@ -0,0 +1,74 @@
|
||||
<![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);
|
||||
}
|
||||
]]>
|
Reference in New Issue
Block a user