IF YOU WOULD LIKE TO GET AN ACCOUNT, please write an
email to Administrator. User accounts are meant only to access repo
and report issues and/or generate pull requests.
This is a purpose-specific Git hosting for
BaseALT
projects. Thank you for your understanding!
Только зарегистрированные пользователи имеют доступ к сервису!
Для получения аккаунта, обратитесь к администратору.
</style><title>Libxml2 set of examples</title></head><bodybgcolor="#8b7765"text="#000000"link="#000000"vlink="#000000"><tableborder="0"width="100%"cellpadding="5"cellspacing="0"align="center"><tr><tdwidth="120"><ahref="http://swpat.ffii.org/"><imgsrc="../epatents.png"alt="Action against software patents"/></a></td><tdwidth="180"><ahref="http://www.gnome.org/"><imgsrc="../gnome2.png"alt="Gnome2 Logo"/></a><ahref="http://www.w3.org/Status"><imgsrc="../w3c.png"alt="W3C Logo"/></a><ahref="http://www.redhat.com/"><imgsrc="../redhat.gif"alt="Red Hat Logo"/></a><divalign="left"><ahref="http://xmlsoft.org/"><imgsrc="../Libxml2-Logo-180x168.gif"alt="Made with Libxml2 Logo"/></a></div></td><td><tableborder="0"width="90%"cellpadding="2"cellspacing="0"align="center"bgcolor="#000000"><tr><td><tablewidth="100%"border="0"cellspacing="1"cellpadding="3"bgcolor="#fffacd"><tr><tdalign="center"><h1></h1><h2>Libxml2 set of examples</h2></td></tr></table></td></tr></table></td></tr></table><tableborder="0"cellpadding="4"cellspacing="0"width="100%"align="center"><tr><tdbgcolor="#8b7765"><tableborder="0"cellspacing="0"cellpadding="2"width="100%"><tr><tdvalign="top"width="200"bgcolor="#8b7765"><tableborder="0"cellspacing="0"cellpadding="1"width="100%"bgcolor="#000000"><tr><td><tablewidth="100%"border="0"cellspacing="1"cellpadding="3"><tr><tdcolspan="1"bgcolor="#eecfa1"align="center"><center><b>Examples Menu</b></center></td></tr><tr><tdbgcolor="#fffacd"><formaction="../search.php"enctype="application/x-www-form-urlencoded"method="get"><inputname="query"type="text"size="20"value=""/><inputname="submit"type="submit"value="Search ..."/></form><ul><li><ahref="../index.html">Home</a></li><li><astyle="font-weight:bold"href="../docs.html">Developer Menu</a></li><li><astyle="font-weight:bold"href="../html/index.html">API Menu</a></li><li><ahref="#InputOutput">InputOutput Examples</a></li><li><ahref="#Parsing">Parsing Examples</a></li><li><ahref="#Tree">Tree Examples</a></li><li><ahref="#XPath">XPath Examples</a></li><li><ahref="#xmlReader">xmlReader Examples</a></li><li><ahref="#xmlWriter">xmlWriter Examples</a></li><li><ahref="../guidelines.html">XML Guidelines</a></li></ul></td></tr></table><tablewidth="100%"border="0"cellspacing="1"cellpadding="3"><tr><tdcolspan="1"bgcolor="#eecfa1"align="center"><center><b>Related links</b></center></td></tr><tr><tdbgcolor="#fffacd"><ul><li><ahref="http://mail.gnome.org/archives/xml/">Mail archive</a></li><li><ahref="http://xmlsoft.org/XSLT/">XSLT libxslt</a></li><li><ahref="http://phd.cs.unibo.it/gdome2/">DOM gdome2</a></li><li><ahref="http://www.aleksey.com/xmlsec/">XML-DSig xmlsec</a></li><li><ahref="ftp://xmlsoft.org/">FTP</a></li><li><ahref="http://www.zlatkovic.com/projects/libxml/">Windows binaries</a></li><li><ahref="http://opencsw.org/packages/libxml2">Solaris binaries</a></li><li><ahref="http://www.explain.com.au/oss/libxml2xslt.html">MacOsX binaries</a></li><li><ahref="http://lxml.de/">lxml Python bindings</a></li><li><ahref="http://cpan.uwinnipeg.ca/dist/XML-LibXML">Perl bindings</a></li><li><ahref="http://libxmlplusplus.sourceforge.net/">C++ bindings</a></li><li><ahref="http://www.zend.com/php5/articles/php5-xmlphp.php#Heading4">PHP bindings</a></li><li><ahref="http://sourceforge.net/projects/libxml2-pas/">Pascal bindings</a></li><li><ahref="http://libxml.rubyforge.org/">Ruby bindings</a></li><li><ahref="http://tclxml.sourceforge.net/">Tcl bindings</a></li><li><ahref="http://bugzilla.gnome.org/buglist.cgi?product=libxml2">Bug Tracker</a></li></ul></td></tr></table></td></tr></table></td><tdvalign="top"bgcolor="#8b7765"><tableborder="0"cellspacing="0"cellpadding="1"width="100%"><tr><td><tableborder="0"cellspacing="0"cellpadding="1"width="100%"bgcolor="#000000"><tr><td><tableborder="0"cellpadding="3"cellspacing="1"width="100%"><tr><tdbgcolor="#fffacd"><p> The examples are stored per section depending on the main focus
of the example:</p><ul><li><p><ahref="#xmlWriter">xmlWriter</a> :</p><ul><li><ahref="#testWriter.c">testWriter.c</a>: use various APIs for the xmlWriter</li></ul></li><li><p><ahref="#InputOutput">InputOutput</a> :</p><ul><li><ahref="#io1.c">io1.c</a>: Example of custom Input/Output</li><li><ahref="#io2.c">io2.c</a>: Output to char buffer</li></ul></li><li><p><ahref="#Tree">Tree</a> :</p><ul><li><ahref="#tree2.c">tree2.c</a>: Creates a tree</li><li><ahref="#tree1.c">tree1.c</a>: Navigates a tree to print element names</li></ul></li><li><p><ahref="#XPath">XPath</a> :</p><ul><li><ahref="#xpath1.c">xpath1.c</a>: Evaluate XPath expression and prints result node set.</li><li><ahref="#xpath2.c">xpath2.c</a>: Load a document, locate subelements with XPath, modify said elements and save the resulting document.</li></ul></li><li><p><ahref="#Parsing">Parsing</a> :</p><ul><li><ahref="#parse3.c">parse3.c</a>: Parse an XML document in memory to a tree and free it</li><li><ahref="#parse4.c">parse4.c</a>: Parse an XML document chunk by chunk to a tree and free it</li><li><ahref="#parse2.c">parse2.c</a>: Parse and validate an XML file to a tree and free the result</li><li><ahref="#parse1.c">parse1.c</a>: Parse an XML file to a tree and free it</li></ul></li><li><p><ahref="#xmlReader">xmlReader</a> :</p><ul><li><ahref="#reader2.c">reader2.c</a>: Parse and validate an XML file with an xmlReader</li><li><ahref="#reader1.c">reader1.c</a>: Parse an XML file with an xmlReader</li><li><ahref="#reader3.c">reader3.c</a>: Show how to extract subdocuments with xmlReader</li><li><ahref="#reader4.c">reader4.c</a>: Parse multiple XML files reusing an xmlReader</li></ul></li></ul><p> Getting the compilation options and libraries dependancies needed
install</i> step or when installing the libxml2 development package:</p><pre>gcc -o example `xml2-config --cflags` example.c `xml2-config --libs`</pre><h2><aname="InputOutput"id="InputOutput"></a>InputOutput Examples</h2><h3><aname="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><ahref="../html/libxml-parser.html"><libxml/parser.h></a></li><li><ahref="../html/libxml-xmlIO.html"><libxml/xmlIO.h></a></li><li><ahref="../html/libxml-xinclude.html"><libxml/xinclude.h></a></li><li><ahref="../html/libxml-tree.html"><libxml/tree.h></a></li></ul><p>Uses:</p><ul><li> line 105: Type <ahref="../html/libxml-tree.html#xmlDocPtr">xmlDocPtr</a> from tree.h</li><li> line 117: Macro <ahref="../html/libxml-xmlversion.html#LIBXML_TEST_VERSION">LIBXML_TEST_VERSION</a> from xmlversion.h</li><li> line 117: Function <ahref="../html/libxml-xmlIO.html#xmlRegisterInputCallbacks">xmlRegisterInputCallbacks</a> from xmlIO.h</li><li> line 124: Function <ahref="../html/libxml-parser.html#xmlReadMemory">xmlReadMemory</a> from parser.h</li><li> line 134: Function <ahref="../html/libxml-xinclude.html#xmlXIncludeProcess">xmlXIncludeProcess</a> from xinclude.h</li><li> line 143: Function <ahref="../html/libxml-tree.html#xmlDocDump">xmlDocDump</a> from tree.h</li><li> line 149: Function <ahref="../html/libxml-tree.html#xmlFreeDoc">xmlFreeDoc</a> from tree.h</li><li> line 154: Function <ahref="../html/libxml-parser.html#xmlCleanupParser">xmlCleanupParser</a> from parser.h</li><li> line 158: Function <ahref="../html/libxml-xmlmemory.html#xmlMemoryDump">xmlMemoryDump</a> from xmlmemory.h</li></ul><p>Usage:</p><p>io1</p><p>Author: Daniel Veillard</p><h3><aname="io2.c"href="io2.c"id="io2.c">io2.c</a>: Output to char buffer</h3><p>Demonstrate the use of xmlDocDumpMemory to output document to a character buffer</p><p>Includes:</p><ul><li><ahref="../html/libxml-parser.html"><libxml/parser.h></a></li></ul><p>Uses:</p><ul><li> line 19: Type <ahref="../html/libxml-tree.html#xmlNodePtr">xmlNodePtr</a> from tree.h</li><li> line 20: Type <ahref="../html/libxml-tree.html#xmlDocPtr">xmlDocPtr</a> from tree.h</li><li> line 27: Function <ahref="../html/libxml-tree.html#xmlNewDoc">xmlNewDoc</a> from tree.h</li><li> line 28: Function <ahref="../html/libxml-tree.html#xmlNewNode">xmlNewNode</a> from tree.h</li><li> line 29: Function <ahref="../html/libxml-tree.html#xmlNodeSetContent">xmlNodeSetContent</a> from tree.h</li><li> line 30: Function <ahref="../html/libxml-tree.html#xmlDocSetRootElement">xmlDocSetRootElement</a> from tree.h</li><li> line 36: Function <ahref="../html/libxml-tree.html#xmlDocDumpFormatMemory">xmlDocDumpFormatMemory</a> from tree.h</li></ul><p>Usage:</p><p>io2</p><p>Author: John Fleck</p><h2><aname="Parsing"id="Parsing"></a>Parsing Examples</h2><h3><aname="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><ahref="../html/libxml-tree.html"><libxml/tree.h></a></li><li><ahref="../html/libxml-parser.html"><libxml/parser.h></a></li></ul><p>Uses:</p><ul><li> line 27: Type <ahref="../html/libxml-tree.html#xmlDocPtr">xmlDocPtr</a> from tree.h</li><li> line 33: Function <ahref="../html/libxml-parser.html#xmlReadMemory">xmlReadMemory</a> from parser.h</li><li> line 38: Function <ahref="../html/libxml-tree.html#xmlFreeDoc">xmlFreeDoc</a> from tree.h</li><li> line 49: Macro <ahref="../html/libxml-xmlversion.html#LIBXML_TEST_VERSION">LIBXML_TEST_VERSION</a> from xmlversion.h</li><li> line 54: Function <ahref="../html/libxml-parser.html#xmlCleanupParser">xmlCleanupParser</a> from parser.h</li><li> line 58: Function <ahref="../html/libxml-xmlmemory.ht