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"> |
MDT 2002 John Fleck | 77e4d35 | 2002-09-01 01:37:11 +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.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> |
MDT 2002 John Fleck | 5452083 | 2002-06-13 03:30:26 +0000 | [diff] [blame] | 3 | <pre class="programlisting"> |
| 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 | |
| 13 | cur = cur->xmlChildrenNode; |
| 14 | while (cur != NULL) { |
| 15 | if ((!xmlStrcmp(cur->name, (const xmlChar *)"reference"))) { |
| 16 | printf("uri: %s\n", xmlGetProp(cur, "uri")); |
| 17 | } |
| 18 | cur = cur->next; |
| 19 | } |
| 20 | return; |
| 21 | } |
| 22 | |
| 23 | |
| 24 | void |
| 25 | parseDoc(char *docname) { |
| 26 | |
| 27 | xmlDocPtr doc; |
| 28 | xmlNodePtr cur; |
| 29 | |
| 30 | doc = xmlParseFile(docname); |
| 31 | |
| 32 | if (doc == NULL ) { |
| 33 | fprintf(stderr,"Document not parsed successfully. \n"); |
| 34 | return; |
| 35 | } |
| 36 | |
| 37 | cur = xmlDocGetRootElement(doc); |
| 38 | |
| 39 | if (cur == NULL) { |
| 40 | fprintf(stderr,"empty document\n"); |
| 41 | xmlFreeDoc(doc); |
| 42 | return; |
| 43 | } |
| 44 | |
| 45 | if (xmlStrcmp(cur->name, (const xmlChar *) "story")) { |
| 46 | fprintf(stderr,"document of the wrong type, root node != story"); |
| 47 | xmlFreeDoc(doc); |
| 48 | return; |
| 49 | } |
| 50 | |
| 51 | getReference (doc, cur); |
MDT 2002 John Fleck | 77e4d35 | 2002-09-01 01:37:11 +0000 | [diff] [blame^] | 52 | xmlFreeDoc(doc); |
MDT 2002 John Fleck | 5452083 | 2002-06-13 03:30:26 +0000 | [diff] [blame] | 53 | return; |
| 54 | } |
| 55 | |
| 56 | int |
| 57 | main(int argc, char **argv) { |
| 58 | |
| 59 | char *docname; |
| 60 | |
| 61 | if (argc <= 1) { |
| 62 | printf("Usage: %s docname\n", 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> |