Commit 241e19d4 authored by Daniel Veillard's avatar Daniel Veillard

added Aleksey XPath example, fixed bugs in the indexer Daniel

* doc/examples/*: added Aleksey XPath example, fixed bugs
  in the indexer
Daniel
parent a59853a3
Thu Nov 13 11:35:35 CET 2003 Daniel Veillard <daniel@veillard.com>
* doc/examples/*: added Aleksey XPath example, fixed bugs
in the indexer
Wed Nov 12 23:48:26 CET 2003 Daniel Veillard <daniel@veillard.com>
* doc/*: integrating the examples in the navigation menus
......
.memdump
Makefile.in
Makefile
xpath1
parse1
parse2
......@@ -13,7 +13,12 @@ index.html: examples.xml examples.xsl
EXTRA_DIST=examples.xsl index.py test1.xml examples.xml test2.xml
noinst_PROGRAMS=parse1 parse2
noinst_PROGRAMS=xpath1 parse1 parse2
xpath1_SOURCES=xpath1.c
xpath1_LDFLAGS=
xpath1_DEPENDENCIES= $(DEPS)
xpath1_LDADD= @RDL_LIBS@ $(LDADDS)
parse1_SOURCES=parse1.c
parse1_LDFLAGS=
......
<examples>
<example filename='xpath1.c'>
<synopsis>Evaluate XPath expression and prints result node set.</synopsis>
<purpose>Shows how to evaluate XPath expression and register known namespaces in XPath context.</purpose>
<usage>xpath1 &lt;xml-file&gt; &lt;xpath-expr&gt; [&lt;known-ns-list&gt;]</usage>
<author>Aleksey Sanin</author>
<copy>see Copyright for the status of this software. </copy>
<section>XPath</section>
<includes>
<include>&lt;libxml/xpath.h&gt;</include>
<include>&lt;libxml/parser.h&gt;</include>
<include>&lt;libxml/xpathInternals.h&gt;</include>
<include>&lt;libxml/tree.h&gt;</include>
</includes>
<uses>
<typedef line='80' file='xpath' name='xmlXPathObjectPtr'/>
<enum line='221' file='tree' name='XML_ELEMENT_NODE'/>
<function line='109' file='xpath' name='xmlXPathEvalExpression'/>
<function line='178' file='xpathInternals' name='xmlXPathRegisterNs'/>
<function line='121' file='xpath' name='xmlXPathFreeObject'/>
<typedef line='78' file='tree' name='xmlDocPtr'/>
<typedef line='210' file='tree' name='xmlNsPtr'/>
<function line='93' file='xpath' name='xmlXPathNewContext'/>
<function line='45' file='parser' name='xmlCleanupParser'/>
<macro line='39' file='xmlversion' name='LIBXML_TEST_VERSION'/>
<typedef line='79' file='xpath' name='xmlXPathContextPtr'/>
<function line='122' file='xpath' name='xmlXPathFreeContext'/>
<function line='35' file='parser' name='xmlInitParser'/>
<function line='148' file='parser' name='xmlStrdup'/>
<function line='123' file='tree' name='xmlFreeDoc'/>
<function line='172' file='parser' name='xmlStrchr'/>
<typedef line='198' file='tree' name='xmlNodePtr'/>
<function line='86' file='parser' name='xmlParseFile'/>
<enum line='209' file='tree' name='XML_NAMESPACE_DECL'/>
</uses>
</example>
<example filename='parse1.c'>
<synopsis>Parse an XML file to a tree and free it</synopsis>
<purpose>Demonstrate the use of xmlReadFile() to read an XML file into a tree and and xmlFreeDoc() to free the resulting tree</purpose>
<usage>parse1 test1.xml</usage>
<author>Daniel veillard</author>
<test>parse1 test1.xml</test>
<author>Daniel Veillard</author>
<copy>see Copyright for the status of this software. </copy>
<section>Parsing</section>
<includes>
......@@ -11,18 +47,19 @@
<include>&lt;libxml/parser.h&gt;</include>
</includes>
<uses>
<function line='49' file='parser' name='xmlCleanupParser'/>
<macro line='44' file='xmlversion' name='LIBXML_TEST_VERSION'/>
<function line='30' file='tree' name='xmlFreeDoc'/>
<function line='25' file='parser' name='xmlReadFile'/>
<typedef line='23' file='tree' name='xmlDocPtr'/>
<function line='50' file='parser' name='xmlCleanupParser'/>
<macro line='45' file='xmlversion' name='LIBXML_TEST_VERSION'/>
<function line='31' file='tree' name='xmlFreeDoc'/>
<function line='26' file='parser' name='xmlReadFile'/>
<typedef line='24' file='tree' name='xmlDocPtr'/>
</uses>
</example>
<example filename='parse2.c'>
<synopsis>Parse and validate an XML file to a tree and free the result</synopsis>
<purpose>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.</purpose>
<usage>parse2 test2.xml</usage>
<author>Daniel veillard</author>
<test>parse2 test2.xml</test>
<author>Daniel Veillard</author>
<copy>see Copyright for the status of this software. </copy>
<section>Parsing</section>
<includes>
......@@ -30,53 +67,109 @@
<include>&lt;libxml/parser.h&gt;</include>
</includes>
<uses>
<function line='46' file='parser' name='xmlFreeParserCtxt'/>
<macro line='60' file='xmlversion' name='LIBXML_TEST_VERSION'/>
<enum line='34' file='parser' name='XML_PARSE_DTDVALID'/>
<function line='28' file='parser' name='xmlNewParserCtxt'/>
<function line='65' file='parser' name='xmlCleanupParser'/>
<typedef line='24' file='tree' name='xmlParserCtxtPtr'/>
<function line='34' file='parser' name='xmlCtxtReadFile'/>
<function line='43' file='tree' name='xmlFreeDoc'/>
<typedef line='25' file='tree' name='xmlDocPtr'/>
<function line='47' file='parser' name='xmlFreeParserCtxt'/>
<macro line='61' file='xmlversion' name='LIBXML_TEST_VERSION'/>
<enum line='35' file='parser' name='XML_PARSE_DTDVALID'/>
<function line='29' file='parser' name='xmlNewParserCtxt'/>
<function line='66' file='parser' name='xmlCleanupParser'/>
<typedef line='25' file='tree' name='xmlParserCtxtPtr'/>
<function line='35' file='parser' name='xmlCtxtReadFile'/>
<function line='44' file='tree' name='xmlFreeDoc'/>
<typedef line='26' file='tree' name='xmlDocPtr'/>
</uses>
</example>
<symbols>
<symbol name='LIBXML_TEST_VERSION'>
<ref filename='xpath1.c'/>
<ref filename='parse1.c'/>
<ref filename='parse2.c'/>
</symbol>
<symbol name='XML_ELEMENT_NODE'>
<ref filename='xpath1.c'/>
</symbol>
<symbol name='XML_NAMESPACE_DECL'>
<ref filename='xpath1.c'/>
</symbol>
<symbol name='XML_PARSE_DTDVALID'>
<ref filename='parse2.c'/>
</symbol>
<symbol name='xmlCleanupParser'>
<ref filename='xpath1.c'/>
<ref filename='parse1.c'/>
<ref filename='parse2.c'/>
</symbol>
<symbol name='xmlCtxtReadFile'>
<ref filename='parse2.c'/>
</symbol>
<symbol name='xmlDocPtr'>
<ref filename='xpath1.c'/>
<ref filename='parse1.c'/>
<ref filename='parse2.c'/>
</symbol>
<symbol name='xmlFreeDoc'>
<ref filename='xpath1.c'/>
<ref filename='parse1.c'/>
<ref filename='parse2.c'/>
</symbol>
<symbol name='xmlFreeParserCtxt'>
<ref filename='parse2.c'/>
</symbol>
<symbol name='xmlInitParser'>
<ref filename='xpath1.c'/>
</symbol>
<symbol name='xmlNewParserCtxt'>
<ref filename='parse2.c'/>
</symbol>
<symbol name='xmlNodePtr'>
<ref filename='xpath1.c'/>
</symbol>
<symbol name='xmlNsPtr'>
<ref filename='xpath1.c'/>
</symbol>
<symbol name='xmlParseFile'>
<ref filename='xpath1.c'/>
</symbol>
<symbol name='xmlParserCtxtPtr'>
<ref filename='parse2.c'/>
</symbol>
<symbol name='xmlReadFile'>
<ref filename='parse1.c'/>
</symbol>
<symbol name='xmlStrchr'>
<ref filename='xpath1.c'/>
</symbol>
<symbol name='xmlStrdup'>
<ref filename='xpath1.c'/>
</symbol>
<symbol name='xmlXPathContextPtr'>
<ref filename='xpath1.c'/>
</symbol>
<symbol name='xmlXPathEvalExpression'>
<ref filename='xpath1.c'/>
</symbol>
<symbol name='xmlXPathFreeContext'>
<ref filename='xpath1.c'/>
</symbol>
<symbol name='xmlXPathFreeObject'>
<ref filename='xpath1.c'/>
</symbol>
<symbol name='xmlXPathNewContext'>
<ref filename='xpath1.c'/>
</symbol>
<symbol name='xmlXPathObjectPtr'>
<ref filename='xpath1.c'/>
</symbol>
<symbol name='xmlXPathRegisterNs'>
<ref filename='xpath1.c'/>
</symbol>
</symbols>
<sections>
<section name='Parsing'>
<example filename='parse1.c'/>
<example filename='parse2.c'/>
</section>
<section name='XPath'>
<example filename='xpath1.c'/>
</section>
</sections>
</examples>
......@@ -7,5 +7,5 @@ H1 {font-family: Verdana,Arial,Helvetica}
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>Main 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 href="#Parsing">Parsing 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="#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></ul><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 23: Type <a href="../html/libxml-tree.html#xmlDocPtr">xmlDocPtr</a> from tree.h</li><li> line 25: Function <a href="../html/libxml-parser.html#xmlReadFile">xmlReadFile</a> from parser.h</li><li> line 30: Function <a href="../html/libxml-tree.html#xmlFreeDoc">xmlFreeDoc</a> from tree.h</li><li> line 44: Macro <a href="../html/libxml-xmlversion.html#LIBXML_TEST_VERSION">LIBXML_TEST_VERSION</a> from xmlversion.h</li><li> line 49: Function <a href="../html/libxml-parser.html#xmlCleanupParser">xmlCleanupParser</a> from parser.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 24: Type <a href="../html/libxml-tree.html#xmlParserCtxtPtr">xmlParserCtxtPtr</a> from tree.h</li><li> line 25: Type <a href="../html/libxml-tree.html#xmlDocPtr">xmlDocPtr</a> from tree.h</li><li> line 28: Function <a href="../html/libxml-parser.html#xmlNewParserCtxt">xmlNewParserCtxt</a> from parser.h</li><li> line 34: Function <a href="../html/libxml-parser.html#xmlCtxtReadFile">xmlCtxtReadFile</a> from parser.h</li><li> line 43: Function <a href="../html/libxml-tree.html#xmlFreeDoc">xmlFreeDoc</a> from tree.h</li><li> line 46: Function <a href="../html/libxml-parser.html#xmlFreeParserCtxt">xmlFreeParserCtxt</a> from parser.h</li><li> line 60: Macro <a href="../html/libxml-xmlversion.html#LIBXML_TEST_VERSION">LIBXML_TEST_VERSION</a> from xmlversion.h</li><li> line 65: Function <a href="../html/libxml-parser.html#xmlCleanupParser">xmlCleanupParser</a> from parser.h</li></ul><p>Usage:</p><p>parse2 test2.xml</p><p>Author: Daniel veillard</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>
</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>Main 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 href="#Parsing">Parsing Examples</a></li><li><a href="#XPath">XPath 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="#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="#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></ul><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></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></ul><p>Usage:</p><p>parse2 test2.xml</p><p>Author: Daniel Veillard</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 39: Macro <a href="../html/libxml-xmlversion.html#LIBXML_TEST_VERSION">LIBXML_TEST_VERSION</a> from xmlversion.h</li><li> line 45: Function <a href="../html/libxml-parser.html#xmlCleanupParser">xmlCleanupParser</a> from parser.h</li><li> line 78: Type <a href="../html/libxml-tree.html#xmlDocPtr">xmlDocPtr</a> from tree.h</li><li> line 79: Type <a href="../html/libxml-xpath.html#xmlXPathContextPtr">xmlXPathContextPtr</a> from xpath.h</li><li> line 80: Type <a href="../html/libxml-xpath.html#xmlXPathObjectPtr">xmlXPathObjectPtr</a> from xpath.h</li><li> line 86: Function <a href="../html/libxml-parser.html#xmlParseFile">xmlParseFile</a> from parser.h</li><li> line 93: Function <a href="../html/libxml-xpath.html#xmlXPathNewContext">xmlXPathNewContext</a> from xpath.h</li><li> line 109: Function <a href="../html/libxml-xpath.html#xmlXPathEvalExpression">xmlXPathEvalExpression</a> from xpath.h</li><li> line 121: Function <a href="../html/libxml-xpath.html#xmlXPathFreeObject">xmlXPathFreeObject</a> from xpath.h</li><li> line 122: Function <a href="../html/libxml-xpath.html#xmlXPathFreeContext">xmlXPathFreeContext</a> from xpath.h</li><li> line 123: Function <a href="../html/libxml-tree.html#xmlFreeDoc">xmlFreeDoc</a> from tree.h</li><li> line 148: Function <a href="../html/libxml-parser.html#xmlStrdup">xmlStrdup</a> from parser.h</li><li> line 172: Function <a href="../html/libxml-parser.html#xmlStrchr">xmlStrchr</a> from parser.h</li><li> line 178: Function <a href="../html/libxml-xpathInternals.html#xmlXPathRegisterNs">xmlXPathRegisterNs</a> from xpathInternals.h</li><li> line 198: Type <a href="../html/libxml-tree.html#xmlNodePtr">xmlNodePtr</a> from tree.h</li><li> line 210: 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><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>
......@@ -66,16 +66,16 @@ def parse_top_comment(filename, comment):
lines = string.split(comment, "\n")
item = None
for line in lines:
while line != "" and line[0] == ' ':
while line != "" and (line[0] == ' ' or line[0] == '\t'):
line = line[1:]
while line != "" and line[0] == '*':
line = line[1:]
while line != "" and line[0] == ' ':
while line != "" and (line[0] == ' ' or line[0] == '\t'):
line = line[1:]
try:
(it, line) = string.split(line, ":", 1)
item = it
while line != "" and line[0] == ' ':
while line != "" and (line[0] == ' ' or line[0] == '\t'):
line = line[1:]
if res.has_key(item):
res[item] = res[item] + " " + line
......@@ -100,33 +100,38 @@ def parse(filename, output):
output.write(" <example filename='%s'>\n" % filename)
try:
synopsis = info['synopsis']
output.write(" <synopsis>%s</synopsis>\n" % synopsis);
output.write(" <synopsis>%s</synopsis>\n" % escape(synopsis));
except:
print "Example %s lacks a synopsis description" % (filename)
try:
purpose = info['purpose']
output.write(" <purpose>%s</purpose>\n" % purpose);
output.write(" <purpose>%s</purpose>\n" % escape(purpose));
except:
print "Example %s lacks a purpose description" % (filename)
try:
usage = info['usage']
output.write(" <usage>%s</usage>\n" % usage);
tests.append(usage)
output.write(" <usage>%s</usage>\n" % escape(usage));
except:
print "Example %s lacks an usage description" % (filename)
try:
test = info['test']
output.write(" <test>%s</test>\n" % escape(test));
tests.append(test)
except:
pass
try:
author = info['author']
output.write(" <author>%s</author>\n" % author);
output.write(" <author>%s</author>\n" % escape(author));
except:
print "Example %s lacks an author description" % (filename)
try:
copy = info['copy']
output.write(" <copy>%s</copy>\n" % copy);
output.write(" <copy>%s</copy>\n" % escape(copy));
except:
print "Example %s lacks a copyright description" % (filename)
try:
section = info['section']
output.write(" <section>%s</section>\n" % section);
output.write(" <section>%s</section>\n" % escape(section));
if sections.has_key(section):
sections[section].append(filename)
else:
......@@ -136,9 +141,10 @@ def parse(filename, output):
for topic in info.keys():
if topic != "purpose" and topic != "usage" and \
topic != "author" and topic != "copy" and \
topic != "section" and topic != "synopsis":
topic != "section" and topic != "synopsis" and topic != "test":
str = info[topic]
output.write(" <extra topic='%s'>%s</extra>\n" % str)
output.write(" <extra topic='%s'>%s</extra>\n" % (
escape(topic), escape(str)))
output.write(" <includes>\n")
for include in idx.includes.keys():
if include.find("libxml") != -1:
......@@ -155,7 +161,7 @@ def parse(filename, output):
# gather at most 5 references per symbols
if refs > 5:
continue
sinfo[refs] = filename
sinfo.append(filename)
sinfo[0] = refs + 1
else:
symbols[name] = [1, filename]
......@@ -246,6 +252,22 @@ index.html: examples.xml examples.xsl
print "Updated Makefile.am"
except:
print "Failed to read or save Makefile.am"
#
# Autogenerate the .cvsignore too ...
#
ignore = """.memdump
Makefile.in
Makefile
"""
for example in examples:
ignore = ignore + "%s\n" % (example)
try:
old = open(".cvsignore", "r").read()
if old != ignore:
n = open(".cvsignore", "w").write(ignore)
print "Updated .cvsignore"
except:
print "Failed to read or save .cvsignore"
if __name__ == "__main__":
load_api()
......
......@@ -4,7 +4,8 @@
* purpose: Demonstrate the use of xmlReadFile() to read an XML file
* into a tree and and xmlFreeDoc() to free the resulting tree
* usage: parse1 test1.xml
* author: Daniel veillard
* test: parse1 test1.xml
* author: Daniel Veillard
* copy: see Copyright for the status of this software.
*/
......
......@@ -5,7 +5,8 @@
* the file, creating a tree, check the validation result
* and xmlFreeDoc() to free the resulting tree.
* usage: parse2 test2.xml
* author: Daniel veillard
* test: parse2 test2.xml
* author: Daniel Veillard
* copy: see Copyright for the status of this software.
*/
......
/**
* section: XPath
* synopsis: Evaluate XPath expression and prints result node set.
* purpose: Shows how to evaluate XPath expression and register
* known namespaces in XPath context.
* usage: xpath1 <xml-file> <xpath-expr> [<known-ns-list>]
* author: Aleksey Sanin
* copy: see Copyright for the status of this software.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <libxml/tree.h>
#include <libxml/parser.h>
#include <libxml/xpath.h>
#include <libxml/xpathInternals.h>
void usage(const char *name);
int execute_xpath_expression(const char* filename, const xmlChar* xpathExpr, const xmlChar* nsList);
int register_namespaces(xmlXPathContextPtr xpathCtx, const xmlChar* nsList);
void print_xpath_nodes(xmlNodeSetPtr nodes, FILE* output);
int
main(int argc, char **argv) {
/* Parse command line and process file */
if((argc < 3) || (argc > 4)) {
fprintf(stderr, "Error: wrong number of arguments.\n");
usage(argv[0]);
return(-1);
}
/* Init libxml */
xmlInitParser();
LIBXML_TEST_VERSION
/* Do the main job */
if(execute_xpath_expression(argv[1], BAD_CAST argv[2], (argc > 3) ? BAD_CAST argv[3] : NULL) < 0) {
usage(argv[0]);
return(-1);
}
/* Shutdown libxml */
xmlCleanupParser();
return 0;
}
/**
* usage:
* @name: the program name.
*
* Prints usage information.
*/
void
usage(const char *name) {
assert(name);
fprintf(stderr, "Usage: %s <xml-file> <xpath-expr> [<known-ns-list>]\n", name);
fprintf(stderr, "where <known-ns-list> is a list of known namespaces\n");
fprintf(stderr, "in \"<prefix1>=<href1> <prefix2>=href2> ...\" format\n");
}
/**
* execute_xpath_expression:
* @filename: the input XML filename.
* @xpathExpr: the xpath expression for evaluation.
* @nsList: the optional list of known namespaces in
* "<prefix1>=<href1> <prefix2>=href2> ..." format.
*
* Parses input XML file, evaluates XPath expression and prints results.
*
* Returns 0 on success and a negative value otherwise.
*/
int
execute_xpath_expression(const char* filename, const xmlChar* xpathExpr, const xmlChar* nsList) {
xmlDocPtr doc;
xmlXPathContextPtr xpathCtx;
xmlXPathObjectPtr xpathObj;
assert(filename);
assert(xpathExpr);
/* Load XML document */
doc = xmlParseFile(filename);
if (doc == NULL) {
fprintf(stderr, "Error: unable to parse file \"%s\"\n", filename);
return(-1);
}
/* Create xpath evaluation context */
xpathCtx = xmlXPathNewContext(doc);
if(xpathCtx == NULL) {
fprintf(stderr,"Error: unable to create new XPath context\n");
xmlFreeDoc(doc);
return(-1);
}
/* Register namespaces from list (if any) */
if((nsList != NULL) && (register_namespaces(xpathCtx, nsList) < 0)) {
fprintf(stderr,"Error: failed to register namespaces list \"%s\"\n", nsList);
xmlXPathFreeContext(xpathCtx);
xmlFreeDoc(doc);
return(-1);
}
/* Evaluate xpath expression */
xpathObj = xmlXPathEvalExpression(xpathExpr, xpathCtx);
if(xpathObj == NULL) {
fprintf(stderr,"Error: unable to evaluate xpath expression \"%s\"\n", xpathExpr);
xmlXPathFreeContext(xpathCtx);
xmlFreeDoc(doc);
return(-1);
}
/* Print results */
print_xpath_nodes(xpathObj->nodesetval, stdout);
/* Cleanup */
xmlXPathFreeObject(xpathObj);
xmlXPathFreeContext(xpathCtx);
xmlFreeDoc(doc);
return(0);
}
/**
* register_namespaces:
* @xpathCtx: the pointer to an XPath context.
* @nsList: the list of known namespaces in
* "<prefix1>=<href1> <prefix2>=href2> ..." format.
*
* Registers namespaces from @nsList in @xpathCtx.
*
* Returns 0 on success and a negative value otherwise.
*/
int
register_namespaces(xmlXPathContextPtr xpathCtx, const xmlChar* nsList) {
xmlChar* nsListDup;
xmlChar* prefix;
xmlChar* href;
xmlChar* next;
assert(xpathCtx);
assert(nsList);
nsListDup = xmlStrdup(nsList);
if(nsListDup == NULL) {
fprintf(stderr, "Error: unable to strdup namespaces list\n");
return(-1);
}
next = nsListDup;
while(next != NULL) {
/* skip spaces */
while((*next) == ' ') next++;
if((*next) == '\0') break;
/* find prefix */
prefix = next;
next = (xmlChar*)xmlStrchr(next, '=');
if(next == NULL) {
fprintf(stderr,"Error: invalid namespaces list format\n");
free(nsListDup);
return(-1);
}
*(next++) = '\0';
/* find href */
href = next;
next = (xmlChar*)xmlStrchr(next, ' ');
if(next != NULL) {
*(next++) = '\0';
}
/* do register namespace */
if(xmlXPathRegisterNs(xpathCtx, prefix, href) != 0) {
fprintf(stderr,"Error: unable to register NS with prefix=\"%s\" and href=\"%s\"\n", prefix, href);
free(nsListDup);
return(-1);
}
}
free(nsListDup);
return(0);
}
/**
* print_xpath_nodes:
* @nodes: the nodes set.
* @output: the output file handle.
*
* Prints the @nodes content to @output.
*/
void
print_xpath_nodes(xmlNodeSetPtr nodes, FILE* output) {
xmlNodePtr cur;
int size;
int i;
assert(output);
size = (nodes) ? nodes->nodeNr : 0;
fprintf(output, "Result (%d nodes):\n", size);
for(i = 0; i < size; ++i) {
assert(nodes->nodeTab[i]);
if(nodes->nodeTab[i]->type == XML_NAMESPACE_DECL) {
xmlNsPtr ns;
ns = (xmlNsPtr)nodes->nodeTab[i];
cur = (xmlNodePtr)ns->next;
if(cur->ns) {
fprintf(output, "= namespace \"%s\"=\"%s\" for node %s:%s\n",
ns->prefix, ns->href, cur->ns->href, cur->name);
} else {
fprintf(output, "= namespace \"%s\"=\"%s\" for node %s\n",
ns->prefix, ns->href, cur->name);
}
} else if(nodes->nodeTab[i]->type == XML_ELEMENT_NODE) {
cur = nodes->nodeTab[i];
if(cur->ns) {
fprintf(output, "= element node \"%s:%s\"\n",
cur->ns->href, cur->name);
} else {
fprintf(output, "= element node \"%s\"\n",
cur->name);
}
} else {
cur = nodes->nodeTab[i];
fprintf(output, "= node \"%s\": type %d\n", cur->name, cur->type);
}
}
}