blob: 9be15e8546b79a9ae34804377fb0547679960bec [file] [log] [blame]
MDT 2002 John Fleck54520832002-06-13 03:30:26 +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>E. Code for Retrieving Attribute Value 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="apd.html" title="D. Code for Add Attribute 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">E. Code for Retrieving Attribute Value Example</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="apd.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> </td></tr></table><hr></div><div class="appendix"><h2 class="title" style="clear: both"><a name="getattributeappendix"></a>E. Code for Retrieving Attribute Value 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
11getReference (xmlDocPtr doc, xmlNodePtr cur) {
12
13 cur = cur-&gt;xmlChildrenNode;
14 while (cur != NULL) {
15 if ((!xmlStrcmp(cur-&gt;name, (const xmlChar *)&quot;reference&quot;))) {
16 printf(&quot;uri: %s\n&quot;, xmlGetProp(cur, &quot;uri&quot;));
17 }
18 cur = cur-&gt;next;
19 }
20 return;
21}
22
23
24void
25parseDoc(char *docname) {
26
27 xmlDocPtr doc;
28 xmlNodePtr cur;
29
30 doc = xmlParseFile(docname);
31
32 if (doc == NULL ) {
33 fprintf(stderr,&quot;Document not parsed successfully. \n&quot;);
34 return;
35 }
36
37 cur = xmlDocGetRootElement(doc);
38
39 if (cur == NULL) {
40 fprintf(stderr,&quot;empty document\n&quot;);
41 xmlFreeDoc(doc);
42 return;
43 }
44
45 if (xmlStrcmp(cur-&gt;name, (const xmlChar *) &quot;story&quot;)) {
46 fprintf(stderr,&quot;document of the wrong type, root node != story&quot;);
47 xmlFreeDoc(doc);
48 return;
49 }
50
51 getReference (doc, cur);
52
53 return;
54}
55
56int
57main(int argc, char **argv) {
58
59 char *docname;
60
61 if (argc &lt;= 1) {
62 printf(&quot;Usage: %s docname\n&quot;, argv[0]);
63 return(0);
64 }
65
66 docname = argv[1];
67 parseDoc (docname);
68
69 return (1);
70}
71
72</pre>
73 </p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="apd.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="index.html">Up</a></td><td width="40%" align="right"> </td></tr><tr><td width="40%" align="left" valign="top">D. Code for Add Attribute Example </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> </td></tr></table></div></body></html>