1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-07-13 09:01:53 +03:00
Files
libxml2/doc/tutorial/includeaddattribute.c
MDT 2002 John Fleck 598f6ebb94 apa.html apb.html apc.html apd.html ar01s02.html ar01s03.html ar01s04.html
Tue Jun  4 09:09:18 MDT 2002 John Fleck <jfleck@inkstain.net>

	* added doc/tutorial, including:
	apa.html
	apb.html
	apc.html
	apd.html
	ar01s02.html
	ar01s03.html
	ar01s04.html
	ar01s05.html
	ar01s06.html
	includeaddattribute.c
	includeaddkeyword.c
	includekeyword.c
	includestory.xml
	index.html
	xmltutorial.xml
	libxml tutorial, including generated html
2002-06-04 15:10:36 +00:00

64 lines
1.1 KiB
C

<![CDATA[
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <libxml/xmlmemory.h>
#include <libxml/parser.h>
xmlDocPtr
parseDoc(char *docname, char *uri) {
xmlDocPtr doc;
xmlNodePtr cur;
xmlNodePtr newnode;
xmlAttrPtr newattr;
doc = xmlParseFile(docname);
if (doc == NULL ) {
fprintf(stderr,"Document not parsed successfully. \n");
return (NULL);
}
cur = xmlDocGetRootElement(doc);
if (cur == NULL) {
fprintf(stderr,"empty document\n");
xmlFreeDoc(doc);
return (NULL);
}
if (xmlStrcmp(cur->name, (const xmlChar *) "story")) {
fprintf(stderr,"document of the wrong type, root node != story");
xmlFreeDoc(doc);
return (NULL);
}
newnode = xmlNewTextChild (cur, NULL, "reference", NULL);
newattr = xmlNewProp (newnode, "uri", uri);
return(doc);
}
int
main(int argc, char **argv) {
char *docname;
char *uri;
xmlDocPtr doc;
if (argc <= 2) {
printf("Usage: %s docname, uri\n", argv[0]);
return(0);
}
docname = argv[1];
uri = argv[2];
doc = parseDoc (docname, uri);
if (doc != NULL) {
xmlSaveFormatFile (docname, doc, 1);
}
return (1);
}
]]>