summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Veillard <veillard@src.gnome.org>2004-03-25 10:43:16 +0000
committerDaniel Veillard <veillard@src.gnome.org>2004-03-25 10:43:16 +0000
commit88155d85e5474f25214bf7d23f38180b649c7ae6 (patch)
tree36a7511fe539e186cb015b2b1bd4b69858783c2c
parentebe25d492075cb8fa141027e7627dfdfdd0262b8 (diff)
downloadlibxml2-88155d85e5474f25214bf7d23f38180b649c7ae6.tar.gz
Added a couple of parsing examples, Daniel
-rw-r--r--doc/examples/.cvsignore2
-rw-r--r--doc/examples/Makefile.am16
-rw-r--r--doc/examples/examples.xml46
-rw-r--r--doc/examples/index.html2
-rw-r--r--doc/examples/parse3.c60
-rw-r--r--doc/examples/parse4.c137
6 files changed, 261 insertions, 2 deletions
diff --git a/doc/examples/.cvsignore b/doc/examples/.cvsignore
index 00877b27..a27ba491 100644
--- a/doc/examples/.cvsignore
+++ b/doc/examples/.cvsignore
@@ -11,3 +11,5 @@ reader1
reader2
reader3
io1
+parse3
+parse4
diff --git a/doc/examples/Makefile.am b/doc/examples/Makefile.am
index 754e6638..4598ab62 100644
--- a/doc/examples/Makefile.am
+++ b/doc/examples/Makefile.am
@@ -17,7 +17,7 @@ install-data-local:
EXTRA_DIST=examples.xsl index.py test1.xml examples.xml test2.xml writer.xml test3.xml reader1.res reader3.res tree1.res tree2.res io1.res
-noinst_PROGRAMS=xpath1 parse1 parse2 tree1 tree2 testWriter reader1 reader2 reader3 io1
+noinst_PROGRAMS=xpath1 parse1 parse2 tree1 tree2 testWriter reader1 reader2 reader3 io1 parse3 parse4
xpath1_SOURCES=xpath1.c
xpath1_LDFLAGS=
@@ -69,6 +69,16 @@ io1_LDFLAGS=
io1_DEPENDENCIES= $(DEPS)
io1_LDADD= @RDL_LIBS@ $(LDADDS)
+parse3_SOURCES=parse3.c
+parse3_LDFLAGS=
+parse3_DEPENDENCIES= $(DEPS)
+parse3_LDADD= @RDL_LIBS@ $(LDADDS)
+
+parse4_SOURCES=parse4.c
+parse4_LDFLAGS=
+parse4_DEPENDENCIES= $(DEPS)
+parse4_LDADD= @RDL_LIBS@ $(LDADDS)
+
tests: $(noinst_PROGRAMS)
@(echo > .memdump)
@(./parse1 test1.xml)
@@ -89,5 +99,9 @@ tests: $(noinst_PROGRAMS)
@(grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0)
@(./io1 > io1.tmp ; diff io1.tmp io1.res ; rm -f io1.tmp)
@(grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0)
+ @(./parse3)
+ @(grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0)
+ @(./parse4 test3.xml)
+ @(grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0)
diff --git a/doc/examples/examples.xml b/doc/examples/examples.xml
index 9c14221b..f2c9ef8a 100644
--- a/doc/examples/examples.xml
+++ b/doc/examples/examples.xml
@@ -279,6 +279,41 @@
<typedef line='105' file='tree' name='xmlDocPtr'/>
</uses>
</example>
+ <example filename='parse3.c'>
+ <synopsis>Parse an XML document in memory to a tree and free it</synopsis>
+ <purpose>Demonstrate the use of xmlReadMemory() to read an XML file into a tree and and xmlFreeDoc() to free the resulting tree</purpose>
+ <usage>parse3</usage>
+ <test>parse3</test>
+ <author>Daniel Veillard</author>
+ <copy>see Copyright for the status of this software. </copy>
+ <section>Parsing</section>
+ <includes>
+ <include>&lt;libxml/tree.h&gt;</include>
+ <include>&lt;libxml/parser.h&gt;</include>
+ </includes>
+ <uses>
+ <function line='33' file='parser' name='xmlReadMemory'/>
+ </uses>
+ </example>
+ <example filename='parse4.c'>
+ <synopsis>Parse an XML document chunk by chunk to a tree and free it</synopsis>
+ <purpose>Demonstrate the use of xmlCreatePushParserCtxt() and xmlParseChunk() to read an XML file progressively into a tree and and xmlFreeDoc() to free the resulting tree</purpose>
+ <usage>parse4 test3.xml</usage>
+ <test>parse4 test3.xml</test>
+ <author>Daniel Veillard</author>
+ <copy>see Copyright for the status of this software. </copy>
+ <section>Parsing</section>
+ <includes>
+ <include>&lt;libxml/tree.h&gt;</include>
+ <include>&lt;libxml/parser.h&gt;</include>
+ </includes>
+ <uses>
+ <function line='94' file='parser' name='xmlFreeParserCtxt'/>
+ <function line='86' file='parser' name='xmlParseChunk'/>
+ <function line='67' file='parser' name='xmlCreatePushParserCtxt'/>
+ <typedef line='44' file='tree' name='xmlParserCtxtPtr'/>
+ </uses>
+ </example>
<symbols>
<symbol name='LIBXML_TEST_VERSION'>
<ref filename='xpath1.c'/>
@@ -334,6 +369,9 @@
<symbol name='xmlCreateIntSubset'>
<ref filename='tree2.c'/>
</symbol>
+ <symbol name='xmlCreatePushParserCtxt'>
+ <ref filename='parse4.c'/>
+ </symbol>
<symbol name='xmlCtxtReadFile'>
<ref filename='parse2.c'/>
</symbol>
@@ -373,6 +411,7 @@
</symbol>
<symbol name='xmlFreeParserCtxt'>
<ref filename='parse2.c'/>
+ <ref filename='parse4.c'/>
</symbol>
<symbol name='xmlFreeTextReader'>
<ref filename='reader1.c'/>
@@ -437,18 +476,23 @@
<symbol name='xmlNsPtr'>
<ref filename='xpath1.c'/>
</symbol>
+ <symbol name='xmlParseChunk'>
+ <ref filename='parse4.c'/>
+ </symbol>
<symbol name='xmlParseFile'>
<ref filename='xpath1.c'/>
<ref filename='tree1.c'/>
</symbol>
<symbol name='xmlParserCtxtPtr'>
<ref filename='parse2.c'/>
+ <ref filename='parse4.c'/>
</symbol>
<symbol name='xmlReadFile'>
<ref filename='parse1.c'/>
</symbol>
<symbol name='xmlReadMemory'>
<ref filename='io1.c'/>
+ <ref filename='parse3.c'/>
</symbol>
<symbol name='xmlReaderForFile'>
<ref filename='reader1.c'/>
@@ -582,6 +626,8 @@
<section name='Parsing'>
<example filename='parse1.c'/>
<example filename='parse2.c'/>
+ <example filename='parse3.c'/>
+ <example filename='parse4.c'/>
</section>
<section name='Tree'>
<example filename='tree1.c'/>
diff --git a/doc/examples/index.html b/doc/examples/index.html
index 4ee662b0..54784ed4 100644
--- a/doc/examples/index.html
+++ b/doc/examples/index.html
@@ -8,4 +8,4 @@ H2 {font-family: Verdana,Arial,Helvetica}
H3 {font-family: Verdana,Arial,Helvetica}
A:link, A:visited, A:active { text-decoration: underline }
</style><title>Libxml2 set of examples</title></head><body bgcolor="#8b7765" text="#000000" link="#000000" vlink="#000000"><table border="0" width="100%" cellpadding="5" cellspacing="0" align="center"><tr><td width="120"><a href="http://swpat.ffii.org/"><img src="../epatents.png" alt="Action against software patents" /></a></td><td width="180"><a href="http://www.gnome.org/"><img src="../gnome2.png" alt="Gnome2 Logo" /></a><a href="http://www.w3.org/Status"><img src="../w3c.png" alt="W3C Logo" /></a><a href="http://www.redhat.com/"><img src="../redhat.gif" alt="Red Hat Logo" /></a><div align="left"><a href="http://xmlsoft.org/"><img src="../Libxml2-Logo-180x168.gif" alt="Made with Libxml2 Logo" /></a></div></td><td><table border="0" width="90%" cellpadding="2" cellspacing="0" align="center" bgcolor="#000000"><tr><td><table width="100%" border="0" cellspacing="1" cellpadding="3" bgcolor="#fffacd"><tr><td align="center"><h1></h1><h2>Libxml2 set of examples</h2></td></tr></table></td></tr></table></td></tr></table><table border="0" cellpadding="4" cellspacing="0" width="100%" align="center"><tr><td bgcolor="#8b7765"><table border="0" cellspacing="0" cellpadding="2" width="100%"><tr><td valign="top" width="200" bgcolor="#8b7765"><table border="0" cellspacing="0" cellpadding="1" width="100%" bgcolor="#000000"><tr><td><table width="100%" border="0" cellspacing="1" cellpadding="3"><tr><td colspan="1" bgcolor="#eecfa1" align="center"><center><b>Examples Menu</b></center></td></tr><tr><td bgcolor="#fffacd"><form action="../search.php" enctype="application/x-www-form-urlencoded" method="get"><input name="query" type="text" size="20" value="" /><input name="submit" type="submit" value="Search ..." /></form><ul><li><a href="../index.html">Home</a></li><li><a style="font-weight:bold" href="../docs.html">Developer Menu</a></li><li><a style="font-weight:bold" href="../html/index.html">API Menu</a></li><li><a href="#InputOutput">InputOutput Examples</a></li><li><a href="#Parsing">Parsing Examples</a></li><li><a href="#Tree">Tree Examples</a></li><li><a href="#XPath">XPath Examples</a></li><li><a href="#xmlReader">xmlReader Examples</a></li><li><a href="#xmlWriter">xmlWriter Examples</a></li><li><a href="../guidelines.html">XML Guidelines</a></li></ul></td></tr></table><table width="100%" border="0" cellspacing="1" cellpadding="3"><tr><td colspan="1" bgcolor="#eecfa1" align="center"><center><b>Related links</b></center></td></tr><tr><td bgcolor="#fffacd"><ul><li><a href="http://mail.gnome.org/archives/xml/">Mail archive</a></li><li><a href="http://xmlsoft.org/XSLT/">XSLT libxslt</a></li><li><a href="http://phd.cs.unibo.it/gdome2/">DOM gdome2</a></li><li><a href="http://www.aleksey.com/xmlsec/">XML-DSig xmlsec</a></li><li><a href="ftp://xmlsoft.org/">FTP</a></li><li><a href="http://www.zlatkovic.com/projects/libxml/">Windows binaries</a></li><li><a href="http://garypennington.net/libxml2/">Solaris binaries</a></li><li><a href="http://www.zveno.com/open_source/libxml2xslt.html">MacOsX binaries</a></li><li><a href="http://sourceforge.net/projects/libxml2-pas/">Pascal bindings</a></li><li><a href="http://bugzilla.gnome.org/buglist.cgi?product=libxml2">Bug Tracker</a></li></ul></td></tr></table></td></tr></table></td><td valign="top" bgcolor="#8b7765"><table border="0" cellspacing="0" cellpadding="1" width="100%"><tr><td><table border="0" cellspacing="0" cellpadding="1" width="100%" bgcolor="#000000"><tr><td><table border="0" cellpadding="3" cellspacing="1" width="100%"><tr><td bgcolor="#fffacd"><p> The examples are stored per section depending on the main focus
- of the example:</p><ul><li><p><a href="#InputOutput">InputOutput</a> :</p><ul><li><a href="#io1.c">io1.c</a>: Example of custom Input/Output</li></ul></li><li><p><a href="#XPath">XPath</a> :</p><ul><li><a href="#xpath1.c">xpath1.c</a>: Evaluate XPath expression and prints result node set.</li></ul></li><li><p><a href="#xmlWriter">xmlWriter</a> :</p><ul><li><a href="#testWriter.c">testWriter.c</a>: use various APIs for the xmlWriter</li></ul></li><li><p><a href="#Parsing">Parsing</a> :</p><ul><li><a href="#parse1.c">parse1.c</a>: Parse an XML file to a tree and free it</li><li><a href="#parse2.c">parse2.c</a>: Parse and validate an XML file to a tree and free the result</li></ul></li><li><p><a href="#Tree">Tree</a> :</p><ul><li><a href="#tree1.c">tree1.c</a>: Navigates a tree to print element names</li><li><a href="#tree2.c">tree2.c</a>: Creates a tree</li></ul></li><li><p><a href="#xmlReader">xmlReader</a> :</p><ul><li><a href="#reader1.c">reader1.c</a>: Parse an XML file with an xmlReader</li><li><a href="#reader2.c">reader2.c</a>: Parse and validate an XML file with an xmlReader</li><li><a href="#reader3.c">reader3.c</a>: Show how to extract subdocuments with xmlReader</li></ul></li></ul><h2><a name="InputOutput" id="InputOutput"></a>InputOutput Examples</h2><h3><a name="io1.c" href="io1.c" id="io1.c">io1.c</a>: Example of custom Input/Output</h3><p>Demonstrate the use of xmlRegisterInputCallbacks to build a custom I/O layer, this is used in an XInclude method context to show how dynamic document can be built in a clean way.</p><p>Includes:</p><ul><li><a href="../html/libxml-parser.html">&lt;libxml/parser.h&gt;</a></li><li><a href="../html/libxml-xinclude.html">&lt;libxml/xinclude.h&gt;</a></li><li><a href="../html/libxml-tree.html">&lt;libxml/tree.h&gt;</a></li><li><a href="../html/libxml-xmlIO.html">&lt;libxml/xmlIO.h&gt;</a></li></ul><p>Uses:</p><ul><li> line 104: Type <a href="../html/libxml-tree.html#xmlDocPtr">xmlDocPtr</a> from tree.h</li><li> line 116: Macro <a href="../html/libxml-xmlversion.html#LIBXML_TEST_VERSION">LIBXML_TEST_VERSION</a> from xmlversion.h</li><li> line 116: Function <a href="../html/libxml-xmlIO.html#xmlRegisterInputCallbacks">xmlRegisterInputCallbacks</a> from xmlIO.h</li><li> line 123: Function <a href="../html/libxml-parser.html#xmlReadMemory">xmlReadMemory</a> from parser.h</li><li> line 132: Function <a href="../html/libxml-xinclude.html#xmlXIncludeProcess">xmlXIncludeProcess</a> from xinclude.h</li><li> line 139: Function <a href="../html/libxml-tree.html#xmlDocDump">xmlDocDump</a> from tree.h</li><li> line 143: Function <a href="../html/libxml-tree.html#xmlFreeDoc">xmlFreeDoc</a> from tree.h</li><li> line 148: Function <a href="../html/libxml-parser.html#xmlCleanupParser">xmlCleanupParser</a> from parser.h</li><li> line 152: Function <a href="../html/libxml-xmlmemory.html#xmlMemoryDump">xmlMemoryDump</a> from xmlmemory.h</li></ul><p>Usage:</p><p>io1</p><p>Author: Daniel Veillard</p><h2><a name="Parsing" id="Parsing"></a>Parsing Examples</h2><h3><a name="parse1.c" href="parse1.c" id="parse1.c">parse1.c</a>: Parse an XML file to a tree and free it</h3><p>Demonstrate the use of xmlReadFile() to read an XML file into a tree and and xmlFreeDoc() to free the resulting tree</p><p>Includes:</p><ul><li><a href="../html/libxml-tree.html">&lt;libxml/tree.h&gt;</a></li><li><a href="../html/libxml-parser.html">&lt;libxml/parser.h&gt;</a></li></ul><p>Uses:</p><ul><li> line 24: Type <a href="../html/libxml-tree.html#xmlDocPtr">xmlDocPtr</a> from tree.h</li><li> line 26: Function <a href="../html/libxml-parser.html#xmlReadFile">xmlReadFile</a> from parser.h</li><li> line 31: Function <a href="../html/libxml-tree.html#xmlFreeDoc">xmlFreeDoc</a> from tree.h</li><li> line 45: Macro <a href="../html/libxml-xmlversion.html#LIBXML_TEST_VERSION">LIBXML_TEST_VERSION</a> from xmlversion.h</li><li> line 50: Function <a href="../html/libxml-parser.html#xmlCleanupParser">xmlCleanupParser</a> from parser.h</li><li> line 54: Function <a href="../html/libxml-xmlmemory.html#xmlMemoryDump">xmlMemoryDump</a> from xmlmemory.h</li></ul><p>Usage:</p><p>parse1 test1.xml</p><p>Author: Daniel Veillard</p><h3><a name="parse2.c" href="parse2.c" id="parse2.c">parse2.c</a>: Parse and validate an XML file to a tree and free the result</h3><p>Create a parser context for an XML file, then parse and validate the file, creating a tree, check the validation result and xmlFreeDoc() to free the resulting tree.</p><p>Includes:</p><ul><li><a href="../html/libxml-tree.html">&lt;libxml/tree.h&gt;</a></li><li><a href="../html/libxml-parser.html">&lt;libxml/parser.h&gt;</a></li></ul><p>Uses:</p><ul><li> line 25: Type <a href="../html/libxml-tree.html#xmlParserCtxtPtr">xmlParserCtxtPtr</a> from tree.h</li><li> line 26: Type <a href="../html/libxml-tree.html#xmlDocPtr">xmlDocPtr</a> from tree.h</li><li> line 29: Function <a href="../html/libxml-parser.html#xmlNewParserCtxt">xmlNewParserCtxt</a> from parser.h</li><li> line 35: Function <a href="../html/libxml-parser.html#xmlCtxtReadFile">xmlCtxtReadFile</a> from parser.h</li><li> line 44: Function <a href="../html/libxml-tree.html#xmlFreeDoc">xmlFreeDoc</a> from tree.h</li><li> line 47: Function <a href="../html/libxml-parser.html#xmlFreeParserCtxt">xmlFreeParserCtxt</a> from parser.h</li><li> line 61: Macro <a href="../html/libxml-xmlversion.html#LIBXML_TEST_VERSION">LIBXML_TEST_VERSION</a> from xmlversion.h</li><li> line 66: Function <a href="../html/libxml-parser.html#xmlCleanupParser">xmlCleanupParser</a> from parser.h</li><li> line 70: Function <a href="../html/libxml-xmlmemory.html#xmlMemoryDump">xmlMemoryDump</a> from xmlmemory.h</li></ul><p>Usage:</p><p>parse2 test2.xml</p><p>Author: Daniel Veillard</p><h2><a name="Tree" id="Tree"></a>Tree Examples</h2><h3><a name="tree1.c" href="tree1.c" id="tree1.c">tree1.c</a>: Navigates a tree to print element names</h3><p>Parse a file to a tree, use xmlDocGetRootElement() to get the root element, then walk the document and print all the element name in document order.</p><p>Includes:</p><ul><li><a href="../html/libxml-tree.html">&lt;libxml/tree.h&gt;</a></li><li><a href="../html/libxml-parser.html">&lt;libxml/parser.h&gt;</a></li></ul><p>Uses:</p><ul><li> line 65: Function <a href="../html/libxml-parser.html#xmlParseFile">xmlParseFile</a> from parser.h</li><li> line 72: Function <a href="../html/libxml-tree.html#xmlDocGetRootElement">xmlDocGetRootElement</a> from tree.h</li><li> line 77: Function <a href="../html/libxml-tree.html#xmlFreeDoc">xmlFreeDoc</a> from tree.h</li></ul><p>Usage:</p><p>tree1 filename_or_URL</p><p>Author: Dodji Seketeli</p><h3><a name="tree2.c" href="tree2.c" id="tree2.c">tree2.c</a>: Creates a tree</h3><p>Shows how to create document, nodes and dump it to stdout or file.</p><p>Includes:</p><ul><li><a href="../html/libxml-tree.html">&lt;libxml/tree.h&gt;</a></li><li><a href="../html/libxml-parser.html">&lt;libxml/parser.h&gt;</a></li></ul><p>Uses:</p><ul><li> line 37: Function <a href="../html/libxml-tree.html#xmlNewDoc">xmlNewDoc</a> from tree.h</li><li> line 39: Function <a href="../html/libxml-tree.html#xmlDocSetRootElement">xmlDocSetRootElement</a> from tree.h</li><li> line 44: Function <a href="../html/libxml-tree.html#xmlCreateIntSubset">xmlCreateIntSubset</a> from tree.h</li><li> line 72: Function <a href="../html/libxml-tree.html#xmlNewNode">xmlNewNode</a> from tree.h</li><li> line 73: Function <a href="../html/libxml-tree.html#xmlNewText">xmlNewText</a> from tree.h</li><li> line 76: Function <a href="../html/libxml-tree.html#xmlAddChild">xmlAddChild</a> from tree.h</li><li> line 86: Function <a href="../html/libxml-tree.html#xmlNewChild">xmlNewChild</a> from tree.h</li><li> line 87: Function <a href="../html/libxml-tree.html#xmlNewProp">xmlNewProp</a> from tree.h</li><li> line 94: Function <a href="../html/libxml-tree.html#xmlSaveFormatFileEnc">xmlSaveFormatFileEnc</a> from tree.h</li></ul><p>Usage:</p><p>tree2 &lt;filename&gt; -Default output: stdout</p><p>Author: Lucas Brasilino &lt;brasilino@recife.pe.gov.br&gt;</p><h2><a name="XPath" id="XPath"></a>XPath Examples</h2><h3><a name="xpath1.c" href="xpath1.c" id="xpath1.c">xpath1.c</a>: Evaluate XPath expression and prints result node set.</h3><p>Shows how to evaluate XPath expression and register known namespaces in XPath context.</p><p>Includes:</p><ul><li><a href="../html/libxml-xpath.html">&lt;libxml/xpath.h&gt;</a></li><li><a href="../html/libxml-parser.html">&lt;libxml/parser.h&gt;</a></li><li><a href="../html/libxml-xpathInternals.html">&lt;libxml/xpathInternals.h&gt;</a></li><li><a href="../html/libxml-tree.html">&lt;libxml/tree.h&gt;</a></li></ul><p>Uses:</p><ul><li> line 35: Function <a href="../html/libxml-parser.html#xmlInitParser">xmlInitParser</a> from parser.h</li><li> line 82: Type <a href="../html/libxml-tree.html#xmlDocPtr">xmlDocPtr</a> from tree.h</li><li> line 83: Type <a href="../html/libxml-xpath.html#xmlXPathContextPtr">xmlXPathContextPtr</a> from xpath.h</li><li> line 84: Type <a href="../html/libxml-xpath.html#xmlXPathObjectPtr">xmlXPathObjectPtr</a> from xpath.h</li><li> line 90: Function <a href="../html/libxml-parser.html#xmlParseFile">xmlParseFile</a> from parser.h</li><li> line 97: Function <a href="../html/libxml-xpath.html#xmlXPathNewContext">xmlXPathNewContext</a> from xpath.h</li><li> line 113: Function <a href="../html/libxml-xpath.html#xmlXPathEvalExpression">xmlXPathEvalExpression</a> from xpath.h</li><li> line 125: Function <a href="../html/libxml-xpath.html#xmlXPathFreeObject">xmlXPathFreeObject</a> from xpath.h</li><li> line 126: Function <a href="../html/libxml-xpath.html#xmlXPathFreeContext">xmlXPathFreeContext</a> from xpath.h</li><li> line 152: Function <a href="../html/libxml-xmlstring.html#xmlStrdup">xmlStrdup</a> from xmlstring.h</li><li> line 176: Function <a href="../html/libxml-xmlstring.html#xmlStrchr">xmlStrchr</a> from xmlstring.h</li><li> line 182: Function <a href="../html/libxml-xpathInternals.html#xmlXPathRegisterNs">xmlXPathRegisterNs</a> from xpathInternals.h</li><li> line 202: Type <a href="../html/libxml-tree.html#xmlNodePtr">xmlNodePtr</a> from tree.h</li><li> line 214: Type <a href="../html/libxml-tree.html#xmlNsPtr">xmlNsPtr</a> from tree.h</li></ul><p>Usage:</p><p>xpath1 &lt;xml-file&gt; &lt;xpath-expr&gt; [&lt;known-ns-list&gt;]</p><p>Author: Aleksey Sanin</p><h2><a name="xmlReader" id="xmlReader"></a>xmlReader Examples</h2><h3><a name="reader1.c" href="reader1.c" id="reader1.c">reader1.c</a>: Parse an XML file with an xmlReader</h3><p>Demonstrate the use of xmlReaderForFile() to parse an XML file and dump the informations about the nodes found in the process. (Note that the XMLReader functions require libxml2 version later than 2.6.)</p><p>Includes:</p><ul><li><a href="../html/libxml-xmlreader.html">&lt;libxml/xmlreader.h&gt;</a></li></ul><p>Uses:</p><ul><li> line 27: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderConstName">xmlTextReaderConstName</a> from xmlreader.h</li><li> line 31: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderConstValue">xmlTextReaderConstValue</a> from xmlreader.h</li><li> line 34: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderDepth">xmlTextReaderDepth</a> from xmlreader.h</li><li> line 35: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderNodeType">xmlTextReaderNodeType</a> from xmlreader.h</li><li> line 37: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderIsEmptyElement">xmlTextReaderIsEmptyElement</a> from xmlreader.h</li><li> line 38: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderHasValue">xmlTextReaderHasValue</a> from xmlreader.h</li><li> line 42: Function <a href="../html/libxml-xmlstring.html#xmlStrlen">xmlStrlen</a> from xmlstring.h</li><li> line 57: Type <a href="../html/libxml-xmlreader.html#xmlTextReaderPtr">xmlTextReaderPtr</a> from xmlreader.h</li><li> line 60: Function <a href="../html/libxml-xmlreader.html#xmlReaderForFile">xmlReaderForFile</a> from xmlreader.h</li><li> line 65: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderRead">xmlTextReaderRead</a> from xmlreader.h</li><li> line 67: Function <a href="../html/libxml-xmlreader.html#xmlFreeTextReader">xmlFreeTextReader</a> from xmlreader.h</li><li> line 87: Macro <a href="../html/libxml-xmlversion.html#LIBXML_TEST_VERSION">LIBXML_TEST_VERSION</a> from xmlversion.h</li><li> line 92: Function <a href="../html/libxml-parser.html#xmlCleanupParser">xmlCleanupParser</a> from parser.h</li><li> line 96: Function <a href="../html/libxml-xmlmemory.html#xmlMemoryDump">xmlMemoryDump</a> from xmlmemory.h</li></ul><p>Usage:</p><p>reader1 &lt;filename&gt;</p><p>Author: Daniel Veillard</p><h3><a name="reader2.c" href="reader2.c" id="reader2.c">reader2.c</a>: Parse and validate an XML file with an xmlReader</h3><p>Demonstrate the use of xmlReaderForFile() to parse an XML file validating the content in the process and activating options like entities substitution, and DTD attributes defaulting. (Note that the XMLReader functions require libxml2 version later than 2.6.)</p><p>Includes:</p><ul><li><a href="../html/libxml-xmlreader.html">&lt;libxml/xmlreader.h&gt;</a></li></ul><p>Uses:</p><ul><li> line 28: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderConstName">xmlTextReaderConstName</a> from xmlreader.h</li><li> line 32: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderConstValue">xmlTextReaderConstValue</a> from xmlreader.h</li><li> line 35: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderDepth">xmlTextReaderDepth</a> from xmlreader.h</li><li> line 36: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderNodeType">xmlTextReaderNodeType</a> from xmlreader.h</li><li> line 38: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderIsEmptyElement">xmlTextReaderIsEmptyElement</a> from xmlreader.h</li><li> line 39: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderHasValue">xmlTextReaderHasValue</a> from xmlreader.h</li><li> line 43: Function <a href="../html/libxml-xmlstring.html#xmlStrlen">xmlStrlen</a> from xmlstring.h</li><li> line 58: Type <a href="../html/libxml-xmlreader.html#xmlTextReaderPtr">xmlTextReaderPtr</a> from xmlreader.h</li><li> line 66: Function <a href="../html/libxml-xmlreader.html#xmlReaderForFile">xmlReaderForFile</a> from xmlreader.h</li><li> line 74: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderRead">xmlTextReaderRead</a> from xmlreader.h</li><li> line 79: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderIsValid">xmlTextReaderIsValid</a> from xmlreader.h</li><li> line 82: Function <a href="../html/libxml-xmlreader.html#xmlFreeTextReader">xmlFreeTextReader</a> from xmlreader.h</li><li> line 102: Macro <a href="../html/libxml-xmlversion.html#LIBXML_TEST_VERSION">LIBXML_TEST_VERSION</a> from xmlversion.h</li><li> line 107: Function <a href="../html/libxml-parser.html#xmlCleanupParser">xmlCleanupParser</a> from parser.h</li><li> line 111: Function <a href="../html/libxml-xmlmemory.html#xmlMemoryDump">xmlMemoryDump</a> from xmlmemory.h</li></ul><p>Usage:</p><p>reader2 &lt;valid_xml_filename&gt;</p><p>Author: Daniel Veillard</p><h3><a name="reader3.c" href="reader3.c" id="reader3.c">reader3.c</a>: Show how to extract subdocuments with xmlReader</h3><p>Demonstrate the use of xmlTextReaderPreservePattern() to parse an XML file with the xmlReader while collecting only some subparts of the document. (Note that the XMLReader functions require libxml2 version later than 2.6.)</p><p>Includes:</p><ul><li><a href="../html/libxml-xmlreader.html">&lt;libxml/xmlreader.h&gt;</a></li></ul><p>Uses:</p><ul><li> line 29: Type <a href="../html/libxml-xmlreader.html#xmlTextReaderPtr">xmlTextReaderPtr</a> from xmlreader.h</li><li> line 35: Function <a href="../html/libxml-xmlreader.html#xmlReaderForFile">xmlReaderForFile</a> from xmlreader.h</li><li> line 40: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderPreservePattern">xmlTextReaderPreservePattern</a> from xmlreader.h</li><li> line 49: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderRead">xmlTextReaderRead</a> from xmlreader.h</li><li> line 59: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderCurrentDoc">xmlTextReaderCurrentDoc</a> from xmlreader.h</li><li> line 63: Function <a href="../html/libxml-xmlreader.html#xmlFreeTextReader">xmlFreeTextReader</a> from xmlreader.h</li><li> line 74: Type <a href="../html/libxml-tree.html#xmlDocPtr">xmlDocPtr</a> from tree.h</li><li> line 88: Macro <a href="../html/libxml-xmlversion.html#LIBXML_TEST_VERSION">LIBXML_TEST_VERSION</a> from xmlversion.h</li><li> line 93: Function <a href="../html/libxml-tree.html#xmlDocDump">xmlDocDump</a> from tree.h</li><li> line 97: Function <a href="../html/libxml-tree.html#xmlFreeDoc">xmlFreeDoc</a> from tree.h</li><li> line 104: Function <a href="../html/libxml-parser.html#xmlCleanupParser">xmlCleanupParser</a> from parser.h</li><li> line 108: Function <a href="../html/libxml-xmlmemory.html#xmlMemoryDump">xmlMemoryDump</a> from xmlmemory.h</li></ul><p>Usage:</p><p>reader3</p><p>Author: Daniel Veillard</p><h2><a name="xmlWriter" id="xmlWriter"></a>xmlWriter Examples</h2><h3><a name="testWriter.c" href="testWriter.c" id="testWriter.c">testWriter.c</a>: use various APIs for the xmlWriter</h3><p>tests a number of APIs for the xmlWriter, especially the various methods to write to a filename, to a memory buffer, to a new document, or to a subtree. It shows how to do encoding string conversions too. The resulting documents are then serialized.</p><p>Includes:</p><ul><li><a href="../html/libxml-encoding.html">&lt;libxml/encoding.h&gt;</a></li><li><a href="../html/libxml-xmlwriter.html">&lt;libxml/xmlwriter.h&gt;</a></li></ul><p>Uses:</p><ul><li> line 74: Function <a href="../html/libxml-xmlwriter.html#xmlNewTextWriterFilename">xmlNewTextWriterFilename</a> from xmlwriter.h</li><li> line 339: Type <a href="../html/libxml-tree.html#xmlBufferPtr">xmlBufferPtr</a> from tree.h</li><li> line 345: Function <a href="../html/libxml-tree.html#xmlBufferCreate">xmlBufferCreate</a> from tree.h</li><li> line 353: Function <a href="../html/libxml-xmlwriter.html#xmlNewTextWriterMemory">xmlNewTextWriterMemory</a> from xmlwriter.h</li><li> line 611: Function <a href="../html/libxml-tree.html#xmlBufferFree">xmlBufferFree</a> from tree.h</li><li> line 630: Function <a href="../html/libxml-xmlwriter.html#xmlNewTextWriterDoc">xmlNewTextWriterDoc</a> from xmlwriter.h</li><li> line 876: Type <a href="../html/libxml-xmlwriter.html#xmlTextWriterPtr">xmlTextWriterPtr</a> from xmlwriter.h</li><li> line 877: Type <a href="../html/libxml-tree.html#xmlDocPtr">xmlDocPtr</a> from tree.h</li><li> line 878: Type <a href="../html/libxml-tree.html#xmlNodePtr">xmlNodePtr</a> from tree.h</li><li> line 883: Macro <a href="../html/libxml-parser.html#XML_DEFAULT_VERSION">XML_DEFAULT_VERSION</a> from parser.h</li><li> line 883: Function <a href="../html/libxml-tree.html#xmlNewDoc">xmlNewDoc</a> from tree.h</li><li> line 892: Function <a href="../html/libxml-tree.html#xmlNewDocNode">xmlNewDocNode</a> from tree.h</li><li> line 899: Function <a href="../html/libxml-tree.html#xmlDocSetRootElement">xmlDocSetRootElement</a> from tree.h</li><li> line 902: Function <a href="../html/libxml-xmlwriter.html#xmlNewTextWriterTree">xmlNewTextWriterTree</a> from xmlwriter.h</li><li> line 911: Function <a href="../html/libxml-xmlwriter.html#xmlTextWriterStartDocument">xmlTextWriterStartDocument</a> from xmlwriter.h</li><li> line 923: Function <a href="../html/libxml-xmlwriter.html#xmlTextWriterWriteComment">xmlTextWriterWriteComment</a> from xmlwriter.h</li><li> line 947: Function <a href="../html/libxml-xmlwriter.html#xmlTextWriterWriteAttribute">xmlTextWriterWriteAttribute</a> from xmlwriter.h</li><li> line 957: Function <a href="../html/libxml-xmlwriter.html#xmlTextWriterWriteFormatComment">xmlTextWriterWriteFormatComment</a> from xmlwriter.h</li><li> line 1071: Function <a href="../html/libxml-xmlwriter.html#xmlTextWriterWriteFormatElement">xmlTextWriterWriteFormatElement</a> from xmlwriter.h</li><li> line 1094: Function <a href="../html/libxml-xmlwriter.html#xmlTextWriterStartElement">xmlTextWriterStartElement</a> from xmlwriter.h</li><li> line 1101: Function <a href="../html/libxml-xmlwriter.html#xmlTextWriterWriteElement">xmlTextWriterWriteElement</a> from xmlwriter.h</li><li> line 1109: Function <a href="../html/libxml-xmlwriter.html#xmlTextWriterEndElement">xmlTextWriterEndElement</a> from xmlwriter.h</li><li> line 1119: Function <a href="../html/libxml-xmlwriter.html#xmlTextWriterEndDocument">xmlTextWriterEndDocument</a> from xmlwriter.h</li><li> line 1125: Function <a href="../html/libxml-xmlwriter.html#xmlFreeTextWriter">xmlFreeTextWriter</a> from xmlwriter.h</li><li> line 1127: Function <a href="../html/libxml-tree.html#xmlSaveFileEnc">xmlSaveFileEnc</a> from tree.h</li><li> line 1129: Function <a href="../html/libxml-tree.html#xmlFreeDoc">xmlFreeDoc</a> from tree.h</li><li> line 1149: Type <a href="../html/libxml-encoding.html#xmlCharEncodingHandlerPtr">xmlCharEncodingHandlerPtr</a> from encoding.h</li><li> line 1154: Function <a href="../html/libxml-encoding.html#xmlFindCharEncodingHandler">xmlFindCharEncodingHandler</a> from encoding.h</li></ul><p>Usage:</p><p>testWriter</p><p>Author: Alfred Mickautsch</p><p><a href="../bugs.html">Daniel Veillard</a></p></td></tr></table></td></tr></table></td></tr></table></td></tr></table></td></tr></table></body></html>
+ of the example:</p><ul><li><p><a href="#InputOutput">InputOutput</a> :</p><ul><li><a href="#io1.c">io1.c</a>: Example of custom Input/Output</li></ul></li><li><p><a href="#XPath">XPath</a> :</p><ul><li><a href="#xpath1.c">xpath1.c</a>: Evaluate XPath expression and prints result node set.</li></ul></li><li><p><a href="#xmlWriter">xmlWriter</a> :</p><ul><li><a href="#testWriter.c">testWriter.c</a>: use various APIs for the xmlWriter</li></ul></li><li><p><a href="#Tree">Tree</a> :</p><ul><li><a href="#tree1.c">tree1.c</a>: Navigates a tree to print element names</li><li><a href="#tree2.c">tree2.c</a>: Creates a tree</li></ul></li><li><p><a href="#xmlReader">xmlReader</a> :</p><ul><li><a href="#reader1.c">reader1.c</a>: Parse an XML file with an xmlReader</li><li><a href="#reader2.c">reader2.c</a>: Parse and validate an XML file with an xmlReader</li><li><a href="#reader3.c">reader3.c</a>: Show how to extract subdocuments with xmlReader</li></ul></li><li><p><a href="#Parsing">Parsing</a> :</p><ul><li><a href="#parse1.c">parse1.c</a>: Parse an XML file to a tree and free it</li><li><a href="#parse2.c">parse2.c</a>: Parse and validate an XML file to a tree and free the result</li><li><a href="#parse3.c">parse3.c</a>: Parse an XML document in memory to a tree and free it</li><li><a href="#parse4.c">parse4.c</a>: Parse an XML document chunk by chunk to a tree and free it</li></ul></li></ul><h2><a name="InputOutput" id="InputOutput"></a>InputOutput Examples</h2><h3><a name="io1.c" href="io1.c" id="io1.c">io1.c</a>: Example of custom Input/Output</h3><p>Demonstrate the use of xmlRegisterInputCallbacks to build a custom I/O layer, this is used in an XInclude method context to show how dynamic document can be built in a clean way.</p><p>Includes:</p><ul><li><a href="../html/libxml-parser.html">&lt;libxml/parser.h&gt;</a></li><li><a href="../html/libxml-xinclude.html">&lt;libxml/xinclude.h&gt;</a></li><li><a href="../html/libxml-tree.html">&lt;libxml/tree.h&gt;</a></li><li><a href="../html/libxml-xmlIO.html">&lt;libxml/xmlIO.h&gt;</a></li></ul><p>Uses:</p><ul><li> line 105: Type <a href="../html/libxml-tree.html#xmlDocPtr">xmlDocPtr</a> from tree.h</li><li> line 117: Function <a href="../html/libxml-xmlIO.html#xmlRegisterInputCallbacks">xmlRegisterInputCallbacks</a> from xmlIO.h</li><li> line 124: Function <a href="../html/libxml-parser.html#xmlReadMemory">xmlReadMemory</a> from parser.h</li><li> line 134: Function <a href="../html/libxml-xinclude.html#xmlXIncludeProcess">xmlXIncludeProcess</a> from xinclude.h</li><li> line 143: Function <a href="../html/libxml-tree.html#xmlDocDump">xmlDocDump</a> from tree.h</li></ul><p>Usage:</p><p>io1</p><p>Author: Daniel Veillard</p><h2><a name="Parsing" id="Parsing"></a>Parsing Examples</h2><h3><a name="parse1.c" href="parse1.c" id="parse1.c">parse1.c</a>: Parse an XML file to a tree and free it</h3><p>Demonstrate the use of xmlReadFile() to read an XML file into a tree and and xmlFreeDoc() to free the resulting tree</p><p>Includes:</p><ul><li><a href="../html/libxml-tree.html">&lt;libxml/tree.h&gt;</a></li><li><a href="../html/libxml-parser.html">&lt;libxml/parser.h&gt;</a></li></ul><p>Uses:</p><ul><li> line 24: Type <a href="../html/libxml-tree.html#xmlDocPtr">xmlDocPtr</a> from tree.h</li><li> line 26: Function <a href="../html/libxml-parser.html#xmlReadFile">xmlReadFile</a> from parser.h</li><li> line 31: Function <a href="../html/libxml-tree.html#xmlFreeDoc">xmlFreeDoc</a> from tree.h</li><li> line 45: Macro <a href="../html/libxml-xmlversion.html#LIBXML_TEST_VERSION">LIBXML_TEST_VERSION</a> from xmlversion.h</li><li> line 50: Function <a href="../html/libxml-parser.html#xmlCleanupParser">xmlCleanupParser</a> from parser.h</li><li> line 54: Function <a href="../html/libxml-xmlmemory.html#xmlMemoryDump">xmlMemoryDump</a> from xmlmemory.h</li></ul><p>Usage:</p><p>parse1 test1.xml</p><p>Author: Daniel Veillard</p><h3><a name="parse2.c" href="parse2.c" id="parse2.c">parse2.c</a>: Parse and validate an XML file to a tree and free the result</h3><p>Create a parser context for an XML file, then parse and validate the file, creating a tree, check the validation result and xmlFreeDoc() to free the resulting tree.</p><p>Includes:</p><ul><li><a href="../html/libxml-tree.html">&lt;libxml/tree.h&gt;</a></li><li><a href="../html/libxml-parser.html">&lt;libxml/parser.h&gt;</a></li></ul><p>Uses:</p><ul><li> line 25: Type <a href="../html/libxml-tree.html#xmlParserCtxtPtr">xmlParserCtxtPtr</a> from tree.h</li><li> line 26: Type <a href="../html/libxml-tree.html#xmlDocPtr">xmlDocPtr</a> from tree.h</li><li> line 29: Function <a href="../html/libxml-parser.html#xmlNewParserCtxt">xmlNewParserCtxt</a> from parser.h</li><li> line 35: Function <a href="../html/libxml-parser.html#xmlCtxtReadFile">xmlCtxtReadFile</a> from parser.h</li><li> line 44: Function <a href="../html/libxml-tree.html#xmlFreeDoc">xmlFreeDoc</a> from tree.h</li><li> line 47: Function <a href="../html/libxml-parser.html#xmlFreeParserCtxt">xmlFreeParserCtxt</a> from parser.h</li><li> line 61: Macro <a href="../html/libxml-xmlversion.html#LIBXML_TEST_VERSION">LIBXML_TEST_VERSION</a> from xmlversion.h</li><li> line 66: Function <a href="../html/libxml-parser.html#xmlCleanupParser">xmlCleanupParser</a> from parser.h</li><li> line 70: Function <a href="../html/libxml-xmlmemory.html#xmlMemoryDump">xmlMemoryDump</a> from xmlmemory.h</li></ul><p>Usage:</p><p>parse2 test2.xml</p><p>Author: Daniel Veillard</p><h3><a name="parse3.c" href="parse3.c" id="parse3.c">parse3.c</a>: Parse an XML document in memory to a tree and free it</h3><p>Demonstrate the use of xmlReadMemory() to read an XML file into a tree and and xmlFreeDoc() to free the resulting tree</p><p>Includes:</p><ul><li><a href="../html/libxml-tree.html">&lt;libxml/tree.h&gt;</a></li><li><a href="../html/libxml-parser.html">&lt;libxml/parser.h&gt;</a></li></ul><p>Uses:</p><ul><li> line 33: Function <a href="../html/libxml-parser.html#xmlReadMemory">xmlReadMemory</a> from parser.h</li></ul><p>Usage:</p><p>parse3</p><p>Author: Daniel Veillard</p><h3><a name="parse4.c" href="parse4.c" id="parse4.c">parse4.c</a>: Parse an XML document chunk by chunk to a tree and free it</h3><p>Demonstrate the use of xmlCreatePushParserCtxt() and xmlParseChunk() to read an XML file progressively into a tree and and xmlFreeDoc() to free the resulting tree</p><p>Includes:</p><ul><li><a href="../html/libxml-tree.html">&lt;libxml/tree.h&gt;</a></li><li><a href="../html/libxml-parser.html">&lt;libxml/parser.h&gt;</a></li></ul><p>Uses:</p><ul><li> line 44: Type <a href="../html/libxml-tree.html#xmlParserCtxtPtr">xmlParserCtxtPtr</a> from tree.h</li><li> line 67: Function <a href="../html/libxml-parser.html#xmlCreatePushParserCtxt">xmlCreatePushParserCtxt</a> from parser.h</li><li> line 86: Function <a href="../html/libxml-parser.html#xmlParseChunk">xmlParseChunk</a> from parser.h</li><li> line 94: Function <a href="../html/libxml-parser.html#xmlFreeParserCtxt">xmlFreeParserCtxt</a> from parser.h</li></ul><p>Usage:</p><p>parse4 test3.xml</p><p>Author: Daniel Veillard</p><h2><a name="Tree" id="Tree"></a>Tree Examples</h2><h3><a name="tree1.c" href="tree1.c" id="tree1.c">tree1.c</a>: Navigates a tree to print element names</h3><p>Parse a file to a tree, use xmlDocGetRootElement() to get the root element, then walk the document and print all the element name in document order.</p><p>Includes:</p><ul><li><a href="../html/libxml-tree.html">&lt;libxml/tree.h&gt;</a></li><li><a href="../html/libxml-parser.html">&lt;libxml/parser.h&gt;</a></li></ul><p>Uses:</p><ul><li> line 67: Macro <a href="../html/libxml-xmlversion.html#LIBXML_TEST_VERSION">LIBXML_TEST_VERSION</a> from xmlversion.h</li><li> line 67: Function <a href="../html/libxml-parser.html#xmlParseFile">xmlParseFile</a> from parser.h</li><li> line 74: Function <a href="../html/libxml-tree.html#xmlDocGetRootElement">xmlDocGetRootElement</a> from tree.h</li><li> line 79: Function <a href="../html/libxml-tree.html#xmlFreeDoc">xmlFreeDoc</a> from tree.h</li><li> line 85: Function <a href="../html/libxml-parser.html#xmlCleanupParser">xmlCleanupParser</a> from parser.h</li></ul><p>Usage:</p><p>tree1 filename_or_URL</p><p>Author: Dodji Seketeli</p><h3><a name="tree2.c" href="tree2.c" id="tree2.c">tree2.c</a>: Creates a tree</h3><p>Shows how to create document, nodes and dump it to stdout or file.</p><p>Includes:</p><ul><li><a href="../html/libxml-tree.html">&lt;libxml/tree.h&gt;</a></li><li><a href="../html/libxml-parser.html">&lt;libxml/parser.h&gt;</a></li></ul><p>Uses:</p><ul><li> line 34: Macro <a href="../html/libxml-xmlversion.html#LIBXML_TEST_VERSION">LIBXML_TEST_VERSION</a> from xmlversion.h</li><li> line 39: Function <a href="../html/libxml-tree.html#xmlNewDoc">xmlNewDoc</a> from tree.h</li><li> line 41: Function <a href="../html/libxml-tree.html#xmlDocSetRootElement">xmlDocSetRootElement</a> from tree.h</li><li> line 46: Function <a href="../html/libxml-tree.html#xmlCreateIntSubset">xmlCreateIntSubset</a> from tree.h</li><li> line 74: Function <a href="../html/libxml-tree.html#xmlNewNode">xmlNewNode</a> from tree.h</li><li> line 75: Function <a href="../html/libxml-tree.html#xmlNewText">xmlNewText</a> from tree.h</li><li> line 78: Function <a href="../html/libxml-tree.html#xmlAddChild">xmlAddChild</a> from tree.h</li><li> line 88: Function <a href="../html/libxml-tree.html#xmlNewChild">xmlNewChild</a> from tree.h</li><li> line 89: Function <a href="../html/libxml-tree.html#xmlNewProp">xmlNewProp</a> from tree.h</li><li> line 96: Function <a href="../html/libxml-tree.html#xmlSaveFormatFileEnc">xmlSaveFormatFileEnc</a> from tree.h</li><li> line 99: Function <a href="../html/libxml-tree.html#xmlFreeDoc">xmlFreeDoc</a> from tree.h</li><li> line 105: Function <a href="../html/libxml-parser.html#xmlCleanupParser">xmlCleanupParser</a> from parser.h</li><li> line 110: Function <a href="../html/libxml-xmlmemory.html#xmlMemoryDump">xmlMemoryDump</a> from xmlmemory.h</li></ul><p>Usage:</p><p>tree2 &lt;filename&gt; -Default output: stdout</p><p>Author: Lucas Brasilino &lt;brasilino@recife.pe.gov.br&gt;</p><h2><a name="XPath" id="XPath"></a>XPath Examples</h2><h3><a name="xpath1.c" href="xpath1.c" id="xpath1.c">xpath1.c</a>: Evaluate XPath expression and prints result node set.</h3><p>Shows how to evaluate XPath expression and register known namespaces in XPath context.</p><p>Includes:</p><ul><li><a href="../html/libxml-xpath.html">&lt;libxml/xpath.h&gt;</a></li><li><a href="../html/libxml-parser.html">&lt;libxml/parser.h&gt;</a></li><li><a href="../html/libxml-xpathInternals.html">&lt;libxml/xpathInternals.h&gt;</a></li><li><a href="../html/libxml-tree.html">&lt;libxml/tree.h&gt;</a></li></ul><p>Uses:</p><ul><li> line 38: Function <a href="../html/libxml-parser.html#xmlInitParser">xmlInitParser</a> from parser.h</li><li> line 42: Macro <a href="../html/libxml-xmlversion.html#LIBXML_TEST_VERSION">LIBXML_TEST_VERSION</a> from xmlversion.h</li><li> line 48: Function <a href="../html/libxml-parser.html#xmlCleanupParser">xmlCleanupParser</a> from parser.h</li><li> line 53: Function <a href="../html/libxml-xmlmemory.html#xmlMemoryDump">xmlMemoryDump</a> from xmlmemory.h</li><li> line 85: Type <a href="../html/libxml-tree.html#xmlDocPtr">xmlDocPtr</a> from tree.h</li><li> line 86: Type <a href="../html/libxml-xpath.html#xmlXPathContextPtr">xmlXPathContextPtr</a> from xpath.h</li><li> line 87: Type <a href="../html/libxml-xpath.html#xmlXPathObjectPtr">xmlXPathObjectPtr</a> from xpath.h</li><li> line 93: Function <a href="../html/libxml-parser.html#xmlParseFile">xmlParseFile</a> from parser.h</li><li> line 100: Function <a href="../html/libxml-xpath.html#xmlXPathNewContext">xmlXPathNewContext</a> from xpath.h</li><li> line 116: Function <a href="../html/libxml-xpath.html#xmlXPathEvalExpression">xmlXPathEvalExpression</a> from xpath.h</li><li> line 128: Function <a href="../html/libxml-xpath.html#xmlXPathFreeObject">xmlXPathFreeObject</a> from xpath.h</li><li> line 129: Function <a href="../html/libxml-xpath.html#xmlXPathFreeContext">xmlXPathFreeContext</a> from xpath.h</li><li> line 130: Function <a href="../html/libxml-tree.html#xmlFreeDoc">xmlFreeDoc</a> from tree.h</li><li> line 155: Function <a href="../html/libxml-xmlstring.html#xmlStrdup">xmlStrdup</a> from xmlstring.h</li><li> line 179: Function <a href="../html/libxml-xmlstring.html#xmlStrchr">xmlStrchr</a> from xmlstring.h</li><li> line 185: Function <a href="../html/libxml-xpathInternals.html#xmlXPathRegisterNs">xmlXPathRegisterNs</a> from xpathInternals.h</li><li> line 205: Type <a href="../html/libxml-tree.html#xmlNodePtr">xmlNodePtr</a> from tree.h</li><li> line 217: Type <a href="../html/libxml-tree.html#xmlNsPtr">xmlNsPtr</a> from tree.h</li></ul><p>Usage:</p><p>xpath1 &lt;xml-file&gt; &lt;xpath-expr&gt; [&lt;known-ns-list&gt;]</p><p>Author: Aleksey Sanin</p><h2><a name="xmlReader" id="xmlReader"></a>xmlReader Examples</h2><h3><a name="reader1.c" href="reader1.c" id="reader1.c">reader1.c</a>: Parse an XML file with an xmlReader</h3><p>Demonstrate the use of xmlReaderForFile() to parse an XML file and dump the informations about the nodes found in the process. (Note that the XMLReader functions require libxml2 version later than 2.6.)</p><p>Includes:</p><ul><li><a href="../html/libxml-xmlreader.html">&lt;libxml/xmlreader.h&gt;</a></li></ul><p>Uses:</p><ul><li> line 29: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderConstName">xmlTextReaderConstName</a> from xmlreader.h</li><li> line 33: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderConstValue">xmlTextReaderConstValue</a> from xmlreader.h</li><li> line 36: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderDepth">xmlTextReaderDepth</a> from xmlreader.h</li><li> line 37: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderNodeType">xmlTextReaderNodeType</a> from xmlreader.h</li><li> line 39: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderIsEmptyElement">xmlTextReaderIsEmptyElement</a> from xmlreader.h</li><li> line 40: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderHasValue">xmlTextReaderHasValue</a> from xmlreader.h</li><li> line 44: Function <a href="../html/libxml-xmlstring.html#xmlStrlen">xmlStrlen</a> from xmlstring.h</li><li> line 59: Type <a href="../html/libxml-xmlreader.html#xmlTextReaderPtr">xmlTextReaderPtr</a> from xmlreader.h</li><li> line 62: Function <a href="../html/libxml-xmlreader.html#xmlReaderForFile">xmlReaderForFile</a> from xmlreader.h</li><li> line 67: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderRead">xmlTextReaderRead</a> from xmlreader.h</li><li> line 69: Function <a href="../html/libxml-xmlreader.html#xmlFreeTextReader">xmlFreeTextReader</a> from xmlreader.h</li><li> line 98: Function <a href="../html/libxml-xmlmemory.html#xmlMemoryDump">xmlMemoryDump</a> from xmlmemory.h</li></ul><p>Usage:</p><p>reader1 &lt;filename&gt;</p><p>Author: Daniel Veillard</p><h3><a name="reader2.c" href="reader2.c" id="reader2.c">reader2.c</a>: Parse and validate an XML file with an xmlReader</h3><p>Demonstrate the use of xmlReaderForFile() to parse an XML file validating the content in the process and activating options like entities substitution, and DTD attributes defaulting. (Note that the XMLReader functions require libxml2 version later than 2.6.)</p><p>Includes:</p><ul><li><a href="../html/libxml-xmlreader.html">&lt;libxml/xmlreader.h&gt;</a></li></ul><p>Uses:</p><ul><li> line 30: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderConstName">xmlTextReaderConstName</a> from xmlreader.h</li><li> line 34: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderConstValue">xmlTextReaderConstValue</a> from xmlreader.h</li><li> line 37: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderDepth">xmlTextReaderDepth</a> from xmlreader.h</li><li> line 38: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderNodeType">xmlTextReaderNodeType</a> from xmlreader.h</li><li> line 40: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderIsEmptyElement">xmlTextReaderIsEmptyElement</a> from xmlreader.h</li><li> line 41: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderHasValue">xmlTextReaderHasValue</a> from xmlreader.h</li><li> line 45: Function <a href="../html/libxml-xmlstring.html#xmlStrlen">xmlStrlen</a> from xmlstring.h</li><li> line 60: Type <a href="../html/libxml-xmlreader.html#xmlTextReaderPtr">xmlTextReaderPtr</a> from xmlreader.h</li><li> line 68: Function <a href="../html/libxml-xmlreader.html#xmlReaderForFile">xmlReaderForFile</a> from xmlreader.h</li><li> line 76: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderRead">xmlTextReaderRead</a> from xmlreader.h</li><li> line 81: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderIsValid">xmlTextReaderIsValid</a> from xmlreader.h</li><li> line 84: Function <a href="../html/libxml-xmlreader.html#xmlFreeTextReader">xmlFreeTextReader</a> from xmlreader.h</li></ul><p>Usage:</p><p>reader2 &lt;valid_xml_filename&gt;</p><p>Author: Daniel Veillard</p><h3><a name="reader3.c" href="reader3.c" id="reader3.c">reader3.c</a>: Show how to extract subdocuments with xmlReader</h3><p>Demonstrate the use of xmlTextReaderPreservePattern() to parse an XML file with the xmlReader while collecting only some subparts of the document. (Note that the XMLReader functions require libxml2 version later than 2.6.)</p><p>Includes:</p><ul><li><a href="../html/libxml-xmlreader.html">&lt;libxml/xmlreader.h&gt;</a></li></ul><p>Uses:</p><ul><li> line 31: Type <a href="../html/libxml-xmlreader.html#xmlTextReaderPtr">xmlTextReaderPtr</a> from xmlreader.h</li><li> line 37: Function <a href="../html/libxml-xmlreader.html#xmlReaderForFile">xmlReaderForFile</a> from xmlreader.h</li><li> line 42: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderPreservePattern">xmlTextReaderPreservePattern</a> from xmlreader.h</li><li> line 51: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderRead">xmlTextReaderRead</a> from xmlreader.h</li><li> line 61: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderCurrentDoc">xmlTextReaderCurrentDoc</a> from xmlreader.h</li><li> line 65: Function <a href="../html/libxml-xmlreader.html#xmlFreeTextReader">xmlFreeTextReader</a> from xmlreader.h</li><li> line 76: Type <a href="../html/libxml-tree.html#xmlDocPtr">xmlDocPtr</a> from tree.h</li><li> line 95: Function <a href="../html/libxml-tree.html#xmlDocDump">xmlDocDump</a> from tree.h</li></ul><p>Usage:</p><p>reader3</p><p>Author: Daniel Veillard</p><h2><a name="xmlWriter" id="xmlWriter"></a>xmlWriter Examples</h2><h3><a name="testWriter.c" href="testWriter.c" id="testWriter.c">testWriter.c</a>: use various APIs for the xmlWriter</h3><p>tests a number of APIs for the xmlWriter, especially the various methods to write to a filename, to a memory buffer, to a new document, or to a subtree. It shows how to do encoding string conversions too. The resulting documents are then serialized.</p><p>Includes:</p><ul><li><a href="../html/libxml-encoding.html">&lt;libxml/encoding.h&gt;</a></li><li><a href="../html/libxml-xmlwriter.html">&lt;libxml/xmlwriter.h&gt;</a></li></ul><p>Uses:</p><ul><li> line 40: Macro <a href="../html/libxml-xmlversion.html#LIBXML_TEST_VERSION">LIBXML_TEST_VERSION</a> from xmlversion.h</li><li> line 54: Function <a href="../html/libxml-parser.html#xmlCleanupParser">xmlCleanupParser</a> from parser.h</li><li> line 58: Function <a href="../html/libxml-xmlmemory.html#xmlMemoryDump">xmlMemoryDump</a> from xmlmemory.h</li><li> line 76: Function <a href="../html/libxml-xmlwriter.html#xmlNewTextWriterFilename">xmlNewTextWriterFilename</a> from xmlwriter.h</li><li> line 341: Type <a href="../html/libxml-tree.html#xmlBufferPtr">xmlBufferPtr</a> from tree.h</li><li> line 347: Function <a href="../html/libxml-tree.html#xmlBufferCreate">xmlBufferCreate</a> from tree.h</li><li> line 355: Function <a href="../html/libxml-xmlwriter.html#xmlNewTextWriterMemory">xmlNewTextWriterMemory</a> from xmlwriter.h</li><li> line 613: Function <a href="../html/libxml-tree.html#xmlBufferFree">xmlBufferFree</a> from tree.h</li><li> line 632: Function <a href="../html/libxml-xmlwriter.html#xmlNewTextWriterDoc">xmlNewTextWriterDoc</a> from xmlwriter.h</li><li> line 878: Type <a href="../html/libxml-xmlwriter.html#xmlTextWriterPtr">xmlTextWriterPtr</a> from xmlwriter.h</li><li> line 879: Type <a href="../html/libxml-tree.html#xmlDocPtr">xmlDocPtr</a> from tree.h</li><li> line 880: Type <a href="../html/libxml-tree.html#xmlNodePtr">xmlNodePtr</a> from tree.h</li><li> line 885: Macro <a href="../html/libxml-parser.html#XML_DEFAULT_VERSION">XML_DEFAULT_VERSION</a> from parser.h</li><li> line 885: Function <a href="../html/libxml-tree.html#xmlNewDoc">xmlNewDoc</a> from tree.h</li><li> line 894: Function <a href="../html/libxml-tree.html#xmlNewDocNode">xmlNewDocNode</a> from tree.h</li><li> line 901: Function <a href="../html/libxml-tree.html#xmlDocSetRootElement">xmlDocSetRootElement</a> from tree.h</li><li> line 904: Function <a href="../html/libxml-xmlwriter.html#xmlNewTextWriterTree">xmlNewTextWriterTree</a> from xmlwriter.h</li><li> line 913: Function <a href="../html/libxml-xmlwriter.html#xmlTextWriterStartDocument">xmlTextWriterStartDocument</a> from xmlwriter.h</li><li> line 925: Function <a href="../html/libxml-xmlwriter.html#xmlTextWriterWriteComment">xmlTextWriterWriteComment</a> from xmlwriter.h</li><li> line 949: Function <a href="../html/libxml-xmlwriter.html#xmlTextWriterWriteAttribute">xmlTextWriterWriteAttribute</a> from xmlwriter.h</li><li> line 959: Function <a href="../html/libxml-xmlwriter.html#xmlTextWriterWriteFormatComment">xmlTextWriterWriteFormatComment</a> from xmlwriter.h</li><li> line 1073: Function <a href="../html/libxml-xmlwriter.html#xmlTextWriterWriteFormatElement">xmlTextWriterWriteFormatElement</a> from xmlwriter.h</li><li> line 1096: Function <a href="../html/libxml-xmlwriter.html#xmlTextWriterStartElement">xmlTextWriterStartElement</a> from xmlwriter.h</li><li> line 1103: Function <a href="../html/libxml-xmlwriter.html#xmlTextWriterWriteElement">xmlTextWriterWriteElement</a> from xmlwriter.h</li><li> line 1111: Function <a href="../html/libxml-xmlwriter.html#xmlTextWriterEndElement">xmlTextWriterEndElement</a> from xmlwriter.h</li><li> line 1121: Function <a href="../html/libxml-xmlwriter.html#xmlTextWriterEndDocument">xmlTextWriterEndDocument</a> from xmlwriter.h</li><li> line 1127: Function <a href="../html/libxml-xmlwriter.html#xmlFreeTextWriter">xmlFreeTextWriter</a> from xmlwriter.h</li><li> line 1129: Function <a href="../html/libxml-tree.html#xmlSaveFileEnc">xmlSaveFileEnc</a> from tree.h</li><li> line 1131: Function <a href="../html/libxml-tree.html#xmlFreeDoc">xmlFreeDoc</a> from tree.h</li><li> line 1151: Type <a href="../html/libxml-encoding.html#xmlCharEncodingHandlerPtr">xmlCharEncodingHandlerPtr</a> from encoding.h</li><li> line 1156: Function <a href="../html/libxml-encoding.html#xmlFindCharEncodingHandler">xmlFindCharEncodingHandler</a> from encoding.h</li></ul><p>Usage:</p><p>testWriter</p><p>Author: Alfred Mickautsch</p><p><a href="../bugs.html">Daniel Veillard</a></p></td></tr></table></td></tr></table></td></tr></table></td></tr></table></td></tr></table></body></html>
diff --git a/doc/examples/parse3.c b/doc/examples/parse3.c
new file mode 100644
index 00000000..a2d3a409
--- /dev/null
+++ b/doc/examples/parse3.c
@@ -0,0 +1,60 @@
+/**
+ * section: Parsing
+ * synopsis: Parse an XML document in memory to a tree and free it
+ * purpose: Demonstrate the use of xmlReadMemory() to read an XML file
+ * into a tree and and xmlFreeDoc() to free the resulting tree
+ * usage: parse3
+ * test: parse3
+ * author: Daniel Veillard
+ * copy: see Copyright for the status of this software.
+ */
+
+#include <stdio.h>
+#include <libxml/parser.h>
+#include <libxml/tree.h>
+
+static const char *document = "<doc/>";
+
+/**
+ * example3Func:
+ * @content: the content of the document
+ * @length: the length in bytes
+ *
+ * Parse the in memory document and free the resulting tree
+ */
+static void
+example3Func(const char *content, int length) {
+ xmlDocPtr doc; /* the resulting document tree */
+
+ /*
+ * The document being in memory, it have no base per RFC 2396,
+ * and the "noname.xml" argument will serve as its base.
+ */
+ doc = xmlReadMemory(content, length, "noname.xml", NULL, 0);
+ if (doc == NULL) {
+ fprintf(stderr, "Failed to parse document\n");
+ return;
+ }
+ xmlFreeDoc(doc);
+}
+
+int main(void) {
+ /*
+ * this initialize the library and check potential ABI mismatches
+ * between the version it was compiled for and the actual shared
+ * library used.
+ */
+ LIBXML_TEST_VERSION
+
+ example3Func(document, 6);
+
+ /*
+ * Cleanup function for the XML library.
+ */
+ xmlCleanupParser();
+ /*
+ * this is to debug memory for regression tests
+ */
+ xmlMemoryDump();
+ return(0);
+}
diff --git a/doc/examples/parse4.c b/doc/examples/parse4.c
new file mode 100644
index 00000000..97825f0f
--- /dev/null
+++ b/doc/examples/parse4.c
@@ -0,0 +1,137 @@
+/**
+ * section: Parsing
+ * synopsis: Parse an XML document chunk by chunk to a tree and free it
+ * purpose: Demonstrate the use of xmlCreatePushParserCtxt() and
+ * xmlParseChunk() to read an XML file progressively
+ * into a tree and and xmlFreeDoc() to free the resulting tree
+ * usage: parse4 test3.xml
+ * test: parse4 test3.xml
+ * author: Daniel Veillard
+ * copy: see Copyright for the status of this software.
+ */
+
+#include <stdio.h>
+#include <libxml/parser.h>
+#include <libxml/tree.h>
+
+static FILE *desc;
+
+/**
+ * readPacket:
+ * @mem: array to store the packet
+ * @size: the packet size
+ *
+ * read at most @size bytes from the document and store it in @mem
+ *
+ * Returns the number of bytes read
+ */
+static int
+readPacket(char *mem, int size) {
+ int res;
+
+ res = fread(mem, 1, size, desc);
+ return(res);
+}
+
+/**
+ * example4Func:
+ * @filename: a filename or an URL
+ *
+ * Parse the resource and free the resulting tree
+ */
+static void
+example4Func(const char *filename) {
+ xmlParserCtxtPtr ctxt;
+ char chars[4];
+ int size = 4;
+ xmlDocPtr doc; /* the resulting document tree */
+ int res;
+
+ /*
+ * Read a few first byte to check the input used for the
+ * encoding detection at the parser level.
+ */
+ res = readPacket(chars, 4);
+ if (res <= 0) {
+ fprintf(stderr, "Failed to parse %s\n", filename);
+ return;
+ }
+
+ /*
+ * Create a progressive parsing context, the 2 first arguments
+ * are not used since we want to build a tree and not use a SAX
+ * parsing interface. We also pass the first bytes of the document
+ * to allow encoding detection when creating the parser but this
+ * is optional.
+ */
+ ctxt = xmlCreatePushParserCtxt(NULL, NULL,
+ chars, res, filename);
+ if (ctxt == NULL) {
+ fprintf(stderr, "Failed to create parser context !\n");
+ return;
+ }
+
+ /*
+ * loop on the input getting the document data, of course 4 bytes
+ * at a time is not realistic but allows to verify testing on small
+ * documents.
+ */
+ while ((res = readPacket(chars, 4)) > 0) {
+ xmlParseChunk(ctxt, chars, res, 0);
+ }
+
+ /*
+ * there is no more input, indicate the parsing is finished.
+ */
+ xmlParseChunk(ctxt, chars, 0, 1);
+
+ /*
+ * collect the document back and if it was wellformed
+ * and destroy the parser context.
+ */
+ doc = ctxt->myDoc;
+ res = ctxt->wellFormed;
+ xmlFreeParserCtxt(ctxt);
+
+ if (!res) {
+ fprintf(stderr, "Failed to parse %s\n", filename);
+ }
+
+ /*
+ * since we don't use the document, destroy it now.
+ */
+ xmlFreeDoc(doc);
+}
+
+int main(int argc, char **argv) {
+ if (argc != 2)
+ return(1);
+
+ /*
+ * this initialize the library and check potential ABI mismatches
+ * between the version it was compiled for and the actual shared
+ * library used.
+ */
+ LIBXML_TEST_VERSION
+
+ /*
+ * simulate a progressive parsing using the input file.
+ */
+ desc = fopen(argv[1], "rb");
+ if (desc != NULL) {
+ example4Func(argv[1]);
+ fclose(desc);
+ } else {
+ fprintf(stderr, "Failed to parse %s\n", argv[1]);
+ }
+
+ /*
+ * Cleanup function for the XML library.
+ */
+ xmlCleanupParser();
+ /*
+ * this is to debug memory for regression tests
+ */
+ xmlMemoryDump();
+ return(0);
+}