blob: 37835d6feed5324ccf375d612f85d3ed47715eb5 [file] [log] [blame]
MDT 2002 John Fleck598f6eb2002-06-04 15:10:36 +00001<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
MDT 2002 John Fleck77e4d352002-09-01 01:37:11 +00002<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>B. Code for Keyword Example</title><meta name="generator" content="DocBook XSL Stylesheets V1.48"><link rel="home" href="index.html" title="Libxml Tutorial"><link rel="up" href="index.html" title="Libxml Tutorial"><link rel="previous" href="apa.html" title="A. Sample Document"><link rel="next" href="apc.html" title="C. Code for Add Keyword Example"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">B. Code for Keyword Example</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="apa.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="apc.html">Next</a></td></tr></table><hr></div><div class="appendix"><h2 class="title" style="clear: both"><a name="keywordappendix"></a>B. Code for Keyword Example</h2><p>
MDT 2002 John Fleck598f6eb2002-06-04 15:10:36 +00003 <pre class="programlisting">
4#include &lt;stdio.h&gt;
5#include &lt;string.h&gt;
6#include &lt;stdlib.h&gt;
7#include &lt;libxml/xmlmemory.h&gt;
8#include &lt;libxml/parser.h&gt;
9
10void
11parseStory (xmlDocPtr doc, xmlNodePtr cur) {
12
13 cur = cur-&gt;xmlChildrenNode;
14 while (cur != NULL) {
15 if ((!xmlStrcmp(cur-&gt;name, (const xmlChar *)&quot;keyword&quot;))) {
16 printf(&quot;keyword: %s\n&quot;, xmlNodeListGetString(doc, cur-&gt;xmlChildrenNode, 1));
17 }
18 cur = cur-&gt;next;
19 }
20 return;
21}
22
23static void
24parseDoc(char *docname) {
25
26 xmlDocPtr doc;
27 xmlNodePtr cur;
28
29 doc = xmlParseFile(docname);
30
31 if (doc == NULL ) {
32 fprintf(stderr,&quot;Document not parsed successfully. \n&quot;);
33 return;
34 }
35
36 cur = xmlDocGetRootElement(doc);
37
38 if (cur == NULL) {
39 fprintf(stderr,&quot;empty document\n&quot;);
40 xmlFreeDoc(doc);
41 return;
42 }
43
44 if (xmlStrcmp(cur-&gt;name, (const xmlChar *) &quot;story&quot;)) {
45 fprintf(stderr,&quot;document of the wrong type, root node != story&quot;);
46 xmlFreeDoc(doc);
47 return;
48 }
49
50 cur = cur-&gt;xmlChildrenNode;
51 while (cur != NULL) {
52 if ((!xmlStrcmp(cur-&gt;name, (const xmlChar *)&quot;storyinfo&quot;))){
53 parseStory (doc, cur);
54 }
55
56 cur = cur-&gt;next;
57 }
MDT 2002 John Fleck77e4d352002-09-01 01:37:11 +000058
59 xmlFreeDoc(doc);
60 return;
MDT 2002 John Fleck598f6eb2002-06-04 15:10:36 +000061}
62
63int
64main(int argc, char **argv) {
65
66 char *docname;
67
68 if (argc &lt;= 1) {
69 printf(&quot;Usage: %s docname\n&quot;, argv[0]);
70 return(0);
71 }
72
73 docname = argv[1];
74 parseDoc (docname);
75
76 return (1);
77}
78
79</pre>
80 </p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="apa.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="index.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="apc.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">A. Sample Document </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> C. Code for Add Keyword Example</td></tr></table></div></body></html>