Commit 8aff3b7d authored by MDT 2003 John Fleck's avatar MDT 2003 John Fleck Committed by John Fleck
Browse files

xmltutorial.xml xmltutorial.pdf *.html add appendix on generating compiler


Fri Apr 25 21:52:33 MDT 2003 John Fleck <jfleck@inkstain.net>

	* doc/tutorial:
	xmltutorial.xml
	xmltutorial.pdf
	*.html
	add appendix on generating compiler flags, more indexing
parent 1c960272
Fri Apr 25 21:52:33 MDT 2003 John Fleck <jfleck@inkstain.net>
* doc/tutorial:
xmltutorial.xml
xmltutorial.pdf
*.html
add appendix on generating compiler flags, more indexing
Sat Apr 26 01:10:48 CEST 2003 Daniel Veillard <daniel@veillard.com>
 
* triodef.h vms/build_libxml.com: applied patch from Craig A. Berry
......
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>A.Sample Document</title><meta name="generator" content="DocBook XSL Stylesheets V1.60.1"><link rel="home" href="index.html" title="Libxml Tutorial"><link rel="up" href="index.html" title="Libxml Tutorial"><link rel="previous" href="ar01s08.html" title="Encoding Conversion"><link rel="next" href="apb.html" title="B.Code for Keyword 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">A.Sample Document</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ar01s08.html">Prev</a></td><th width="60%" align="center"></th><td width="20%" align="right"><a accesskey="n" href="apb.html">Next</a></td></tr></table><hr></div><div class="appendix" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="sampledoc"></a>A.Sample Document</h2></div></div><div></div></div><pre class="programlisting">
&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;story&gt;
&lt;storyinfo&gt;
&lt;author&gt;John Fleck&lt;/author&gt;
&lt;datewritten&gt;June 2, 2002&lt;/datewritten&gt;
&lt;keyword&gt;example keyword&lt;/keyword&gt;
&lt;/storyinfo&gt;
&lt;body&gt;
&lt;headline&gt;This is the headline&lt;/headline&gt;
&lt;para&gt;This is the body text.&lt;/para&gt;
&lt;/body&gt;
&lt;/story&gt;
</pre></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ar01s08.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="apb.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Encoding Conversion</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">B.Code for Keyword Example</td></tr></table></div></body></html>
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>A.Compilation</title><meta name="generator" content="DocBook XSL Stylesheets V1.60.1"><link rel="home" href="index.html" title="Libxml Tutorial"><link rel="up" href="index.html" title="Libxml Tutorial"><link rel="previous" href="ar01s08.html" title="Encoding Conversion"><link rel="next" href="apb.html" title="B.Sample Document"></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">A.Compilation</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ar01s08.html">Prev</a></td><th width="60%" align="center"></th><td width="20%" align="right"><a accesskey="n" href="apb.html">Next</a></td></tr></table><hr></div><div class="appendix" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="compilation"></a>A.Compilation</h2></div></div><div></div></div><p><a class="indexterm" name="id2814889"></a>
<span class="application">Libxml</span> includes a script,
<span class="application">xml2-config</span>, that can be used to generate
flags for compilation and linking of programs written with the
library. For pre-processor and compiler flags, use <b class="command">xml2-config
--cflags</b>. For library linking flags, use <b class="command">xml2-config
--libs</b>. Other options are available using <b class="command">xml2-config
--help</b>.</p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ar01s08.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="apb.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Encoding Conversion</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">B.Sample Document</td></tr></table></div></body></html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>B.Code for Keyword Example</title><meta name="generator" content="DocBook XSL Stylesheets V1.60.1"><link rel="home" href="index.html" title="Libxml Tutorial"><link rel="up" href="index.html" title="Libxml Tutorial"><link rel="previous" href="apa.html" title="A.Sample Document"><link rel="next" href="apc.html" title="C.Code for Add Keyword 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">B.Code for Keyword Example</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="apa.html">Prev</a></td><th width="60%" align="center"></th><td width="20%" align="right"><a accesskey="n" href="apc.html">Next</a></td></tr></table><hr></div><div class="appendix" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="keywordappendix"></a>B.Code for Keyword Example</h2></div></div><div></div></div><p>
</p><pre class="programlisting">
#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;libxml/xmlmemory.h&gt;
#include &lt;libxml/parser.h&gt;
void
parseStory (xmlDocPtr doc, xmlNodePtr cur) {
xmlChar *key;
cur = cur-&gt;xmlChildrenNode;
while (cur != NULL) {
if ((!xmlStrcmp(cur-&gt;name, (const xmlChar *)&quot;keyword&quot;))) {
key = xmlNodeListGetString(doc, cur-&gt;xmlChildrenNode, 1);
printf(&quot;keyword: %s\n&quot;, key);
xmlFree(key);
}
cur = cur-&gt;next;
}
return;
}
static void
parseDoc(char *docname) {
xmlDocPtr doc;
xmlNodePtr cur;
doc = xmlParseFile(docname);
if (doc == NULL ) {
fprintf(stderr,&quot;Document not parsed successfully. \n&quot;);
return;
}
cur = xmlDocGetRootElement(doc);
if (cur == NULL) {
fprintf(stderr,&quot;empty document\n&quot;);
xmlFreeDoc(doc);
return;
}
if (xmlStrcmp(cur-&gt;name, (const xmlChar *) &quot;story&quot;)) {
fprintf(stderr,&quot;document of the wrong type, root node != story&quot;);
xmlFreeDoc(doc);
return;
}
cur = cur-&gt;xmlChildrenNode;
while (cur != NULL) {
if ((!xmlStrcmp(cur-&gt;name, (const xmlChar *)&quot;storyinfo&quot;))){
parseStory (doc, cur);
}
cur = cur-&gt;next;
}
xmlFreeDoc(doc);
return;
}
int
main(int argc, char **argv) {
char *docname;
if (argc &lt;= 1) {
printf(&quot;Usage: %s docname\n&quot;, argv[0]);
return(0);
}
docname = argv[1];
parseDoc (docname);
return (1);
}
</pre><p>
</p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="apa.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="apc.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">A.Sample Document</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">C.Code for Add Keyword Example</td></tr></table></div></body></html>
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>B.Sample Document</title><meta name="generator" content="DocBook XSL Stylesheets V1.60.1"><link rel="home" href="index.html" title="Libxml Tutorial"><link rel="up" href="index.html" title="Libxml Tutorial"><link rel="previous" href="apa.html" title="A.Compilation"><link rel="next" href="apc.html" title="C.Code for Keyword 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">B.Sample Document</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="apa.html">Prev</a></td><th width="60%" align="center"></th><td width="20%" align="right"><a accesskey="n" href="apc.html">Next</a></td></tr></table><hr></div><div class="appendix" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="sampledoc"></a>B.Sample Document</h2></div></div><div></div></div><pre class="programlisting">
&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;story&gt;
&lt;storyinfo&gt;
&lt;author&gt;John Fleck&lt;/author&gt;
&lt;datewritten&gt;June 2, 2002&lt;/datewritten&gt;
&lt;keyword&gt;example keyword&lt;/keyword&gt;
&lt;/storyinfo&gt;
&lt;body&gt;
&lt;headline&gt;This is the headline&lt;/headline&gt;
&lt;para&gt;This is the body text.&lt;/para&gt;
&lt;/body&gt;
&lt;/story&gt;
</pre></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="apa.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="apc.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">A.Compilation</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">C.Code for Keyword Example</td></tr></table></div></body></html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>C.Code for Add Keyword Example</title><meta name="generator" content="DocBook XSL Stylesheets V1.60.1"><link rel="home" href="index.html" title="Libxml Tutorial"><link rel="up" href="index.html" title="Libxml Tutorial"><link rel="previous" href="apb.html" title="B.Code for Keyword Example"><link rel="next" href="apd.html" title="D.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">C.Code for Add Keyword Example</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="apb.html">Prev</a></td><th width="60%" align="center"></th><td width="20%" align="right"><a accesskey="n" href="apd.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>C.Code for Add Keyword Example</h2></div></div><div></div></div><p>
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>C.Code for Keyword Example</title><meta name="generator" content="DocBook XSL Stylesheets V1.60.1"><link rel="home" href="index.html" title="Libxml Tutorial"><link rel="up" href="index.html" title="Libxml Tutorial"><link rel="previous" href="apb.html" title="B.Sample Document"><link rel="next" href="apd.html" title="D.Code for Add Keyword 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">C.Code for Keyword Example</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="apb.html">Prev</a></td><th width="60%" align="center"></th><td width="20%" align="right"><a accesskey="n" href="apd.html">Next</a></td></tr></table><hr></div><div class="appendix" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="keywordappendix"></a>C.Code for Keyword Example</h2></div></div><div></div></div><p>
</p><pre class="programlisting">
#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
......@@ -8,14 +8,23 @@
#include &lt;libxml/parser.h&gt;
void
parseStory (xmlDocPtr doc, xmlNodePtr cur, char *keyword) {
parseStory (xmlDocPtr doc, xmlNodePtr cur) {
xmlNewTextChild (cur, NULL, &quot;keyword&quot;, keyword);
xmlChar *key;
cur = cur-&gt;xmlChildrenNode;
while (cur != NULL) {
if ((!xmlStrcmp(cur-&gt;name, (const xmlChar *)&quot;keyword&quot;))) {
key = xmlNodeListGetString(doc, cur-&gt;xmlChildrenNode, 1);
printf(&quot;keyword: %s\n&quot;, key);
xmlFree(key);
}
cur = cur-&gt;next;
}
return;
}
xmlDocPtr
parseDoc(char *docname, char *keyword) {
static void
parseDoc(char *docname) {
xmlDocPtr doc;
xmlNodePtr cur;
......@@ -24,7 +33,7 @@ parseDoc(char *docname, char *keyword) {
if (doc == NULL ) {
fprintf(stderr,&quot;Document not parsed successfully. \n&quot;);
return (NULL);
return;
}
cur = xmlDocGetRootElement(doc);
......@@ -32,48 +41,43 @@ parseDoc(char *docname, char *keyword) {
if (cur == NULL) {
fprintf(stderr,&quot;empty document\n&quot;);
xmlFreeDoc(doc);
return (NULL);
return;
}
if (xmlStrcmp(cur-&gt;name, (const xmlChar *) &quot;story&quot;)) {
fprintf(stderr,&quot;document of the wrong type, root node != story&quot;);
xmlFreeDoc(doc);
return (NULL);
return;
}
cur = cur-&gt;xmlChildrenNode;
while (cur != NULL) {
if ((!xmlStrcmp(cur-&gt;name, (const xmlChar *)&quot;storyinfo&quot;))){
parseStory (doc, cur, keyword);
parseStory (doc, cur);
}
cur = cur-&gt;next;
}
return(doc);
xmlFreeDoc(doc);
return;
}
int
main(int argc, char **argv) {
char *docname;
char *keyword;
xmlDocPtr doc;
if (argc &lt;= 2) {
printf(&quot;Usage: %s docname, keyword\n&quot;, argv[0]);
if (argc &lt;= 1) {
printf(&quot;Usage: %s docname\n&quot;, argv[0]);
return(0);
}
docname = argv[1];
keyword = argv[2];
doc = parseDoc (docname, keyword);
if (doc != NULL) {
xmlSaveFormatFile (docname, doc, 0);
xmlFreeDoc(doc);
}
parseDoc (docname);
return (1);
}
</pre><p>
</p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="apb.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="apd.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">B.Code for Keyword Example</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">D.Code for Add Attribute Example</td></tr></table></div></body></html>
</p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="apb.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="apd.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">B.Sample Document</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">D.Code for Add Keyword Example</td></tr></table></div></body></html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>D.Code for Add Attribute Example</title><meta name="generator" content="DocBook XSL Stylesheets V1.60.1"><link rel="home" href="index.html" title="Libxml Tutorial"><link rel="up" href="index.html" title="Libxml Tutorial"><link rel="previous" href="apc.html" title="C.Code for Add Keyword Example"><link rel="next" href="ape.html" title="E.Code for Retrieving Attribute Value 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">D.Code for Add Attribute Example</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="apc.html">Prev</a></td><th width="60%" align="center"></th><td width="20%" align="right"><a accesskey="n" href="ape.html">Next</a></td></tr></table><hr></div><div class="appendix" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="addattributeappendix"></a>D.Code for Add Attribute Example</h2></div></div><div></div></div><p>
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>D.Code for Add Keyword Example</title><meta name="generator" content="DocBook XSL Stylesheets V1.60.1"><link rel="home" href="index.html" title="Libxml Tutorial"><link rel="up" href="index.html" title="Libxml Tutorial"><link rel="previous" href="apc.html" title="C.Code for Keyword Example"><link rel="next" href="ape.html" title="E.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">D.Code for Add Keyword Example</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="apc.html">Prev</a></td><th width="60%" align="center"></th><td width="20%" align="right"><a accesskey="n" href="ape.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>D.Code for Add Keyword Example</h2></div></div><div></div></div><p>
</p><pre class="programlisting">
#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
......@@ -7,14 +7,18 @@
#include &lt;libxml/xmlmemory.h&gt;
#include &lt;libxml/parser.h&gt;
void
parseStory (xmlDocPtr doc, xmlNodePtr cur, char *keyword) {
xmlNewTextChild (cur, NULL, &quot;keyword&quot;, keyword);
return;
}
xmlDocPtr
parseDoc(char *docname, char *uri) {
parseDoc(char *docname, char *keyword) {
xmlDocPtr doc;
xmlNodePtr cur;
xmlNodePtr newnode;
xmlAttrPtr newattr;
doc = xmlParseFile(docname);
......@@ -37,8 +41,14 @@ parseDoc(char *docname, char *uri) {
return (NULL);
}
newnode = xmlNewTextChild (cur, NULL, &quot;reference&quot;, NULL);
newattr = xmlNewProp (newnode, &quot;uri&quot;, uri);
cur = cur-&gt;xmlChildrenNode;
while (cur != NULL) {
if ((!xmlStrcmp(cur-&gt;name, (const xmlChar *)&quot;storyinfo&quot;))){
parseStory (doc, cur, keyword);
}
cur = cur-&gt;next;
}
return(doc);
}
......@@ -46,23 +56,24 @@ int
main(int argc, char **argv) {
char *docname;
char *uri;
char *keyword;
xmlDocPtr doc;
if (argc &lt;= 2) {
printf(&quot;Usage: %s docname, uri\n&quot;, argv[0]);
printf(&quot;Usage: %s docname, keyword\n&quot;, argv[0]);
return(0);
}
docname = argv[1];
uri = argv[2];
doc = parseDoc (docname, uri);
keyword = argv[2];
doc = parseDoc (docname, keyword);
if (doc != NULL) {
xmlSaveFormatFile (docname, doc, 1);
xmlSaveFormatFile (docname, doc, 0);
xmlFreeDoc(doc);
}
return (1);
}
</pre><p>
</p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="apc.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="ape.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">C.Code for Add Keyword Example</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">E.Code for Retrieving Attribute Value Example</td></tr></table></div></body></html>
</p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="apc.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="ape.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">C.Code for Keyword Example</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">E.Code for Add Attribute Example</td></tr></table></div></body></html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>E.Code for Retrieving Attribute Value Example</title><meta name="generator" content="DocBook XSL Stylesheets V1.60.1"><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 Add Attribute Example"><link rel="next" href="apf.html" title="F.Code for Encoding Conversion 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 Retrieving Attribute Value 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="getattributeappendix"></a>E.Code for Retrieving Attribute Value Example</h2></div></div><div></div></div><p>
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>E.Code for Add Attribute Example</title><meta name="generator" content="DocBook XSL Stylesheets V1.60.1"><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 Add Keyword Example"><link rel="next" href="apf.html" title="F.Code for Retrieving Attribute Value 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 Attribute 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="addattributeappendix"></a>E.Code for Add Attribute Example</h2></div></div><div></div></div><p>
</p><pre class="programlisting">
#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
......@@ -7,34 +7,20 @@
#include &lt;libxml/xmlmemory.h&gt;
#include &lt;libxml/parser.h&gt;
void
getReference (xmlDocPtr doc, xmlNodePtr cur) {
xmlChar *uri;
cur = cur-&gt;xmlChildrenNode;
while (cur != NULL) {
if ((!xmlStrcmp(cur-&gt;name, (const xmlChar *)&quot;reference&quot;))) {
uri = xmlGetProp(cur, &quot;uri&quot;);
printf(&quot;uri: %s\n&quot;, uri);
xmlFree(uri);
}
cur = cur-&gt;next;
}
return;
}
void
parseDoc(char *docname) {
xmlDocPtr
parseDoc(char *docname, char *uri) {
xmlDocPtr doc;
xmlNodePtr cur;
xmlNodePtr newnode;
xmlAttrPtr newattr;
doc = xmlParseFile(docname);
if (doc == NULL ) {
fprintf(stderr,&quot;Document not parsed successfully. \n&quot;);
return;
return (NULL);
}
cur = xmlDocGetRootElement(doc);
......@@ -42,35 +28,41 @@ parseDoc(char *docname) {
if (cur == NULL) {
fprintf(stderr,&quot;empty document\n&quot;);
xmlFreeDoc(doc);
return;
return (NULL);
}
if (xmlStrcmp(cur-&gt;name, (const xmlChar *) &quot;story&quot;)) {
fprintf(stderr,&quot;document of the wrong type, root node != story&quot;);
xmlFreeDoc(doc);
return;
return (NULL);
}
getReference (doc, cur);
xmlFreeDoc(doc);
return;
newnode = xmlNewTextChild (cur, NULL, &quot;reference&quot;, NULL);
newattr = xmlNewProp (newnode, &quot;uri&quot;, uri);
return(doc);
}
int
main(int argc, char **argv) {
char *docname;
char *uri;
xmlDocPtr doc;
if (argc &lt;= 1) {
printf(&quot;Usage: %s docname\n&quot;, argv[0]);
if (argc &lt;= 2) {
printf(&quot;Usage: %s docname, uri\n&quot;, argv[0]);
return(0);
}
docname = argv[1];
parseDoc (docname);
uri = argv[2];
doc = parseDoc (docname, uri);
if (doc != NULL) {
xmlSaveFormatFile (docname, doc, 1);
xmlFreeDoc(doc);
}
return (1);
}
</pre><p>
</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 Add Attribute 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 Encoding Conversion Example</td></tr></table></div></body></html>
</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 Add Keyword 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 Retrieving Attribute Value Example</td></tr></table></div></body></html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>F.Code for Encoding Conversion Example</title><meta name="generator" content="DocBook XSL Stylesheets V1.60.1"><link rel="home" href="index.html" title="Libxml Tutorial"><link rel="up" href="index.html" title="Libxml Tutorial"><link rel="previous" href="ape.html" title="E.Code for Retrieving Attribute Value Example"><link rel="next" href="ix01.html" title="Index"></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">F.Code for Encoding Conversion Example</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ape.html">Prev</a></td><th width="60%" align="center"></th><td width="20%" align="right"><a accesskey="n" href="ix01.html">Next</a></td></tr></table><hr></div><div class="appendix" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="convertappendix"></a>F.Code for Encoding Conversion Example</h2></div></div><div></div></div><p>
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>F.Code for Retrieving Attribute Value Example</title><meta name="generator" content="DocBook XSL Stylesheets V1.60.1"><link rel="home" href="index.html" title="Libxml Tutorial"><link rel="up" href="index.html" title="Libxml Tutorial"><link rel="previous" href="ape.html" title="E.Code for Add Attribute Example"><link rel="next" href="apg.html" title="G.Code for Encoding Conversion 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">F.Code for Retrieving Attribute Value Example</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ape.html">Prev</a></td><th width="60%" align="center"></th><td width="20%" align="right"><a accesskey="n" href="apg.html">Next</a></td></tr></table><hr></div><div class="appendix" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="getattributeappendix"></a>F.Code for Retrieving Attribute Value Example</h2></div></div><div></div></div><p>
</p><pre class="programlisting">
#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;libxml/xmlmemory.h&gt;
#include &lt;libxml/parser.h&gt;
void
getReference (xmlDocPtr doc, xmlNodePtr cur) {
unsigned char*
convert (unsigned char *in, char *encoding)
{
unsigned char *out;
int ret,size,out_size,temp;
xmlCharEncodingHandlerPtr handler;
xmlChar *uri;
cur = cur-&gt;xmlChildrenNode;
while (cur != NULL) {
if ((!xmlStrcmp(cur-&gt;name, (const xmlChar *)&quot;reference&quot;))) {
uri = xmlGetProp(cur, &quot;uri&quot;);
printf(&quot;uri: %s\n&quot;, uri);
xmlFree(uri);
}
cur = cur-&gt;next;
}
return;
}
size = (int)strlen(in)+1;
out_size = size*2-1;
out = malloc((size_t)out_size);
if (out) {
handler = xmlFindCharEncodingHandler(encoding);
if (!handler) {
free(out);
out = NULL;
}
}
if (out) {
temp=size-1;
ret = handler-&gt;input(out, &amp;out_size, in, &amp;temp);
if (ret || temp-size+1) {
if (ret) {
printf(&quot;conversion wasn't successful.\n&quot;);
} else {
printf(&quot;conversion wasn't successful. converted: %i octets.\n&quot;,temp);
}
free(out);
out = NULL;
} else {
out = realloc(out,out_size+1);
out[out_size]=0; /*null terminating out*/
}
} else {
printf(&quot;no mem\n&quot;);
}
return (out);
}
void
parseDoc(char *docname) {
xmlDocPtr doc;
xmlNodePtr cur;
doc = xmlParseFile(docname);
if (doc == NULL ) {
fprintf(stderr,&quot;Document not parsed successfully. \n&quot;);
return;
}
cur = xmlDocGetRootElement(doc);
if (cur == NULL) {
fprintf(stderr,&quot;empty document\n&quot;);
xmlFreeDoc(doc);
return;
}
if (xmlStrcmp(cur-&gt;name, (const xmlChar *) &quot;story&quot;)) {
fprintf(stderr,&quot;document of the wrong type, root node != story&quot;);
xmlFreeDoc(doc);
return;
}
getReference (doc, cur);
xmlFreeDoc(doc);
return;
}
int
main(int argc, char **argv) {
unsigned char *content, *out;
xmlDocPtr doc;
xmlNodePtr rootnode;
char *encoding = &quot;ISO-8859-1&quot;;
char *docname;
if (argc &lt;= 1) {
printf(&quot;Usage: %s content\n&quot;, argv[0]);
printf(&quot;Usage: %s docname\n&quot;, argv[0]);
return(0);
}
content = argv[1];
out = convert(content, encoding);
doc = xmlNewDoc (&quot;1.0&quot;);
rootnode = xmlNewDocNode(doc, NULL, (const xmlChar*)&quot;root&quot;, out);
xmlDocSetRootElement(doc, rootnode);
xmlSaveFormatFileEnc(&quot;-&quot;, doc, encoding, 1);
docname = argv[1];
parseDoc (docname);
return (1);
}
</pre><p>
</p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ape.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="ix01.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">E.Code for Retrieving Attribute Value Example</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">Index</td></tr></table></div></body></html>
</p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ape.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="apg.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">E.Code for Add Attribute Example</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">G.Code for Encoding Conversion Example</td></tr></table></div></body></html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>G.Acknowledgements</title><meta name="generator" content="DocBook XSL Stylesheets V1.60.1"><link rel="home" href="index.html" title="Libxml Tutorial"><link rel="up" href="index.html" title="Libxml Tutorial"><link rel="previous" href="ix01.html" title="Index"></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">G.Acknowledgements</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ix01.html">Prev</a></td><th width="60%" align="center"></th><td width="20%" align="right"></td></tr></table><hr></div><div class="appendix" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="id2877795"></a>G.Acknowledgements</h2></div></div><div></div></div><p>A number of people have generously offered feedback, code and
suggested improvements to this tutorial. In no particular order:
<span class="simplelist">Daniel Veillard, Marcus Labib Iskander, Christopher R. Harris, Igor Zlatkovic, Niraj Tolia</span>
</p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ix01.html">Prev</a></td><td width="20%" align="center"><a accesskey="u" href="index.html">Up</a></td><td width="40%" align="right"></td></tr><tr><td width="40%" align="left" valign="top">Index</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"></td></tr></table></div></body></html>
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>G.Code for Encoding Conversion Example</title><meta name="generator" content="DocBook XSL Stylesheets V1.60.1"><link rel="home" href="index.html" title="Libxml Tutorial"><link rel="up" href="index.html" title="Libxml Tutorial"><link rel="previous" href="apf.html" title="F.Code for Retrieving Attribute Value Example"><link rel="next" href="aph.html" title="H.Acknowledgements"></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">G.Code for Encoding Conversion Example</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="apf.html">Prev</a></td><th width="60%" align="center"></th><td width="20%" align="right"><a accesskey="n" href="aph.html">Next</a></td></tr></table><hr></div><div class="appendix" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="convertappendix"></a>G.Code for Encoding Conversion Example</h2></div></div><div></div></div><p>
</p><pre class="programlisting">
#include &lt;string.h&gt;
#include &lt;libxml/parser.h&gt;
unsigned char*
convert (unsigned char *in, char *encoding)
{
unsigned char *out;
int ret,size,out_size,temp;
xmlCharEncodingHandlerPtr handler;
size = (int)strlen(in)+1;
out_size = size*2-1;
out = malloc((size_t)out_size);
if (out) {
handler = xmlFindCharEncodingHandler(encoding);
if (!handler) {
free(out);
out = NULL;
}
}
if (out) {
temp=size-1;
ret = handler-&gt;input(out, &amp;out_size, in, &amp;temp);
if (ret || temp-size+1) {
if (ret) {
printf(&quot;conversion wasn't successful.\n&quot;);
} else {
printf(&quot;conversion wasn't successful. converted: %i octets.\n&quot;,temp);
}
free(out);
out = NULL;
} else {
out = realloc(out,out_size+1);
out[out_size]=0; /*null terminating out*/
}
} else {
printf(&quot;no mem\n&quot;);
}
return (out);
}