blob: bb6a18b478f50e7d69fb8f0e17f8f670153ae347 [file] [log] [blame]
MDT 2002 John Fleck598f6eb2002-06-04 15:10:36 +00001<![CDATA[
2#include <stdio.h>
3#include <string.h>
4#include <stdlib.h>
5#include <libxml/xmlmemory.h>
6#include <libxml/parser.h>
7
8
9xmlDocPtr
10parseDoc(char *docname, char *uri) {
11
12 xmlDocPtr doc;
13 xmlNodePtr cur;
14 xmlNodePtr newnode;
15 xmlAttrPtr newattr;
16
17 doc = xmlParseFile(docname);
18
19 if (doc == NULL ) {
20 fprintf(stderr,"Document not parsed successfully. \n");
21 return (NULL);
22 }
23
24 cur = xmlDocGetRootElement(doc);
25
26 if (cur == NULL) {
27 fprintf(stderr,"empty document\n");
28 xmlFreeDoc(doc);
29 return (NULL);
30 }
31
32 if (xmlStrcmp(cur->name, (const xmlChar *) "story")) {
33 fprintf(stderr,"document of the wrong type, root node != story");
34 xmlFreeDoc(doc);
35 return (NULL);
36 }
37
38 newnode = xmlNewTextChild (cur, NULL, "reference", NULL);
39 newattr = xmlNewProp (newnode, "uri", uri);
40 return(doc);
41}
42
43int
44main(int argc, char **argv) {
45
46 char *docname;
47 char *uri;
48 xmlDocPtr doc;
49
50 if (argc <= 2) {
51 printf("Usage: %s docname, uri\n", argv[0]);
52 return(0);
53 }
54
55 docname = argv[1];
56 uri = argv[2];
57 doc = parseDoc (docname, uri);
58 if (doc != NULL) {
59 xmlSaveFormatFile (docname, doc, 1);
MDT 2002 John Fleck77e4d352002-09-01 01:37:11 +000060 xmlFreeDoc(doc);
MDT 2002 John Fleck598f6eb2002-06-04 15:10:36 +000061 }
62 return (1);
63}
64]]>