ape.html revision 38ae7e4efe803ea78b6499cd05a394db32623e41
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>E.�Code for Add Keyword Example</title><meta name="generator" content="DocBook XSL Stylesheets V1.61.2"><link rel="home" href="index.html" title="Libxml Tutorial"><link rel="up" href="index.html" title="Libxml Tutorial"><link rel="previous" href="apd.html" title="D.�Code for XPath Example"><link rel="next" href="apf.html" title="F.�Code for Add Attribute Example"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">E.�Code for Add Keyword Example</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="apd.html">Prev</a>�</td><th width="60%" align="center">�</th><td width="20%" align="right">�<a accesskey="n" href="apf.html">Next</a></td></tr></table><hr></div><div class="appendix" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="addkeywordappendix"></a>E.�Code for Add Keyword Example</h2></div></div><div></div></div><p>
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens#include <stdio.h>
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens#include <string.h>
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens#include <stdlib.h>
3cb34c601f3ef3016f638574f5982e80c3735c71ahrensparseStory (xmlDocPtr doc, xmlNodePtr cur, char *keyword) {
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens xmlNewTextChild (cur, NULL, "keyword", keyword);
3cb34c601f3ef3016f638574f5982e80c3735c71ahrensparseDoc(char *docname, char *keyword) {
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens xmlDocPtr doc;
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens xmlNodePtr cur;
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens doc = xmlParseFile(docname);
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrens if (doc == NULL ) {
4e3c9f4489a18514e5e8caeb91d4e6db07c98415Bill Pijewski fprintf(stderr,"Document not parsed successfully. \n");
a7a845e4bf22fd1b2a284729ccd95c7370a0438cSteven Hartland return (NULL);
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens cur = xmlDocGetRootElement(doc);
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens if (cur == NULL) {
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens fprintf(stderr,"empty document\n");
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens xmlFreeDoc(doc);
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens return (NULL);
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens if (xmlStrcmp(cur->name, (const xmlChar *) "story")) {
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens fprintf(stderr,"document of the wrong type, root node != story");
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens xmlFreeDoc(doc);
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt return (NULL);
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens cur = cur->xmlChildrenNode;
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens while (cur != NULL) {
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrens if ((!xmlStrcmp(cur->name, (const xmlChar *)"storyinfo"))){
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens parseStory (doc, cur, keyword);
495db6fbcd9e8ab893e91f6f5627df6e0cec63cfLori Alt cur = cur->next;
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt return(doc);
92241e0b80813d0b83c08e730a29b9d1831794fcTom Ericksonmain(int argc, char **argv) {
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson char *docname;
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens char *keyword;
c99e4bdccfb4ac4da569c64a43baaf908d726329Chris Kirby xmlDocPtr doc;
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt if (argc <= 2) {
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt printf("Usage: %s docname, keyword\n", argv[0]);
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt docname = argv[1];
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt keyword = argv[2];
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt doc = parseDoc (docname, keyword);
4e3c9f4489a18514e5e8caeb91d4e6db07c98415Bill Pijewski if (doc != NULL) {
4e3c9f4489a18514e5e8caeb91d4e6db07c98415Bill Pijewski xmlSaveFormatFile (docname, doc, 0);
4e3c9f4489a18514e5e8caeb91d4e6db07c98415Bill Pijewski xmlFreeDoc(doc);
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt </p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="apd.html">Prev</a>�</td><td width="20%" align="center"><a accesskey="u" href="index.html">Up</a></td><td width="40%" align="right">�<a accesskey="n" href="apf.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">D.�Code for XPath Example�</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">�F.�Code for Add Attribute Example</td></tr></table></div></body></html>