mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-10-23 01:52:48 +03:00
doc/tutorial/xmltutorial.xml doc/tutorial/xmltutorial.pdf
Sat Feb 14 18:55:40 MST 2004 John Fleck <jfleck@inkstain.net> * doc/tutorial/xmltutorial.xml * doc/tutorial/xmltutorial.pdf * doc/tutorial/*.html Fix bug in XPath example in the tutorial, thanks to Carlos, whose last name I don't know, for pointing this out
This commit is contained in:
committed by
John Fleck
parent
5c9547e4f3
commit
d14bccc241
@@ -1,4 +1,4 @@
|
|||||||
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>A.<2E>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="ar01s09.html" title="Encoding Conversion"><link rel="next" href="apb.html" title="B.<2E>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.<2E>Compilation</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ar01s09.html">Prev</a><EFBFBD></td><th width="60%" align="center"><EFBFBD></th><td width="20%" align="right"><EFBFBD><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.<2E>Compilation</h2></div></div><div></div></div><p><a class="indexterm" name="id2815990"></a>
|
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>A.<2E>Compilation</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="ar01s09.html" title="Encoding Conversion"><link rel="next" href="apb.html" title="B.<2E>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.<2E>Compilation</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ar01s09.html">Prev</a><EFBFBD></td><th width="60%" align="center"><EFBFBD></th><td width="20%" align="right"><EFBFBD><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.<2E>Compilation</h2></div></div><div></div></div><p><a class="indexterm" name="id2509671"></a>
|
||||||
<span class="application">Libxml</span> includes a script,
|
<span class="application">Libxml</span> includes a script,
|
||||||
<span class="application">xml2-config</span>, that can be used to generate
|
<span class="application">xml2-config</span>, that can be used to generate
|
||||||
flags for compilation and linking of programs written with the
|
flags for compilation and linking of programs written with the
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>B.<2E>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.<2E>Compilation"><link rel="next" href="apc.html" title="C.<2E>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.<2E>Sample Document</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="apa.html">Prev</a><EFBFBD></td><th width="60%" align="center"><EFBFBD></th><td width="20%" align="right"><EFBFBD><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.<2E>Sample Document</h2></div></div><div></div></div><pre class="programlisting">
|
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>B.<2E>Sample Document</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="apa.html" title="A.<2E>Compilation"><link rel="next" href="apc.html" title="C.<2E>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.<2E>Sample Document</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="apa.html">Prev</a><EFBFBD></td><th width="60%" align="center"><EFBFBD></th><td width="20%" align="right"><EFBFBD><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.<2E>Sample Document</h2></div></div><div></div></div><pre class="programlisting">
|
||||||
<?xml version="1.0"?>
|
<?xml version="1.0"?>
|
||||||
<story>
|
<story>
|
||||||
<storyinfo>
|
<storyinfo>
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>C.<2E>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.<2E>Sample Document"><link rel="next" href="apd.html" title="D.<2E>Code for XPath 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.<2E>Code for Keyword Example</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="apb.html">Prev</a><EFBFBD></td><th width="60%" align="center"><EFBFBD></th><td width="20%" align="right"><EFBFBD><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.<2E>Code for 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.<2E>Code for 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="apb.html" title="B.<2E>Sample Document"><link rel="next" href="apd.html" title="D.<2E>Code for XPath 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.<2E>Code for Keyword Example</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="apb.html">Prev</a><EFBFBD></td><th width="60%" align="center"><EFBFBD></th><td width="20%" align="right"><EFBFBD><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.<2E>Code for Keyword Example</h2></div></div><div></div></div><p>
|
||||||
</p><pre class="programlisting">
|
</p><pre class="programlisting">
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>D.<2E>Code for XPath 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.<2E>Code for Keyword Example"><link rel="next" href="ape.html" title="E.<2E>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.<2E>Code for XPath Example</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="apc.html">Prev</a><EFBFBD></td><th width="60%" align="center"><EFBFBD></th><td width="20%" align="right"><EFBFBD><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="xpathappendix"></a>D.<2E>Code for XPath Example</h2></div></div><div></div></div><p>
|
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>D.<2E>Code for XPath 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="apc.html" title="C.<2E>Code for Keyword Example"><link rel="next" href="ape.html" title="E.<2E>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.<2E>Code for XPath Example</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="apc.html">Prev</a><EFBFBD></td><th width="60%" align="center"><EFBFBD></th><td width="20%" align="right"><EFBFBD><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="xpathappendix"></a>D.<2E>Code for XPath Example</h2></div></div><div></div></div><p>
|
||||||
</p><pre class="programlisting">
|
</p><pre class="programlisting">
|
||||||
#include <libxml/parser.h>
|
#include <libxml/parser.h>
|
||||||
#include <libxml/xpath.h>
|
#include <libxml/xpath.h>
|
||||||
@@ -55,10 +55,10 @@ main(int argc, char **argv) {
|
|||||||
for (i=0; i < nodeset->nodeNr; i++) {
|
for (i=0; i < nodeset->nodeNr; i++) {
|
||||||
keyword = xmlNodeListGetString(doc, nodeset->nodeTab[i]->xmlChildrenNode, 1);
|
keyword = xmlNodeListGetString(doc, nodeset->nodeTab[i]->xmlChildrenNode, 1);
|
||||||
printf("keyword: %s\n", keyword);
|
printf("keyword: %s\n", keyword);
|
||||||
|
xmlFree(keyword);
|
||||||
}
|
}
|
||||||
|
xmlXPathFreeObject (result);
|
||||||
}
|
}
|
||||||
xmlXPathFreeObject (result);
|
|
||||||
xmlFree(keyword);
|
|
||||||
xmlFreeDoc(doc);
|
xmlFreeDoc(doc);
|
||||||
xmlCleanupParser();
|
xmlCleanupParser();
|
||||||
return (1);
|
return (1);
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>E.<2E>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="apd.html" title="D.<2E>Code for XPath Example"><link rel="next" href="apf.html" title="F.<2E>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.<2E>Code for Add Keyword Example</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="apd.html">Prev</a><EFBFBD></td><th width="60%" align="center"><EFBFBD></th><td width="20%" align="right"><EFBFBD><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.<2E>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>E.<2E>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.<2E>Code for XPath Example"><link rel="next" href="apf.html" title="F.<2E>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.<2E>Code for Add Keyword Example</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="apd.html">Prev</a><EFBFBD></td><th width="60%" align="center"><EFBFBD></th><td width="20%" align="right"><EFBFBD><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.<2E>Code for Add Keyword Example</h2></div></div><div></div></div><p>
|
||||||
</p><pre class="programlisting">
|
</p><pre class="programlisting">
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>F.<2E>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="ape.html" title="E.<2E>Code for Add Keyword Example"><link rel="next" href="apg.html" title="G.<2E>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">F.<2E>Code for Add Attribute Example</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ape.html">Prev</a><EFBFBD></td><th width="60%" align="center"><EFBFBD></th><td width="20%" align="right"><EFBFBD><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="addattributeappendix"></a>F.<2E>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>F.<2E>Code for Add Attribute 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="ape.html" title="E.<2E>Code for Add Keyword Example"><link rel="next" href="apg.html" title="G.<2E>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">F.<2E>Code for Add Attribute Example</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ape.html">Prev</a><EFBFBD></td><th width="60%" align="center"><EFBFBD></th><td width="20%" align="right"><EFBFBD><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="addattributeappendix"></a>F.<2E>Code for Add Attribute Example</h2></div></div><div></div></div><p>
|
||||||
</p><pre class="programlisting">
|
</p><pre class="programlisting">
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>G.<2E>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="apf.html" title="F.<2E>Code for Add Attribute Example"><link rel="next" href="aph.html" title="H.<2E>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">G.<2E>Code for Retrieving Attribute Value Example</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="apf.html">Prev</a><EFBFBD></td><th width="60%" align="center"><EFBFBD></th><td width="20%" align="right"><EFBFBD><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="getattributeappendix"></a>G.<2E>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>G.<2E>Code for Retrieving Attribute Value 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="apf.html" title="F.<2E>Code for Add Attribute Example"><link rel="next" href="aph.html" title="H.<2E>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">G.<2E>Code for Retrieving Attribute Value Example</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="apf.html">Prev</a><EFBFBD></td><th width="60%" align="center"><EFBFBD></th><td width="20%" align="right"><EFBFBD><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="getattributeappendix"></a>G.<2E>Code for Retrieving Attribute Value Example</h2></div></div><div></div></div><p>
|
||||||
</p><pre class="programlisting">
|
</p><pre class="programlisting">
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>H.<2E>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="apg.html" title="G.<2E>Code for Retrieving Attribute Value Example"><link rel="next" href="api.html" title="I.<2E>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">H.<2E>Code for Encoding Conversion Example</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="apg.html">Prev</a><EFBFBD></td><th width="60%" align="center"><EFBFBD></th><td width="20%" align="right"><EFBFBD><a accesskey="n" href="api.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>H.<2E>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>H.<2E>Code for Encoding Conversion 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="apg.html" title="G.<2E>Code for Retrieving Attribute Value Example"><link rel="next" href="api.html" title="I.<2E>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">H.<2E>Code for Encoding Conversion Example</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="apg.html">Prev</a><EFBFBD></td><th width="60%" align="center"><EFBFBD></th><td width="20%" align="right"><EFBFBD><a accesskey="n" href="api.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>H.<2E>Code for Encoding Conversion Example</h2></div></div><div></div></div><p>
|
||||||
</p><pre class="programlisting">
|
</p><pre class="programlisting">
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <libxml/parser.h>
|
#include <libxml/parser.h>
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>I.<2E>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="aph.html" title="H.<2E>Code for Encoding Conversion 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">I.<2E>Acknowledgements</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="aph.html">Prev</a><EFBFBD></td><th width="60%" align="center"><EFBFBD></th><td width="20%" align="right"><EFBFBD><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="id2882392"></a>I.<2E>Acknowledgements</h2></div></div><div></div></div><p>A number of people have generously offered feedback, code and
|
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>I.<2E>Acknowledgements</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="aph.html" title="H.<2E>Code for Encoding Conversion 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">I.<2E>Acknowledgements</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="aph.html">Prev</a><EFBFBD></td><th width="60%" align="center"><EFBFBD></th><td width="20%" align="right"><EFBFBD><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="id2510287"></a>I.<2E>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:
|
suggested improvements to this tutorial. In no particular order:
|
||||||
<span class="simplelist">Daniel Veillard, Marcus Labib Iskander, Christopher R. Harris, Igor Zlatkovic, Niraj Tolia, David Turover</span>
|
<span class="simplelist">Daniel Veillard, Marcus Labib Iskander, Christopher R. Harris, Igor Zlatkovic, Niraj Tolia, David Turover</span>
|
||||||
</p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="aph.html">Prev</a><EFBFBD></td><td width="20%" align="center"><a accesskey="u" href="index.html">Up</a></td><td width="40%" align="right"><EFBFBD><a accesskey="n" href="ix01.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">H.<2E>Code for Encoding Conversion Example<6C></td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"><EFBFBD>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="aph.html">Prev</a><EFBFBD></td><td width="20%" align="center"><a accesskey="u" href="index.html">Up</a></td><td width="40%" align="right"><EFBFBD><a accesskey="n" href="ix01.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">H.<2E>Code for Encoding Conversion Example<6C></td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"><EFBFBD>Index</td></tr></table></div></body></html>
|
||||||
|
@@ -1,13 +1,13 @@
|
|||||||
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Data Types</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="index.html" title="Libxml Tutorial"><link rel="next" href="ar01s03.html" title="Parsing the file"></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">Data Types</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="index.html">Prev</a><EFBFBD></td><th width="60%" align="center"><EFBFBD></th><td width="20%" align="right"><EFBFBD><a accesskey="n" href="ar01s03.html">Next</a></td></tr></table><hr></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="xmltutorialdatatypes"></a>Data Types</h2></div></div><div></div></div><p><span class="application">Libxml</span> declares a number of data types we
|
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Data Types</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="index.html" title="Libxml Tutorial"><link rel="next" href="ar01s03.html" title="Parsing the file"></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">Data Types</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="index.html">Prev</a><EFBFBD></td><th width="60%" align="center"><EFBFBD></th><td width="20%" align="right"><EFBFBD><a accesskey="n" href="ar01s03.html">Next</a></td></tr></table><hr></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="xmltutorialdatatypes"></a>Data Types</h2></div></div><div></div></div><p><span class="application">Libxml</span> declares a number of data types we
|
||||||
will encounter repeatedly, hiding the messy stuff so you do not have to deal
|
will encounter repeatedly, hiding the messy stuff so you do not have to deal
|
||||||
with it unless you have some specific need.</p><p>
|
with it unless you have some specific need.</p><p>
|
||||||
</p><div class="variablelist"><dl><dt><span class="term"><a class="indexterm" name="id2813490"></a>
|
</p><div class="variablelist"><dl><dt><span class="term"><a class="indexterm" name="id2496072"></a>
|
||||||
<a href="http://xmlsoft.org/html/libxml-tree.html#XMLCHAR" target="_top">xmlChar</a></span></dt><dd><p>A basic replacement for char, a byte in a UTF-8 encoded
|
<a href="http://xmlsoft.org/html/libxml-tree.html#XMLCHAR" target="_top">xmlChar</a></span></dt><dd><p>A basic replacement for char, a byte in a UTF-8 encoded
|
||||||
string. If your data uses another encoding, it must be converted to
|
string. If your data uses another encoding, it must be converted to
|
||||||
UTF-8 for use with <span class="application">libxml's</span>
|
UTF-8 for use with <span class="application">libxml's</span>
|
||||||
functions. More information on encoding is available on the <a href="http://www.xmlsoft.org/encoding.html" target="_top"><span class="application">libxml</span> encoding support web page</a>.</p></dd><dt><span class="term"><a class="indexterm" name="id2813547"></a>
|
functions. More information on encoding is available on the <a href="http://www.xmlsoft.org/encoding.html" target="_top"><span class="application">libxml</span> encoding support web page</a>.</p></dd><dt><span class="term"><a class="indexterm" name="id2448173"></a>
|
||||||
<a href="http://xmlsoft.org/html/libxml-tree.html#XMLDOC" target="_top">xmlDoc</a></span></dt><dd><p>A structure containing the tree created by a parsed doc. <a href="http://xmlsoft.org/html/libxml-tree.html#XMLDOCPTR" target="_top">xmlDocPtr</a>
|
<a href="http://xmlsoft.org/html/libxml-tree.html#XMLDOC" target="_top">xmlDoc</a></span></dt><dd><p>A structure containing the tree created by a parsed doc. <a href="http://xmlsoft.org/html/libxml-tree.html#XMLDOCPTR" target="_top">xmlDocPtr</a>
|
||||||
is a pointer to the structure.</p></dd><dt><span class="term"><a class="indexterm" name="id2813589"></a>
|
is a pointer to the structure.</p></dd><dt><span class="term"><a class="indexterm" name="id2448206"></a>
|
||||||
<a href="http://xmlsoft.org/html/libxml-tree.html#XMLNODEPTR" target="_top">xmlNodePtr</a>
|
<a href="http://xmlsoft.org/html/libxml-tree.html#XMLNODEPTR" target="_top">xmlNodePtr</a>
|
||||||
and <a href="http://xmlsoft.org/html/libxml-tree.html#XMLNODE" target="_top">xmlNode</a></span></dt><dd><p>A structure containing a single node. <a href="http://xmlsoft.org/html/libxml-tree.html#XMLNODEPTR" target="_top">xmlNodePtr</a>
|
and <a href="http://xmlsoft.org/html/libxml-tree.html#XMLNODE" target="_top">xmlNode</a></span></dt><dd><p>A structure containing a single node. <a href="http://xmlsoft.org/html/libxml-tree.html#XMLNODEPTR" target="_top">xmlNodePtr</a>
|
||||||
is a pointer to the structure, and is used in traversing the document tree.</p></dd></dl></div><p>
|
is a pointer to the structure, and is used in traversing the document tree.</p></dd></dl></div><p>
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Parsing the file</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="ar01s02.html" title="Data Types"><link rel="next" href="ar01s04.html" title="Retrieving Element Content"></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">Parsing the file</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ar01s02.html">Prev</a><EFBFBD></td><th width="60%" align="center"><EFBFBD></th><td width="20%" align="right"><EFBFBD><a accesskey="n" href="ar01s04.html">Next</a></td></tr></table><hr></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="xmltutorialparsing"></a>Parsing the file</h2></div></div><div></div></div><p><a class="indexterm" name="fileparsing"></a>
|
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Parsing the file</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="ar01s02.html" title="Data Types"><link rel="next" href="ar01s04.html" title="Retrieving Element Content"></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">Parsing the file</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ar01s02.html">Prev</a><EFBFBD></td><th width="60%" align="center"><EFBFBD></th><td width="20%" align="right"><EFBFBD><a accesskey="n" href="ar01s04.html">Next</a></td></tr></table><hr></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="xmltutorialparsing"></a>Parsing the file</h2></div></div><div></div></div><p><a class="indexterm" name="fileparsing"></a>
|
||||||
Parsing the file requires only the name of the file and a single
|
Parsing the file requires only the name of the file and a single
|
||||||
function call, plus error checking. Full code: <a href="apc.html" title="C.<2E>Code for Keyword Example">Appendix<EFBFBD>C, <i>Code for Keyword Example</i></a></p><p>
|
function call, plus error checking. Full code: <a href="apc.html" title="C.<2E>Code for Keyword Example">Appendix<EFBFBD>C, <i>Code for Keyword Example</i></a></p><p>
|
||||||
</p><pre class="programlisting">
|
</p><pre class="programlisting">
|
||||||
@@ -31,7 +31,7 @@ Parsing the file requires only the name of the file and a single
|
|||||||
interact with individual nodes).</p></td></tr><tr><td width="5%" valign="top" align="left"><a href="#checkparseerror"><img src="images/callouts/4.png" alt="4" border="0"></a> </td><td valign="top" align="left"><p>Check to see that the document was successfully parsed. If it
|
interact with individual nodes).</p></td></tr><tr><td width="5%" valign="top" align="left"><a href="#checkparseerror"><img src="images/callouts/4.png" alt="4" border="0"></a> </td><td valign="top" align="left"><p>Check to see that the document was successfully parsed. If it
|
||||||
was not, <span class="application">libxml</span> will at this point
|
was not, <span class="application">libxml</span> will at this point
|
||||||
register an error and stop.
|
register an error and stop.
|
||||||
</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p><a class="indexterm" name="id2813921"></a>
|
</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note"><tr><td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="images/note.png"></td><th align="left">Note</th></tr><tr><td colspan="2" align="left" valign="top"><p><a class="indexterm" name="id2447307"></a>
|
||||||
One common example of an error at this point is improper
|
One common example of an error at this point is improper
|
||||||
handling of encoding. The <span class="acronym">XML</span> standard requires
|
handling of encoding. The <span class="acronym">XML</span> standard requires
|
||||||
documents stored with an encoding other than UTF-8 or UTF-16 to
|
documents stored with an encoding other than UTF-8 or UTF-16 to
|
||||||
@@ -39,9 +39,9 @@ One common example of an error at this point is improper
|
|||||||
declaration is there, <span class="application">libxml</span> will
|
declaration is there, <span class="application">libxml</span> will
|
||||||
automatically perform the necessary conversion to UTF-8 for
|
automatically perform the necessary conversion to UTF-8 for
|
||||||
you. More information on <span class="acronym">XML's</span> encoding
|
you. More information on <span class="acronym">XML's</span> encoding
|
||||||
requirements is contained in the <a href="http://www.w3.org/TR/REC-xml#charencoding" target="_top">standard</a>.</p></div><p>
|
requirements is contained in the <a href="http://www.w3.org/TR/REC-xml#charencoding" target="_top">standard</a>.</p></td></tr></table></div><p>
|
||||||
</p></td></tr><tr><td width="5%" valign="top" align="left"><a href="#getrootelement"><img src="images/callouts/5.png" alt="5" border="0"></a> </td><td valign="top" align="left"><p>Retrieve the document's root element.</p></td></tr><tr><td width="5%" valign="top" align="left"><a href="#checkemptyerror"><img src="images/callouts/6.png" alt="6" border="0"></a> </td><td valign="top" align="left"><p>Check to make sure the document actually contains something.</p></td></tr><tr><td width="5%" valign="top" align="left"><a href="#checkroottype"><img src="images/callouts/7.png" alt="7" border="0"></a> </td><td valign="top" align="left"><p>In our case, we need to make sure the document is the right
|
</p></td></tr><tr><td width="5%" valign="top" align="left"><a href="#getrootelement"><img src="images/callouts/5.png" alt="5" border="0"></a> </td><td valign="top" align="left"><p>Retrieve the document's root element.</p></td></tr><tr><td width="5%" valign="top" align="left"><a href="#checkemptyerror"><img src="images/callouts/6.png" alt="6" border="0"></a> </td><td valign="top" align="left"><p>Check to make sure the document actually contains something.</p></td></tr><tr><td width="5%" valign="top" align="left"><a href="#checkroottype"><img src="images/callouts/7.png" alt="7" border="0"></a> </td><td valign="top" align="left"><p>In our case, we need to make sure the document is the right
|
||||||
type. "story" is the root type of the documents used in this
|
type. "story" is the root type of the documents used in this
|
||||||
tutorial.</p></td></tr></table></div><p>
|
tutorial.</p></td></tr></table></div><p>
|
||||||
<a class="indexterm" name="id2814015"></a>
|
<a class="indexterm" name="id2447385"></a>
|
||||||
</p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ar01s02.html">Prev</a><EFBFBD></td><td width="20%" align="center"><a accesskey="u" href="index.html">Up</a></td><td width="40%" align="right"><EFBFBD><a accesskey="n" href="ar01s04.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Data Types<65></td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"><EFBFBD>Retrieving Element Content</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="ar01s02.html">Prev</a><EFBFBD></td><td width="20%" align="center"><a accesskey="u" href="index.html">Up</a></td><td width="40%" align="right"><EFBFBD><a accesskey="n" href="ar01s04.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Data Types<65></td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"><EFBFBD>Retrieving Element Content</td></tr></table></div></body></html>
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Retrieving Element Content</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="ar01s03.html" title="Parsing the file"><link rel="next" href="ar01s05.html" title="Using XPath to Retrieve Element Content"></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 Element Content</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ar01s03.html">Prev</a><EFBFBD></td><th width="60%" align="center"><EFBFBD></th><td width="20%" align="right"><EFBFBD><a accesskey="n" href="ar01s05.html">Next</a></td></tr></table><hr></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="xmltutorialgettext"></a>Retrieving Element Content</h2></div></div><div></div></div><p><a class="indexterm" name="id2814041"></a>
|
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Retrieving Element Content</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="ar01s03.html" title="Parsing the file"><link rel="next" href="ar01s05.html" title="Using XPath to Retrieve Element Content"></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 Element Content</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ar01s03.html">Prev</a><EFBFBD></td><th width="60%" align="center"><EFBFBD></th><td width="20%" align="right"><EFBFBD><a accesskey="n" href="ar01s05.html">Next</a></td></tr></table><hr></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="xmltutorialgettext"></a>Retrieving Element Content</h2></div></div><div></div></div><p><a class="indexterm" name="id2447408"></a>
|
||||||
Retrieving the content of an element involves traversing the document
|
Retrieving the content of an element involves traversing the document
|
||||||
tree until you find what you are looking for. In this case, we are looking
|
tree until you find what you are looking for. In this case, we are looking
|
||||||
for an element called "keyword" contained within element called "story". The
|
for an element called "keyword" contained within element called "story". The
|
||||||
@@ -48,7 +48,7 @@ parseStory (xmlDocPtr doc, xmlNodePtr cur) {
|
|||||||
its contents. Remember that in <span class="acronym">XML</span>, the text
|
its contents. Remember that in <span class="acronym">XML</span>, the text
|
||||||
contained within an element is a child node of that element, so we
|
contained within an element is a child node of that element, so we
|
||||||
turn to <tt class="varname">cur->xmlChildrenNode</tt>. To retrieve it, we
|
turn to <tt class="varname">cur->xmlChildrenNode</tt>. To retrieve it, we
|
||||||
use the function <tt class="function"><a href="http://xmlsoft.org/html/libxml-tree.html#XMLNODELISTGETSTRING" target="_top">xmlNodeListGetString</a></tt>, which also takes the <tt class="varname">doc</tt> pointer as an argument. In this case, we just print it out.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>Because <tt class="function">xmlNodeListGetString</tt> allocates
|
use the function <tt class="function"><a href="http://xmlsoft.org/html/libxml-tree.html#XMLNODELISTGETSTRING" target="_top">xmlNodeListGetString</a></tt>, which also takes the <tt class="varname">doc</tt> pointer as an argument. In this case, we just print it out.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note"><tr><td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="images/note.png"></td><th align="left">Note</th></tr><tr><td colspan="2" align="left" valign="top"><p>Because <tt class="function">xmlNodeListGetString</tt> allocates
|
||||||
memory for the string it returns, you must use
|
memory for the string it returns, you must use
|
||||||
<tt class="function">xmlFree</tt> to free it.</p></div></td></tr></table></div><p>
|
<tt class="function">xmlFree</tt> to free it.</p></td></tr></table></div></td></tr></table></div><p>
|
||||||
</p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ar01s03.html">Prev</a><EFBFBD></td><td width="20%" align="center"><a accesskey="u" href="index.html">Up</a></td><td width="40%" align="right"><EFBFBD><a accesskey="n" href="ar01s05.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Parsing the file<6C></td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"><EFBFBD>Using XPath to Retrieve Element Content</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="ar01s03.html">Prev</a><EFBFBD></td><td width="20%" align="center"><a accesskey="u" href="index.html">Up</a></td><td width="40%" align="right"><EFBFBD><a accesskey="n" href="ar01s05.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Parsing the file<6C></td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"><EFBFBD>Using XPath to Retrieve Element Content</td></tr></table></div></body></html>
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Using XPath to Retrieve Element Content</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="ar01s04.html" title="Retrieving Element Content"><link rel="next" href="ar01s06.html" title="Writing element content"></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">Using XPath to Retrieve Element Content</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ar01s04.html">Prev</a><EFBFBD></td><th width="60%" align="center"><EFBFBD></th><td width="20%" align="right"><EFBFBD><a accesskey="n" href="ar01s06.html">Next</a></td></tr></table><hr></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="xmltutorialxpath"></a>Using XPath to Retrieve Element Content</h2></div></div><div></div></div><p>In addition to walking the document tree to find an element,
|
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Using XPath to Retrieve Element Content</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="ar01s04.html" title="Retrieving Element Content"><link rel="next" href="ar01s06.html" title="Writing element content"></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">Using XPath to Retrieve Element Content</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ar01s04.html">Prev</a><EFBFBD></td><th width="60%" align="center"><EFBFBD></th><td width="20%" align="right"><EFBFBD><a accesskey="n" href="ar01s06.html">Next</a></td></tr></table><hr></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="xmltutorialxpath"></a>Using XPath to Retrieve Element Content</h2></div></div><div></div></div><p>In addition to walking the document tree to find an element,
|
||||||
<span class="application">Libxml2</span> includes support for
|
<span class="application">Libxml2</span> includes support for
|
||||||
use of <span class="application">XPath</span> expressions to retrieve sets of
|
use of <span class="application">XPath</span> expressions to retrieve sets of
|
||||||
nodes that match a specified criteria. Full documentation of the
|
nodes that match a specified criteria. Full documentation of the
|
||||||
@@ -7,8 +7,8 @@
|
|||||||
for nodes that match specified criteria. In the example below we search
|
for nodes that match specified criteria. In the example below we search
|
||||||
through a document for the contents of all <tt class="varname">keyword</tt>
|
through a document for the contents of all <tt class="varname">keyword</tt>
|
||||||
elements.
|
elements.
|
||||||
</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>A full discussion of <span class="application">XPath</span> is beyond
|
</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note"><tr><td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="images/note.png"></td><th align="left">Note</th></tr><tr><td colspan="2" align="left" valign="top"><p>A full discussion of <span class="application">XPath</span> is beyond
|
||||||
the scope of this document. For details on its use, see the <a href="http://www.w3.org/TR/xpath" target="_top">XPath specification</a>.</p></div><p>
|
the scope of this document. For details on its use, see the <a href="http://www.w3.org/TR/xpath" target="_top">XPath specification</a>.</p></td></tr></table></div><p>
|
||||||
Full code for this example is at <a href="apd.html" title="D.<2E>Code for XPath Example">Appendix<EFBFBD>D, <i>Code for XPath Example</i></a>.
|
Full code for this example is at <a href="apd.html" title="D.<2E>Code for XPath Example">Appendix<EFBFBD>D, <i>Code for XPath Example</i></a>.
|
||||||
</p><p>Using <span class="application">XPath</span> requires setting up an
|
</p><p>Using <span class="application">XPath</span> requires setting up an
|
||||||
xmlXPathContext and then supplying the <span class="application">XPath</span>
|
xmlXPathContext and then supplying the <span class="application">XPath</span>
|
||||||
@@ -44,12 +44,13 @@
|
|||||||
<a name="conodesetcounter"></a><img src="images/callouts/1.png" alt="1" border="0">for (i=0; i < nodeset->nodeNr; i++) {
|
<a name="conodesetcounter"></a><img src="images/callouts/1.png" alt="1" border="0">for (i=0; i < nodeset->nodeNr; i++) {
|
||||||
<a name="coprintkeywords"></a><img src="images/callouts/2.png" alt="2" border="0">keyword = xmlNodeListGetString(doc, nodeset->nodeTab[i]->xmlChildrenNode, 1);
|
<a name="coprintkeywords"></a><img src="images/callouts/2.png" alt="2" border="0">keyword = xmlNodeListGetString(doc, nodeset->nodeTab[i]->xmlChildrenNode, 1);
|
||||||
printf("keyword: %s\n", keyword);
|
printf("keyword: %s\n", keyword);
|
||||||
|
xmlFree(keyword);
|
||||||
}
|
}
|
||||||
</pre><p>
|
</pre><p>
|
||||||
</p><div class="calloutlist"><table border="0" summary="Callout list"><tr><td width="5%" valign="top" align="left"><a href="#conodesetcounter"><img src="images/callouts/1.png" alt="1" border="0"></a> </td><td valign="top" align="left"><p>The value of <tt class="varname">nodeset->Nr</tt> holds the number of
|
</p><div class="calloutlist"><table border="0" summary="Callout list"><tr><td width="5%" valign="top" align="left"><a href="#conodesetcounter"><img src="images/callouts/1.png" alt="1" border="0"></a> </td><td valign="top" align="left"><p>The value of <tt class="varname">nodeset->Nr</tt> holds the number of
|
||||||
elements in the node set. Here we use it to iterate through the array.</p></td></tr><tr><td width="5%" valign="top" align="left"><a href="#coprintkeywords"><img src="images/callouts/2.png" alt="2" border="0"></a> </td><td valign="top" align="left"><p>Here we print the contents of each of the nodes returned.
|
elements in the node set. Here we use it to iterate through the array.</p></td></tr><tr><td width="5%" valign="top" align="left"><a href="#coprintkeywords"><img src="images/callouts/2.png" alt="2" border="0"></a> </td><td valign="top" align="left"><p>Here we print the contents of each of the nodes returned.
|
||||||
</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>Note that we are printing the child node of the node that is
|
</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note"><tr><td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="images/note.png"></td><th align="left">Note</th></tr><tr><td colspan="2" align="left" valign="top"><p>Note that we are printing the child node of the node that is
|
||||||
returned, because the contents of the <tt class="varname">keyword</tt>
|
returned, because the contents of the <tt class="varname">keyword</tt>
|
||||||
element are a child text node.</p></div><p>
|
element are a child text node.</p></td></tr></table></div><p>
|
||||||
</p></td></tr></table></div><p>
|
</p></td></tr></table></div><p>
|
||||||
</p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ar01s04.html">Prev</a><EFBFBD></td><td width="20%" align="center"><a accesskey="u" href="index.html">Up</a></td><td width="40%" align="right"><EFBFBD><a accesskey="n" href="ar01s06.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Retrieving Element Content<6E></td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"><EFBFBD>Writing element content</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="ar01s04.html">Prev</a><EFBFBD></td><td width="20%" align="center"><a accesskey="u" href="index.html">Up</a></td><td width="40%" align="right"><EFBFBD><a accesskey="n" href="ar01s06.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Retrieving Element Content<6E></td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"><EFBFBD>Writing element content</td></tr></table></div></body></html>
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Writing element content</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="ar01s05.html" title="Using XPath to Retrieve Element Content"><link rel="next" href="ar01s07.html" title="Writing Attribute"></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 element content</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ar01s05.html">Prev</a><EFBFBD></td><th width="60%" align="center"><EFBFBD></th><td width="20%" align="right"><EFBFBD><a accesskey="n" href="ar01s07.html">Next</a></td></tr></table><hr></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="xmltutorialwritingcontent"></a>Writing element content</h2></div></div><div></div></div><p><a class="indexterm" name="id2815235"></a>
|
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Writing element content</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="ar01s05.html" title="Using XPath to Retrieve Element Content"><link rel="next" href="ar01s07.html" title="Writing Attribute"></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 element content</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ar01s05.html">Prev</a><EFBFBD></td><th width="60%" align="center"><EFBFBD></th><td width="20%" align="right"><EFBFBD><a accesskey="n" href="ar01s07.html">Next</a></td></tr></table><hr></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="xmltutorialwritingcontent"></a>Writing element content</h2></div></div><div></div></div><p><a class="indexterm" name="id2508968"></a>
|
||||||
Writing element content uses many of the same steps we used above
|
Writing element content uses many of the same steps we used above
|
||||||
— parsing the document and walking the tree. We parse the document,
|
— parsing the document and walking the tree. We parse the document,
|
||||||
then traverse the tree to find the place we want to insert our element. For
|
then traverse the tree to find the place we want to insert our element. For
|
||||||
@@ -21,7 +21,7 @@ parseStory (xmlDocPtr doc, xmlNodePtr cur, char *keyword) {
|
|||||||
current node pointer's location in the
|
current node pointer's location in the
|
||||||
tree, specified by <tt class="varname">cur</tt>.</p></td></tr></table></div><p>
|
tree, specified by <tt class="varname">cur</tt>.</p></td></tr></table></div><p>
|
||||||
</p><p>
|
</p><p>
|
||||||
<a class="indexterm" name="id2815335"></a>
|
<a class="indexterm" name="id2509052"></a>
|
||||||
Once the node has been added, we would like to write the document to
|
Once the node has been added, we would like to write the document to
|
||||||
file. Is you want the element to have a namespace, you can add it here as
|
file. Is you want the element to have a namespace, you can add it here as
|
||||||
well. In our case, the namespace is NULL.
|
well. In our case, the namespace is NULL.
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Writing Attribute</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="ar01s06.html" title="Writing element content"><link rel="next" href="ar01s08.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="ar01s06.html">Prev</a><EFBFBD></td><th width="60%" align="center"><EFBFBD></th><td width="20%" align="right"><EFBFBD><a accesskey="n" href="ar01s08.html">Next</a></td></tr></table><hr></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="xmltutorialwritingattribute"></a>Writing Attribute</h2></div></div><div></div></div><p><a class="indexterm" name="id2815386"></a>
|
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Writing Attribute</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="ar01s06.html" title="Writing element content"><link rel="next" href="ar01s08.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="ar01s06.html">Prev</a><EFBFBD></td><th width="60%" align="center"><EFBFBD></th><td width="20%" align="right"><EFBFBD><a accesskey="n" href="ar01s08.html">Next</a></td></tr></table><hr></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="xmltutorialwritingattribute"></a>Writing Attribute</h2></div></div><div></div></div><p><a class="indexterm" name="id2509094"></a>
|
||||||
Writing an attribute is similar to writing text to a new element. In
|
Writing an attribute is similar to writing text to a new element. In
|
||||||
this case, we'll add a reference <span class="acronym">URI</span> to our
|
this case, we'll add a reference <span class="acronym">URI</span> to our
|
||||||
document. Full code:<a href="apf.html" title="F.<2E>Code for Add Attribute Example">Appendix<EFBFBD>F, <i>Code for Add Attribute Example</i></a>.</p><p>
|
document. Full code:<a href="apf.html" title="F.<2E>Code for Add Attribute Example">Appendix<EFBFBD>F, <i>Code for Add Attribute Example</i></a>.</p><p>
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Retrieving Attributes</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="ar01s07.html" title="Writing Attribute"><link rel="next" href="ar01s09.html" title="Encoding Conversion"></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="ar01s07.html">Prev</a><EFBFBD></td><th width="60%" align="center"><EFBFBD></th><td width="20%" align="right"><EFBFBD><a accesskey="n" href="ar01s09.html">Next</a></td></tr></table><hr></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="xmltutorialattribute"></a>Retrieving Attributes</h2></div></div><div></div></div><p><a class="indexterm" name="id2815553"></a>
|
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Retrieving Attributes</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="ar01s07.html" title="Writing Attribute"><link rel="next" href="ar01s09.html" title="Encoding Conversion"></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="ar01s07.html">Prev</a><EFBFBD></td><th width="60%" align="center"><EFBFBD></th><td width="20%" align="right"><EFBFBD><a accesskey="n" href="ar01s09.html">Next</a></td></tr></table><hr></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="xmltutorialattribute"></a>Retrieving Attributes</h2></div></div><div></div></div><p><a class="indexterm" name="id2509236"></a>
|
||||||
Retrieving the value of an attribute is similar to the previous
|
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
|
example in which we retrieved a node's text contents. In this case we'll
|
||||||
extract the value of the <span class="acronym">URI</span> we added in the previous
|
extract the value of the <span class="acronym">URI</span> we added in the previous
|
||||||
@@ -29,10 +29,10 @@ getReference (xmlDocPtr doc, xmlNodePtr cur) {
|
|||||||
The key function is <tt class="function"><a href="http://xmlsoft.org/html/libxml-tree.html#XMLGETPROP" target="_top">xmlGetProp</a></tt>, which returns an
|
The key function is <tt class="function"><a href="http://xmlsoft.org/html/libxml-tree.html#XMLGETPROP" target="_top">xmlGetProp</a></tt>, which returns an
|
||||||
<tt class="varname">xmlChar</tt> containing the attribute's value. In this case,
|
<tt class="varname">xmlChar</tt> containing the attribute's value. In this case,
|
||||||
we just print it out.
|
we just print it out.
|
||||||
</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
|
</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note"><tr><td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="images/note.png"></td><th align="left">Note</th></tr><tr><td colspan="2" align="left" valign="top"><p>
|
||||||
If you are using a <span class="acronym">DTD</span> that declares a fixed or
|
If you are using a <span class="acronym">DTD</span> that declares a fixed or
|
||||||
default value for the attribute, this function will retrieve it.
|
default value for the attribute, this function will retrieve it.
|
||||||
</p></div><p>
|
</p></td></tr></table></div><p>
|
||||||
</p></td></tr></table></div><p>
|
</p></td></tr></table></div><p>
|
||||||
|
|
||||||
</p></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><EFBFBD></td><td width="20%" align="center"><a accesskey="u" href="index.html">Up</a></td><td width="40%" align="right"><EFBFBD><a accesskey="n" href="ar01s09.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Writing Attribute<74></td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"><EFBFBD>Encoding Conversion</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="ar01s07.html">Prev</a><EFBFBD></td><td width="20%" align="center"><a accesskey="u" href="index.html">Up</a></td><td width="40%" align="right"><EFBFBD><a accesskey="n" href="ar01s09.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Writing Attribute<74></td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"><EFBFBD>Encoding Conversion</td></tr></table></div></body></html>
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Encoding Conversion</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="Retrieving Attributes"><link rel="next" href="apa.html" title="A.<2E>Compilation"></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">Encoding Conversion</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ar01s08.html">Prev</a><EFBFBD></td><th width="60%" align="center"><EFBFBD></th><td width="20%" align="right"><EFBFBD><a accesskey="n" href="apa.html">Next</a></td></tr></table><hr></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="xmltutorialconvert"></a>Encoding Conversion</h2></div></div><div></div></div><p><a class="indexterm" name="id2815684"></a>
|
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Encoding Conversion</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="ar01s08.html" title="Retrieving Attributes"><link rel="next" href="apa.html" title="A.<2E>Compilation"></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">Encoding Conversion</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ar01s08.html">Prev</a><EFBFBD></td><th width="60%" align="center"><EFBFBD></th><td width="20%" align="right"><EFBFBD><a accesskey="n" href="apa.html">Next</a></td></tr></table><hr></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="xmltutorialconvert"></a>Encoding Conversion</h2></div></div><div></div></div><p><a class="indexterm" name="id2509349"></a>
|
||||||
Data encoding compatibility problems are one of the most common
|
Data encoding compatibility problems are one of the most common
|
||||||
difficulties encountered by programmers new to <span class="acronym">XML</span> in
|
difficulties encountered by programmers new to <span class="acronym">XML</span> in
|
||||||
general and <span class="application">libxml</span> in particular. Thinking
|
general and <span class="application">libxml</span> in particular. Thinking
|
||||||
@@ -18,14 +18,14 @@ Data encoding compatibility problems are one of the most common
|
|||||||
different character formats with ability to convert from any to any. While
|
different character formats with ability to convert from any to any. While
|
||||||
the actual number of supported formats varies between implementations, every
|
the actual number of supported formats varies between implementations, every
|
||||||
<span class="application">iconv</span> implementation is almost guaranteed to
|
<span class="application">iconv</span> implementation is almost guaranteed to
|
||||||
support every format anyone has ever heard of.</p><div class="warning" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Warning</h3><p>A common mistake is to use different formats for the internal data
|
support every format anyone has ever heard of.</p><div class="warning" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Warning"><tr><td rowspan="2" align="center" valign="top" width="25"><img alt="[Warning]" src="images/warning.png"></td><th align="left">Warning</th></tr><tr><td colspan="2" align="left" valign="top"><p>A common mistake is to use different formats for the internal data
|
||||||
in different parts of one's code. The most common case is an application
|
in different parts of one's code. The most common case is an application
|
||||||
that assumes ISO-8859-1 to be the internal data format, combined with
|
that assumes ISO-8859-1 to be the internal data format, combined with
|
||||||
<span class="application">libxml</span>, which assumes UTF-8 to be the
|
<span class="application">libxml</span>, which assumes UTF-8 to be the
|
||||||
internal data format. The result is an application that treats internal
|
internal data format. The result is an application that treats internal
|
||||||
data differently, depending on which code section is executing. The one or
|
data differently, depending on which code section is executing. The one or
|
||||||
the other part of code will then, naturally, misinterpret the data.
|
the other part of code will then, naturally, misinterpret the data.
|
||||||
</p></div><p>This example constructs a simple document, then adds content provided
|
</p></td></tr></table></div><p>This example constructs a simple document, then adds content provided
|
||||||
at the command line to the document's root element and outputs the results
|
at the command line to the document's root element and outputs the results
|
||||||
to <tt class="filename">stdout</tt> in the proper encoding. For this example, we
|
to <tt class="filename">stdout</tt> in the proper encoding. For this example, we
|
||||||
use ISO-8859-1 encoding. The encoding of the string input at the command
|
use ISO-8859-1 encoding. The encoding of the string input at the command
|
||||||
|
@@ -54,10 +54,10 @@ main(int argc, char **argv) {
|
|||||||
for (i=0; i < nodeset->nodeNr; i++) {
|
for (i=0; i < nodeset->nodeNr; i++) {
|
||||||
keyword = xmlNodeListGetString(doc, nodeset->nodeTab[i]->xmlChildrenNode, 1);
|
keyword = xmlNodeListGetString(doc, nodeset->nodeTab[i]->xmlChildrenNode, 1);
|
||||||
printf("keyword: %s\n", keyword);
|
printf("keyword: %s\n", keyword);
|
||||||
|
xmlFree(keyword);
|
||||||
}
|
}
|
||||||
|
xmlXPathFreeObject (result);
|
||||||
}
|
}
|
||||||
xmlXPathFreeObject (result);
|
|
||||||
xmlFree(keyword);
|
|
||||||
xmlFreeDoc(doc);
|
xmlFreeDoc(doc);
|
||||||
xmlCleanupParser();
|
xmlCleanupParser();
|
||||||
return (1);
|
return (1);
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Libxml Tutorial</title><meta name="generator" content="DocBook XSL Stylesheets V1.60.1"><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"><EFBFBD></td><th width="60%" align="center"><EFBFBD></th><td width="20%" align="right"><EFBFBD><a accesskey="n" href="ar01s02.html">Next</a></td></tr></table><hr></div><div class="article" lang="en"><div class="titlepage"><div><div><h1 class="title"><a name="id2759069"></a>Libxml Tutorial</h1></div><div><div class="author"><h3 class="author"><span class="firstname">John</span> <span class="surname">Fleck</span></h3></div></div><div><p class="copyright">Copyright <20> 2002, 2003 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" colspan="2">Initial draft</td></tr><tr><td align="left">Revision 2</td><td align="left">June 12, 2002</td></tr><tr><td align="left" colspan="2">retrieving attribute value added</td></tr><tr><td align="left">Revision 3</td><td align="left">Aug. 31, 2002</td></tr><tr><td align="left" colspan="2">freeing memory fix</td></tr><tr><td align="left">Revision 4</td><td align="left">Nov. 10, 2002</td></tr><tr><td align="left" colspan="2">encoding discussion added</td></tr><tr><td align="left">Revision 5</td><td align="left">Dec. 15, 2002</td></tr><tr><td align="left" colspan="2">more memory freeing changes</td></tr><tr><td align="left">Revision 6</td><td align="left">Jan. 26. 2003</td></tr><tr><td align="left" colspan="2">add index</td></tr><tr><td align="left">Revision 7</td><td align="left">April 25, 2003</td></tr><tr><td align="left" colspan="2">add compilation appendix</td></tr><tr><td align="left">Revision 8</td><td align="left">July 24, 2003</td></tr><tr><td align="left" colspan="2">add XPath example</td></tr></table></div></div></div><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">Using XPath to Retrieve Element Content</a></dt><dt><a href="ar01s06.html">Writing element content</a></dt><dt><a href="ar01s07.html">Writing Attribute</a></dt><dt><a href="ar01s08.html">Retrieving Attributes</a></dt><dt><a href="ar01s09.html">Encoding Conversion</a></dt><dt>A. <a href="apa.html">Compilation</a></dt><dt>B. <a href="apb.html">Sample Document</a></dt><dt>C. <a href="apc.html">Code for Keyword Example</a></dt><dt>D. <a href="apd.html">Code for XPath Example</a></dt><dt>E. <a href="ape.html">Code for Add Keyword Example</a></dt><dt>F. <a href="apf.html">Code for Add Attribute Example</a></dt><dt>G. <a href="apg.html">Code for Retrieving Attribute Value Example</a></dt><dt>H. <a href="aph.html">Code for Encoding Conversion Example</a></dt><dt>I. <a href="api.html">Acknowledgements</a></dt></dl></div><div class="abstract"><p class="title"><b>Abstract</b></p><p>Libxml is a freely licensed C language library for handling
|
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Libxml Tutorial</title><meta name="generator" content="DocBook XSL Stylesheets V1.61.2"><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"><EFBFBD></td><th width="60%" align="center"><EFBFBD></th><td width="20%" align="right"><EFBFBD><a accesskey="n" href="ar01s02.html">Next</a></td></tr></table><hr></div><div class="article" lang="en"><div class="titlepage"><div><div><h1 class="title"><a name="id2393988"></a>Libxml Tutorial</h1></div><div><div class="author"><h3 class="author"><span class="firstname">John</span> <span class="surname">Fleck</span></h3></div></div><div><p class="copyright">Copyright <20> 2002, 2003 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" colspan="2">Initial draft</td></tr><tr><td align="left">Revision 2</td><td align="left">June 12, 2002</td></tr><tr><td align="left" colspan="2">retrieving attribute value added</td></tr><tr><td align="left">Revision 3</td><td align="left">Aug. 31, 2002</td></tr><tr><td align="left" colspan="2">freeing memory fix</td></tr><tr><td align="left">Revision 4</td><td align="left">Nov. 10, 2002</td></tr><tr><td align="left" colspan="2">encoding discussion added</td></tr><tr><td align="left">Revision 5</td><td align="left">Dec. 15, 2002</td></tr><tr><td align="left" colspan="2">more memory freeing changes</td></tr><tr><td align="left">Revision 6</td><td align="left">Jan. 26. 2003</td></tr><tr><td align="left" colspan="2">add index</td></tr><tr><td align="left">Revision 7</td><td align="left">April 25, 2003</td></tr><tr><td align="left" colspan="2">add compilation appendix</td></tr><tr><td align="left">Revision 8</td><td align="left">July 24, 2003</td></tr><tr><td align="left" colspan="2">add XPath example</td></tr><tr><td align="left">Revision 9</td><td align="left">Feb. 14, 2004</td></tr><tr><td align="left" colspan="2">Fix bug in XPath example</td></tr></table></div></div></div><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">Using XPath to Retrieve Element Content</a></dt><dt><a href="ar01s06.html">Writing element content</a></dt><dt><a href="ar01s07.html">Writing Attribute</a></dt><dt><a href="ar01s08.html">Retrieving Attributes</a></dt><dt><a href="ar01s09.html">Encoding Conversion</a></dt><dt>A. <a href="apa.html">Compilation</a></dt><dt>B. <a href="apb.html">Sample Document</a></dt><dt>C. <a href="apc.html">Code for Keyword Example</a></dt><dt>D. <a href="apd.html">Code for XPath Example</a></dt><dt>E. <a href="ape.html">Code for Add Keyword Example</a></dt><dt>F. <a href="apf.html">Code for Add Attribute Example</a></dt><dt>G. <a href="apg.html">Code for Retrieving Attribute Value Example</a></dt><dt>H. <a href="aph.html">Code for Encoding Conversion Example</a></dt><dt>I. <a href="api.html">Acknowledgements</a></dt></dl></div><div class="abstract"><p class="title"><b>Abstract</b></p><p>Libxml is a freely licensed C language library for handling
|
||||||
<span class="acronym">XML</span>, portable across a large number of platforms. This
|
<span class="acronym">XML</span>, portable across a large number of platforms. This
|
||||||
tutorial provides examples of its basic functions.</p></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="introduction"></a>Introduction</h2></div></div><div></div></div><p>Libxml is a C language library implementing functions for reading,
|
tutorial provides examples of its basic functions.</p></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="introduction"></a>Introduction</h2></div></div><div></div></div><p>Libxml is a C language library implementing functions for reading,
|
||||||
creating and manipulating <span class="acronym">XML</span> data. This tutorial
|
creating and manipulating <span class="acronym">XML</span> data. This tutorial
|
||||||
|
@@ -1 +1 @@
|
|||||||
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Index</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="api.html" title="I.<2E>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">Index</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="api.html">Prev</a><EFBFBD></td><th width="60%" align="center"><EFBFBD></th><td width="20%" align="right"><EFBFBD></td></tr></table><hr></div><div class="index"><div class="titlepage"><div><div><h2 class="title"><a name="id2882762"></a>Index</h2></div></div><div></div></div><div class="index"><div class="indexdiv"><h3>A</h3><dl><dt>attribute</dt><dd><dl><dt>retrieving value, <a href="ar01s08.html">Retrieving Attributes</a></dt><dt>writing, <a href="ar01s07.html">Writing Attribute</a></dt></dl></dd></dl></div><div class="indexdiv"><h3>C</h3><dl><dt>compiler flags, <a href="apa.html">Compilation</a></dt></dl></div><div class="indexdiv"><h3>E</h3><dl><dt>element</dt><dd><dl><dt>retrieving content, <a href="ar01s04.html">Retrieving Element Content</a></dt><dt>writing content, <a href="ar01s06.html">Writing element content</a></dt></dl></dd><dt>encoding, <a href="ar01s03.html">Parsing the file</a>, <a href="ar01s09.html">Encoding Conversion</a></dt></dl></div><div class="indexdiv"><h3>F</h3><dl><dt>file</dt><dd><dl><dt>parsing, <a href="ar01s03.html">Parsing the file</a>-<a href="ar01s03.html">Parsing the file</a></dt><dt>saving, <a href="ar01s06.html">Writing element content</a></dt></dl></dd></dl></div><div class="indexdiv"><h3>X</h3><dl><dt>xmlChar, <a href="ar01s02.html">Data Types</a></dt><dt>xmlDoc, <a href="ar01s02.html">Data Types</a></dt><dt>xmlNodePtr, <a href="ar01s02.html">Data Types</a></dt></dl></div></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="api.html">Prev</a><EFBFBD></td><td width="20%" align="center"><a accesskey="u" href="index.html">Up</a></td><td width="40%" align="right"><EFBFBD></td></tr><tr><td width="40%" align="left" valign="top">I.<2E>Acknowledgements<74></td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"><EFBFBD></td></tr></table></div></body></html>
|
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Index</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="api.html" title="I.<2E>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">Index</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="api.html">Prev</a><EFBFBD></td><th width="60%" align="center"><EFBFBD></th><td width="20%" align="right"><EFBFBD></td></tr></table><hr></div><div class="index"><div class="titlepage"><div><div><h2 class="title"><a name="id2510579"></a>Index</h2></div></div><div></div></div><div class="index"><div class="indexdiv"><h3>A</h3><dl><dt>attribute</dt><dd><dl><dt>retrieving value, <a href="ar01s08.html">Retrieving Attributes</a></dt><dt>writing, <a href="ar01s07.html">Writing Attribute</a></dt></dl></dd></dl></div><div class="indexdiv"><h3>C</h3><dl><dt>compiler flags, <a href="apa.html">Compilation</a></dt></dl></div><div class="indexdiv"><h3>E</h3><dl><dt>element</dt><dd><dl><dt>retrieving content, <a href="ar01s04.html">Retrieving Element Content</a></dt><dt>writing content, <a href="ar01s06.html">Writing element content</a></dt></dl></dd><dt>encoding, <a href="ar01s03.html">Parsing the file</a>, <a href="ar01s09.html">Encoding Conversion</a></dt></dl></div><div class="indexdiv"><h3>F</h3><dl><dt>file</dt><dd><dl><dt>parsing, <a href="ar01s03.html">Parsing the file</a>-<a href="ar01s03.html">Parsing the file</a></dt><dt>saving, <a href="ar01s06.html">Writing element content</a></dt></dl></dd></dl></div><div class="indexdiv"><h3>X</h3><dl><dt>xmlChar, <a href="ar01s02.html">Data Types</a></dt><dt>xmlDoc, <a href="ar01s02.html">Data Types</a></dt><dt>xmlNodePtr, <a href="ar01s02.html">Data Types</a></dt></dl></div></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="api.html">Prev</a><EFBFBD></td><td width="20%" align="center"><a accesskey="u" href="index.html">Up</a></td><td width="40%" align="right"><EFBFBD></td></tr><tr><td width="40%" align="left" valign="top">I.<2E>Acknowledgements<74></td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"><EFBFBD></td></tr></table></div></body></html>
|
||||||
|
File diff suppressed because it is too large
Load Diff
@@ -62,6 +62,11 @@
|
|||||||
<date>July 24, 2003</date>
|
<date>July 24, 2003</date>
|
||||||
<revremark>add XPath example</revremark>
|
<revremark>add XPath example</revremark>
|
||||||
</revision>
|
</revision>
|
||||||
|
<revision>
|
||||||
|
<revnumber>9</revnumber>
|
||||||
|
<date>Feb. 14, 2004</date>
|
||||||
|
<revremark>Fix bug in XPath example</revremark>
|
||||||
|
</revision>
|
||||||
</revhistory>
|
</revhistory>
|
||||||
</articleinfo>
|
</articleinfo>
|
||||||
<abstract>
|
<abstract>
|
||||||
@@ -396,6 +401,7 @@ parseStory (xmlDocPtr doc, xmlNodePtr cur) {
|
|||||||
<co id="conodesetcounter" />for (i=0; i < nodeset->nodeNr; i++) {
|
<co id="conodesetcounter" />for (i=0; i < nodeset->nodeNr; i++) {
|
||||||
<co id="coprintkeywords" />keyword = xmlNodeListGetString(doc, nodeset->nodeTab[i]->xmlChildrenNode, 1);
|
<co id="coprintkeywords" />keyword = xmlNodeListGetString(doc, nodeset->nodeTab[i]->xmlChildrenNode, 1);
|
||||||
printf("keyword: %s\n", keyword);
|
printf("keyword: %s\n", keyword);
|
||||||
|
xmlFree(keyword);
|
||||||
}
|
}
|
||||||
</programlisting>
|
</programlisting>
|
||||||
<calloutlist>
|
<calloutlist>
|
||||||
|
Reference in New Issue
Block a user