MDT 2002 John Fleck | 5452083 | 2002-06-13 03:30:26 +0000 | [diff] [blame] | 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |
MST 2003 John Fleck | 731967e | 2003-01-27 00:39:50 +0000 | [diff] [blame^] | 2 | <html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>E. Code for Retrieving Attribute Value Example</title><meta name="generator" content="DocBook XSL Stylesheets V1.60.1"><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"><link rel="next" href="apf.html" title="F. Code for Encoding Conversion 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"> <a accesskey="n" href="apf.html">Next</a></td></tr></table><hr></div><div class="appendix" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="getattributeappendix"></a>E. Code for Retrieving Attribute Value Example</h2></div></div><div></div></div><p> |
| 3 | </p><pre class="programlisting"> |
MDT 2002 John Fleck | 5452083 | 2002-06-13 03:30:26 +0000 | [diff] [blame] | 4 | #include <stdio.h> |
| 5 | #include <string.h> |
| 6 | #include <stdlib.h> |
| 7 | #include <libxml/xmlmemory.h> |
| 8 | #include <libxml/parser.h> |
| 9 | |
| 10 | void |
| 11 | getReference (xmlDocPtr doc, xmlNodePtr cur) { |
| 12 | |
MST 2002 John Fleck | 44aacb3 | 2002-12-16 04:34:57 +0000 | [diff] [blame] | 13 | xmlChar *uri; |
MDT 2002 John Fleck | 5452083 | 2002-06-13 03:30:26 +0000 | [diff] [blame] | 14 | cur = cur->xmlChildrenNode; |
| 15 | while (cur != NULL) { |
| 16 | if ((!xmlStrcmp(cur->name, (const xmlChar *)"reference"))) { |
MST 2002 John Fleck | 44aacb3 | 2002-12-16 04:34:57 +0000 | [diff] [blame] | 17 | uri = xmlGetProp(cur, "uri"); |
| 18 | printf("uri: %s\n", uri); |
| 19 | xmlFree(uri); |
| 20 | } |
MDT 2002 John Fleck | 5452083 | 2002-06-13 03:30:26 +0000 | [diff] [blame] | 21 | cur = cur->next; |
| 22 | } |
MST 2002 John Fleck | 44aacb3 | 2002-12-16 04:34:57 +0000 | [diff] [blame] | 23 | return; |
MDT 2002 John Fleck | 5452083 | 2002-06-13 03:30:26 +0000 | [diff] [blame] | 24 | } |
| 25 | |
| 26 | |
| 27 | void |
| 28 | parseDoc(char *docname) { |
| 29 | |
| 30 | xmlDocPtr doc; |
| 31 | xmlNodePtr cur; |
| 32 | |
| 33 | doc = xmlParseFile(docname); |
| 34 | |
| 35 | if (doc == NULL ) { |
| 36 | fprintf(stderr,"Document not parsed successfully. \n"); |
| 37 | return; |
| 38 | } |
| 39 | |
| 40 | cur = xmlDocGetRootElement(doc); |
| 41 | |
| 42 | if (cur == NULL) { |
| 43 | fprintf(stderr,"empty document\n"); |
| 44 | xmlFreeDoc(doc); |
| 45 | return; |
| 46 | } |
| 47 | |
| 48 | if (xmlStrcmp(cur->name, (const xmlChar *) "story")) { |
| 49 | fprintf(stderr,"document of the wrong type, root node != story"); |
| 50 | xmlFreeDoc(doc); |
| 51 | return; |
| 52 | } |
| 53 | |
| 54 | getReference (doc, cur); |
MDT 2002 John Fleck | 77e4d35 | 2002-09-01 01:37:11 +0000 | [diff] [blame] | 55 | xmlFreeDoc(doc); |
MDT 2002 John Fleck | 5452083 | 2002-06-13 03:30:26 +0000 | [diff] [blame] | 56 | return; |
| 57 | } |
| 58 | |
| 59 | int |
| 60 | main(int argc, char **argv) { |
| 61 | |
| 62 | char *docname; |
| 63 | |
| 64 | if (argc <= 1) { |
| 65 | printf("Usage: %s docname\n", argv[0]); |
| 66 | return(0); |
| 67 | } |
| 68 | |
| 69 | docname = argv[1]; |
| 70 | parseDoc (docname); |
| 71 | |
| 72 | return (1); |
| 73 | } |
| 74 | |
MST 2003 John Fleck | 731967e | 2003-01-27 00:39:50 +0000 | [diff] [blame^] | 75 | </pre><p> |
| 76 | </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"> <a accesskey="n" href="apf.html">Next</a></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"> F. Code for Encoding Conversion Example</td></tr></table></div></body></html> |