aboutsummaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
authorMDT 2002 John Fleck <jfleck@inkstain.net>2002-06-13 03:30:26 +0000
committerJohn Fleck <jfleck@src.gnome.org>2002-06-13 03:30:26 +0000
commit54520837add57527ec0c0ccc34d37cc1e3c51aa2 (patch)
tree0d79ab4f7295943aba0c95586531f486ec0cfd8a /doc
parentf5582f156c82962e669f68c8cd6b8ea4d3277086 (diff)
downloadandroid_external_libxml2-54520837add57527ec0c0ccc34d37cc1e3c51aa2.tar.gz
android_external_libxml2-54520837add57527ec0c0ccc34d37cc1e3c51aa2.tar.bz2
android_external_libxml2-54520837add57527ec0c0ccc34d37cc1e3c51aa2.zip
doc/tutorial/xmltutorial.xml doc/tutorial/ar01s07.html
Wed Jun 12 21:26:08 MDT 2002 John Fleck <jfleck@inkstain.net> * doc/tutorial/xmltutorial.xml * doc/tutorial/ar01s07.html * doc/tutorial/ape.html * doc/tutorial/includegetattribute.c adding section to tutorial about retrieving an attribute value
Diffstat (limited to 'doc')
-rw-r--r--doc/tutorial/apa.html4
-rw-r--r--doc/tutorial/apd.html4
-rw-r--r--doc/tutorial/ape.html73
-rw-r--r--doc/tutorial/ar01s06.html4
-rw-r--r--doc/tutorial/ar01s07.html35
-rw-r--r--doc/tutorial/includegetattribute.c69
-rw-r--r--doc/tutorial/index.html5
-rw-r--r--doc/tutorial/xmltutorial.xml72
8 files changed, 245 insertions, 21 deletions
diff --git a/doc/tutorial/apa.html b/doc/tutorial/apa.html
index d01ea2ed..375fb695 100644
--- a/doc/tutorial/apa.html
+++ b/doc/tutorial/apa.html
@@ -1,5 +1,5 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
-<html><head><meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type"><title>A. Sample Document</title><meta name="generator" content="DocBook XSL Stylesheets V1.48"><link rel="home" href="index.html" title="Libxml Tutorial"><link rel="up" href="index.html" title="Libxml Tutorial"><link rel="previous" href="ar01s06.html" title="Writing Attribute"><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="ar01s06.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"><h2 class="title" style="clear: both"><a name="sampledoc"></a>A. Sample Document</h2><pre class="programlisting">
+<html><head><meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type"><title>A. Sample Document</title><meta name="generator" content="DocBook XSL Stylesheets V1.48"><link rel="home" href="index.html" title="Libxml Tutorial"><link rel="up" href="index.html" title="Libxml Tutorial"><link rel="previous" href="ar01s07.html" title="Retrieving Attributes"><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="ar01s07.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"><h2 class="title" style="clear: both"><a name="sampledoc"></a>A. Sample Document</h2><pre class="programlisting">
&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;story&gt;
&lt;storyinfo&gt;
@@ -12,4 +12,4 @@
&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="ar01s06.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">Writing Attribute </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>
+</pre></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ar01s07.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">Retrieving Attributes </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>
diff --git a/doc/tutorial/apd.html b/doc/tutorial/apd.html
index 66cddfe3..5e56f3c5 100644
--- a/doc/tutorial/apd.html
+++ b/doc/tutorial/apd.html
@@ -1,5 +1,5 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
-<html><head><meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type"><title>D. Code for Add Attribute Example</title><meta name="generator" content="DocBook XSL Stylesheets V1.48"><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"></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"> </td></tr></table><hr></div><div class="appendix"><h2 class="title" style="clear: both"><a name="addattributeappendix"></a>D. Code for Add Attribute Example</h2><p>
+<html><head><meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type"><title>D. Code for Add Attribute Example</title><meta name="generator" content="DocBook XSL Stylesheets V1.48"><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"><h2 class="title" style="clear: both"><a name="addattributeappendix"></a>D. Code for Add Attribute Example</h2><p>
<pre class="programlisting">
#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
@@ -64,4 +64,4 @@ main(int argc, char **argv) {
}
</pre>
- </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"> </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"> </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 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>
diff --git a/doc/tutorial/ape.html b/doc/tutorial/ape.html
new file mode 100644
index 00000000..9be15e85
--- /dev/null
+++ b/doc/tutorial/ape.html
@@ -0,0 +1,73 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html><head><meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type"><title>E. Code for Retrieving Attribute Value Example</title><meta name="generator" content="DocBook XSL Stylesheets V1.48"><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"></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"> </td></tr></table><hr></div><div class="appendix"><h2 class="title" style="clear: both"><a name="getattributeappendix"></a>E. Code for Retrieving Attribute Value Example</h2><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) {
+
+ cur = cur-&gt;xmlChildrenNode;
+ while (cur != NULL) {
+ if ((!xmlStrcmp(cur-&gt;name, (const xmlChar *)&quot;reference&quot;))) {
+ printf(&quot;uri: %s\n&quot;, xmlGetProp(cur, &quot;uri&quot;));
+ }
+ cur = cur-&gt;next;
+ }
+ return;
+}
+
+
+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);
+
+ 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></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"> </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"> </td></tr></table></div></body></html>
diff --git a/doc/tutorial/ar01s06.html b/doc/tutorial/ar01s06.html
index 8d2afd15..2bbd2dfa 100644
--- a/doc/tutorial/ar01s06.html
+++ b/doc/tutorial/ar01s06.html
@@ -1,5 +1,5 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
-<html><head><meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type"><title>Writing Attribute</title><meta name="generator" content="DocBook XSL Stylesheets V1.48"><link rel="home" href="index.html" title="Libxml Tutorial"><link rel="up" href="index.html" title="Libxml Tutorial"><link rel="previous" href="ar01s05.html" title="Writing element content"><link rel="next" href="apa.html" title="A. 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">Writing Attribute</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ar01s05.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="apa.html">Next</a></td></tr></table><hr></div><div class="sect1"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="xmltutorialwritingattribute"></a>Writing Attribute</h2></div></div><p>Writing an attribute is similar to writing text to a new element. In
+<html><head><meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type"><title>Writing Attribute</title><meta name="generator" content="DocBook XSL Stylesheets V1.48"><link rel="home" href="index.html" title="Libxml Tutorial"><link rel="up" href="index.html" title="Libxml Tutorial"><link rel="previous" href="ar01s05.html" title="Writing element content"><link rel="next" href="ar01s07.html" title="Retrieving Attributes"></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">Writing Attribute</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ar01s05.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="ar01s07.html">Next</a></td></tr></table><hr></div><div class="sect1"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="xmltutorialwritingattribute"></a>Writing Attribute</h2></div></div><p>Writing an attribute is similar to writing text to a new element. In
this case, we'll add a reference URI to our
document. Full code:<a href="apd.html" title="D. Code for Add Attribute Example">Appendix D</a>.</p><p>
A <tt class="sgmltag-element">reference</tt> is a child of the <tt class="sgmltag-element">story</tt>
@@ -27,4 +27,4 @@
<div class="calloutlist"><table border="0" summary="Callout list"><tr><td width="5%" valign="top" align="left"><a href="#addreferencenode"><img src="images/callouts/1.png" alt="1" border="0"></a> </td><td valign="top" align="left"><p>First we add a new node at the location of the current node
pointer, <tt>cur.</tt> using the <a href="http://xmlsoft.org/html/libxml-tree.html#XMLNEWTEXTCHILD" target="_top">xmlNewTextChild</a> function.</p></td></tr></table></div>
</p><p>Once the node is added, the file is written to disk just as in the
- previous example in which we added an element with text content.</p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ar01s05.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="apa.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Writing element content </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> A. Sample Document</td></tr></table></div></body></html>
+ previous example in which we added an element with text content.</p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ar01s05.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="ar01s07.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Writing element content </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Retrieving Attributes</td></tr></table></div></body></html>
diff --git a/doc/tutorial/ar01s07.html b/doc/tutorial/ar01s07.html
new file mode 100644
index 00000000..7dda324c
--- /dev/null
+++ b/doc/tutorial/ar01s07.html
@@ -0,0 +1,35 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html><head><meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type"><title>Retrieving Attributes</title><meta name="generator" content="DocBook XSL Stylesheets V1.48"><link rel="home" href="index.html" title="Libxml Tutorial"><link rel="up" href="index.html" title="Libxml Tutorial"><link rel="previous" href="ar01s06.html" title="Writing Attribute"><link rel="next" href="apa.html" title="A. 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">Retrieving Attributes</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ar01s06.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="apa.html">Next</a></td></tr></table><hr></div><div class="sect1"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="xmltutorialattribute"></a>Retrieving Attributes</h2></div></div><p>Retrieving the value of an attribute is similar to the previous
+ example in which we retrieved a node's text contents. In this case we'll
+ extract the value of the URI we added in the previous
+ section. Full code: <a href="ape.html" title="E. Code for Retrieving Attribute Value Example">Appendix E</a>.</p><p>
+ The initial steps for this example are similar to the previous ones: parse
+ the doc, find the element you are interested in, then enter a function to
+ carry out the specific task required. In this case, we call
+ <tt>getReference</tt>:
+ <pre class="programlisting">
+void
+getReference (xmlDocPtr doc, xmlNodePtr cur) {
+
+ cur = cur-&gt;xmlChildrenNode;
+ while (cur != NULL) {
+ if ((!xmlStrcmp(cur-&gt;name, (const xmlChar *)&quot;reference&quot;))) {
+ <a name="getattributevalue"></a><img src="images/callouts/1.png" alt="1" border="0"> printf(&quot;uri: %s\n&quot;, xmlGetProp(cur, &quot;uri&quot;));
+ }
+ cur = cur-&gt;next;
+ }
+ return;
+}
+ </pre>
+
+ <div class="calloutlist"><table border="0" summary="Callout list"><tr><td width="5%" valign="top" align="left"><a href="#getattributevalue"><img src="images/callouts/1.png" alt="1" border="0"></a> </td><td valign="top" align="left"><p>
+ The key function is <tt><a href="http://xmlsoft.org/html/libxml-tree.html#XMLGETPROP" target="_top">xmlGetProp</a></tt>, which returns an
+ <tt>xmlChar</tt> containing the attribute's value. In this case,
+ we just print it out.
+ <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
+ If you are using a DTD that declares a fixed or
+ default value for the attribute, this function will retrieve it.
+ </p></div>
+ </p></td></tr></table></div>
+
+ </p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ar01s06.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="apa.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Writing Attribute </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> A. Sample Document</td></tr></table></div></body></html>
diff --git a/doc/tutorial/includegetattribute.c b/doc/tutorial/includegetattribute.c
new file mode 100644
index 00000000..f934667e
--- /dev/null
+++ b/doc/tutorial/includegetattribute.c
@@ -0,0 +1,69 @@
+<![CDATA[
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <libxml/xmlmemory.h>
+#include <libxml/parser.h>
+
+void
+getReference (xmlDocPtr doc, xmlNodePtr cur) {
+
+ cur = cur->xmlChildrenNode;
+ while (cur != NULL) {
+ if ((!xmlStrcmp(cur->name, (const xmlChar *)"reference"))) {
+ printf("uri: %s\n", xmlGetProp(cur, "uri"));
+ }
+ cur = cur->next;
+ }
+ return;
+}
+
+
+void
+parseDoc(char *docname) {
+
+ xmlDocPtr doc;
+ xmlNodePtr cur;
+
+ doc = xmlParseFile(docname);
+
+ if (doc == NULL ) {
+ fprintf(stderr,"Document not parsed successfully. \n");
+ return;
+ }
+
+ cur = xmlDocGetRootElement(doc);
+
+ if (cur == NULL) {
+ fprintf(stderr,"empty document\n");
+ xmlFreeDoc(doc);
+ return;
+ }
+
+ if (xmlStrcmp(cur->name, (const xmlChar *) "story")) {
+ fprintf(stderr,"document of the wrong type, root node != story");
+ xmlFreeDoc(doc);
+ return;
+ }
+
+ getReference (doc, cur);
+
+ return;
+}
+
+int
+main(int argc, char **argv) {
+
+ char *docname;
+
+ if (argc <= 1) {
+ printf("Usage: %s docname\n", argv[0]);
+ return(0);
+ }
+
+ docname = argv[1];
+ parseDoc (docname);
+
+ return (1);
+}
+]]>
diff --git a/doc/tutorial/index.html b/doc/tutorial/index.html
index eef00e37..3dee1480 100644
--- a/doc/tutorial/index.html
+++ b/doc/tutorial/index.html
@@ -1,5 +1,5 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
-<html><head><meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type"><title>Libxml Tutorial</title><meta name="generator" content="DocBook XSL Stylesheets V1.48"><link rel="home" href="index.html" title="Libxml Tutorial"><link rel="next" href="ar01s02.html" title="Data Types"></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">Libxml Tutorial</th></tr><tr><td width="20%" align="left"> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="ar01s02.html">Next</a></td></tr></table><hr></div><div class="article"><div class="titlepage"><div><h1 class="title"><a name="id2759085"></a>Libxml Tutorial</h1></div><div><h3 class="author">John Fleck</h3></div><div><p class="copyright">Copyright © 2002 John Fleck</p></div><div><div class="revhistory"><table border="1" width="100%" summary="Revision history"><tr><th align="left" valign="top" colspan="2"><b>Revision History</b></th></tr><tr><td align="left">Revision 1</td><td align="left">June 4,2002</td></tr></table></div></div><hr></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="index.html#introduction">Introduction</a></dt><dt><a href="ar01s02.html">Data Types</a></dt><dt><a href="ar01s03.html">Parsing the file</a></dt><dt><a href="ar01s04.html">Retrieving Element Content</a></dt><dt><a href="ar01s05.html">Writing element content</a></dt><dt><a href="ar01s06.html">Writing Attribute</a></dt><dt>A. <a href="apa.html">Sample Document</a></dt><dt>B. <a href="apb.html">Code for Keyword Example</a></dt><dt>C. <a href="apc.html">Code for Add Keyword Example</a></dt><dt>D. <a href="apd.html">Code for Add Attribute Example</a></dt></dl></div><div class="abstract"><p><b>Abstract</b></p><p>Libxml is a freely licensed C language library for handling
+<html><head><meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type"><title>Libxml Tutorial</title><meta name="generator" content="DocBook XSL Stylesheets V1.48"><link rel="home" href="index.html" title="Libxml Tutorial"><link rel="next" href="ar01s02.html" title="Data Types"></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">Libxml Tutorial</th></tr><tr><td width="20%" align="left"> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="ar01s02.html">Next</a></td></tr></table><hr></div><div class="article"><div class="titlepage"><div><h1 class="title"><a name="id2755382"></a>Libxml Tutorial</h1></div><div><h3 class="author">John Fleck</h3></div><div><p class="copyright">Copyright © 2002 John Fleck</p></div><div><div class="revhistory"><table border="1" width="100%" summary="Revision history"><tr><th align="left" valign="top" colspan="2"><b>Revision History</b></th></tr><tr><td align="left">Revision 1</td><td align="left">June 4,2002</td></tr><tr><td align="left">Revision 2</td><td align="left">June 12, 2002</td></tr></table></div></div><hr></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="index.html#introduction">Introduction</a></dt><dt><a href="ar01s02.html">Data Types</a></dt><dt><a href="ar01s03.html">Parsing the file</a></dt><dt><a href="ar01s04.html">Retrieving Element Content</a></dt><dt><a href="ar01s05.html">Writing element content</a></dt><dt><a href="ar01s06.html">Writing Attribute</a></dt><dt><a href="ar01s07.html">Retrieving Attributes</a></dt><dt>A. <a href="apa.html">Sample Document</a></dt><dt>B. <a href="apb.html">Code for Keyword Example</a></dt><dt>C. <a href="apc.html">Code for Add Keyword Example</a></dt><dt>D. <a href="apd.html">Code for Add Attribute Example</a></dt><dt>E. <a href="ape.html">Code for Retrieving Attribute Value Example</a></dt></dl></div><div class="abstract"><p><b>Abstract</b></p><p>Libxml is a freely licensed C language library for handling
XML, portable across a large number of platforms. This
tutorial provides examples of its basic functions.</p></div><div class="sect1"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="introduction"></a>Introduction</h2></div></div><p>Libxml is a C language library implementing functions for reading,
creating and manipulating XML data. This tutorial
@@ -11,6 +11,5 @@
</p><p>The tutorial is based on a simple XML application I
use for articles I write. The format includes metadata and the body
of the article.</p><p>The example code in this tutorial demonstrates how to:
- <div class="itemizedlist"><ul type="disc"><li><p>Parse the document.</p></li><li><p>Extract the text within a specified element.</p></li><li><p>Add an element and its content.</p></li><li><p>Extract the value of an attribute.</p></li><li><p>Add an attribute.</p></li></ul></div>
-
+ <div class="itemizedlist"><ul type="disc"><li><p>Parse the document.</p></li><li><p>Extract the text within a specified element.</p></li><li><p>Add an element and its content.</p></li><li><p>Add an attribute.</p></li><li><p>Extract the value of an attribute.</p></li></ul></div>
</p><p>Full code for the examples is included in the appendices.</p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"> </td><td width="20%" align="center"> </td><td width="40%" align="right"> <a accesskey="n" href="ar01s02.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top"> </td><td width="20%" align="center"> </td><td width="40%" align="right" valign="top"> Data Types</td></tr></table></div></body></html>
diff --git a/doc/tutorial/xmltutorial.xml b/doc/tutorial/xmltutorial.xml
index be9a1ba3..e73ec3a4 100644
--- a/doc/tutorial/xmltutorial.xml
+++ b/doc/tutorial/xmltutorial.xml
@@ -5,6 +5,7 @@
<!ENTITY STORY SYSTEM "includestory.xml">
<!ENTITY ADDKEYWORD SYSTEM "includeaddkeyword.c">
<!ENTITY ADDATTRIBUTE SYSTEM "includeaddattribute.c">
+<!ENTITY GETATTRIBUTE SYSTEM "includegetattribute.c">
]>
<article>
<articleinfo>
@@ -22,6 +23,10 @@
<revnumber>1</revnumber>
<date>June 4,2002</date>
</revision>
+ <revision>
+ <revnumber>2</revnumber>
+ <date>June 12, 2002</date>
+ </revision>
</revhistory>
</articleinfo>
<abstract>
@@ -59,13 +64,12 @@
<para>Add an element and its content.</para>
</listitem>
<listitem>
- <para>Extract the value of an attribute.</para>
- </listitem>
- <listitem>
<para>Add an attribute.</para>
+ </listitem>
+ <listitem>
+ <para>Extract the value of an attribute.</para>
</listitem>
</itemizedlist>
-
</para>
<para>Full code for the examples is included in the appendices.</para>
@@ -288,15 +292,7 @@ parseStory (xmlDocPtr doc, xmlNodePtr cur, char *keyword) {
the old file. The second parameter is a pointer to the xmlDoc
structure. Setting the third parameter equal to one ensures indenting on output.
</para>
-
</sect1>
-<!--
- <sect1 id="xmltutorialattribute">
- <title>Retrieving Attributes</title>
- <para>Retrieving</para>
- </sect1>
--->
-
<sect1 id="xmltutorialwritingattribute">
<title>Writing Attribute</title>
@@ -341,6 +337,52 @@ parseStory (xmlDocPtr doc, xmlNodePtr cur, char *keyword) {
</sect1>
+ <sect1 id="xmltutorialattribute">
+ <title>Retrieving Attributes</title>
+ <para>Retrieving the value of an attribute is similar to the previous
+ example in which we retrieved a node's text contents. In this case we'll
+ extract the value of the <acronym>URI</acronym> we added in the previous
+ section. Full code: <xref linkend="getattributeappendix" />.</para>
+ <para>
+ The initial steps for this example are similar to the previous ones: parse
+ the doc, find the element you are interested in, then enter a function to
+ carry out the specific task required. In this case, we call
+ <function>getReference</function>:
+ <programlisting>
+void
+getReference (xmlDocPtr doc, xmlNodePtr cur) {
+
+ cur = cur->xmlChildrenNode;
+ while (cur != NULL) {
+ if ((!xmlStrcmp(cur->name, (const xmlChar *)"reference"))) {
+ <co id="getattributevalue" /> printf("uri: %s\n", xmlGetProp(cur, "uri"));
+ }
+ cur = cur->next;
+ }
+ return;
+}
+ </programlisting>
+
+ <calloutlist>
+ <callout arearefs="getattributevalue">
+ <para>
+ The key function is <function><ulink
+ url="http://xmlsoft.org/html/libxml-tree.html#XMLGETPROP">xmlGetProp</ulink></function>, which returns an
+ <varname>xmlChar</varname> containing the attribute's value. In this case,
+ we just print it out.
+ <note>
+ <para>
+ If you are using a <acronym>DTD</acronym> that declares a fixed or
+ default value for the attribute, this function will retrieve it.
+ </para>
+ </note>
+ </para>
+ </callout>
+ </calloutlist>
+
+ </para>
+ </sect1>
+
<!--
<appendix id="furtherresources">
<title>Further Resources</title>
@@ -369,4 +411,10 @@ parseStory (xmlDocPtr doc, xmlNodePtr cur, char *keyword) {
<programlisting>&ADDATTRIBUTE;</programlisting>
</para>
</appendix>
+<appendix id="getattributeappendix">
+ <title>Code for Retrieving Attribute Value Example</title>
+ <para>
+ <programlisting>&GETATTRIBUTE;</programlisting>
+ </para>
+ </appendix>
</article>