libxml2 2.9.1 clean sources
[tomato.git] / release / src / router / libxml2 / doc / tutorial / includegetattribute.c
blobb2b7471102d799e38f5f1b07a14ea73ed457f813
1 <![CDATA[
2 #include <stdio.h>
3 #include <string.h>
4 #include <stdlib.h>
5 #include <libxml/xmlmemory.h>
6 #include <libxml/parser.h>
8 void
9 getReference (xmlDocPtr doc, xmlNodePtr cur) {
11 xmlChar *uri;
12 cur = cur->xmlChildrenNode;
13 while (cur != NULL) {
14 if ((!xmlStrcmp(cur->name, (const xmlChar *)"reference"))) {
15 uri = xmlGetProp(cur, "uri");
16 printf("uri: %s\n", uri);
17 xmlFree(uri);
19 cur = cur->next;
21 return;
25 void
26 parseDoc(char *docname) {
28 xmlDocPtr doc;
29 xmlNodePtr cur;
31 doc = xmlParseFile(docname);
33 if (doc == NULL ) {
34 fprintf(stderr,"Document not parsed successfully. \n");
35 return;
38 cur = xmlDocGetRootElement(doc);
40 if (cur == NULL) {
41 fprintf(stderr,"empty document\n");
42 xmlFreeDoc(doc);
43 return;
46 if (xmlStrcmp(cur->name, (const xmlChar *) "story")) {
47 fprintf(stderr,"document of the wrong type, root node != story");
48 xmlFreeDoc(doc);
49 return;
52 getReference (doc, cur);
53 xmlFreeDoc(doc);
54 return;
57 int
58 main(int argc, char **argv) {
60 char *docname;
62 if (argc <= 1) {
63 printf("Usage: %s docname\n", argv[0]);
64 return(0);
67 docname = argv[1];
68 parseDoc (docname);
70 return (1);
72 ]]>