blob: e3b119ff569e5a4bb1274898f3ed618462d0b728 [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">
2<html><head><meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type"><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>
3 <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 }
58
59}
60
61int
62main(int argc, char **argv) {
63
64 char *docname;
65
66 if (argc &lt;= 1) {
67 printf(&quot;Usage: %s docname\n&quot;, argv[0]);
68 return(0);
69 }
70
71 docname = argv[1];
72 parseDoc (docname);
73
74 return (1);
75}
76
77</pre>
78 </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>