mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-07-28 00:21:53 +03:00
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
This commit is contained in:
committed by
John Fleck
parent
6f4e5e7697
commit
598f6ebb94
63
doc/tutorial/includeaddattribute.c
Normal file
63
doc/tutorial/includeaddattribute.c
Normal file
@ -0,0 +1,63 @@
|
||||
<![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);
|
||||
}
|
||||
]]>
|
Reference in New Issue
Block a user