VirtualBox

source: vbox/trunk/src/libs/libxml2-2.6.30/doc/tutorial/includeaddattribute.c@ 11632

Last change on this file since 11632 was 6076, checked in by vboxsync, 17 years ago

Merged dmik/s2 branch (r25959:26751) to the trunk.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Revision Author Id
File size: 1.1 KB
Line 
1<![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);
60 xmlFreeDoc(doc);
61 }
62 return (1);
63}
64]]>
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette