aboutsummaryrefslogtreecommitdiffstats
path: root/doc/examples
diff options
context:
space:
mode:
authorDaniel Veillard <veillard@src.gnome.org>2004-01-23 13:15:13 +0000
committerDaniel Veillard <veillard@src.gnome.org>2004-01-23 13:15:13 +0000
commit4773df2a58be83e1b9b1b55840371acf37386820 (patch)
treece137762c538aa4b931cc42676df51d4b70cd766 /doc/examples
parente9f0811a2fab2491383c6d78800ab07a0b4f8336 (diff)
downloadandroid_external_libxml2-4773df2a58be83e1b9b1b55840371acf37386820.tar.gz
android_external_libxml2-4773df2a58be83e1b9b1b55840371acf37386820.tar.bz2
android_external_libxml2-4773df2a58be83e1b9b1b55840371acf37386820.zip
added io1.c an example ox xmlIO usage and io1.res test result, fixed a
* doc/examples/*: added io1.c an example ox xmlIO usage and io1.res test result, fixed a awful lot of memory leaks showing up in testWriter.c, changed the examples and the Makefiles to test memory leaks. * xmlwriter.c: fixed a memory leak * Makefile.am: run the doc/examples regression tests as part of make tests * xpath.c include/libxml/xpath.h: added xmlXPathCtxtCompile() to compile an XPath expression within a context, currently the goal is to be able to reuse the XSLT stylesheet dictionnary, but this opens the door to others possible optimizations. * dict.c include/libxml/dict.h: added xmlDictCreateSub() which allows to build a new dictionnary based on another read-only dictionnary. This is needed for XSLT to keep the stylesheet dictionnary read-only while being able to reuse the strings for the transformation dictionnary. * xinclude.c: fixed a dictionnar reference counting problem occuring when document parsing failed. * testSAX.c: adding option --repeat for timing 100times the parsing * doc/* : rebuilt all the docs Daniel
Diffstat (limited to 'doc/examples')
-rw-r--r--doc/examples/.cvsignore1
-rw-r--r--doc/examples/Makefile.am20
-rw-r--r--doc/examples/examples.xml158
-rw-r--r--doc/examples/index.html4
-rwxr-xr-xdoc/examples/index.py2
-rw-r--r--doc/examples/io1.c154
-rw-r--r--doc/examples/io1.res5
-rw-r--r--doc/examples/parse1.c4
-rw-r--r--doc/examples/parse2.c4
-rw-r--r--doc/examples/reader1.c4
-rw-r--r--doc/examples/reader2.c4
-rw-r--r--doc/examples/reader3.c4
-rw-r--r--doc/examples/testWriter.c122
-rw-r--r--doc/examples/tree2.c4
-rw-r--r--doc/examples/xpath1.c4
15 files changed, 393 insertions, 101 deletions
diff --git a/doc/examples/.cvsignore b/doc/examples/.cvsignore
index 17222712..00877b27 100644
--- a/doc/examples/.cvsignore
+++ b/doc/examples/.cvsignore
@@ -10,3 +10,4 @@ testWriter
reader1
reader2
reader3
+io1
diff --git a/doc/examples/Makefile.am b/doc/examples/Makefile.am
index 61136ab9..3dfc8cf2 100644
--- a/doc/examples/Makefile.am
+++ b/doc/examples/Makefile.am
@@ -19,9 +19,9 @@ install-data-local:
$(mkinstalldirs) $(DESTDIR)$(TARGET_DIR)
-@INSTALL@ -m 0644 $(srcdir)/*.html $(srcdir)/*.c $(srcdir)/*.xml $(srcdir)/*.xsl $(srcdir)/*.res $(DESTDIR)$(TARGET_DIR)
-EXTRA_DIST=examples.xsl index.py test1.xml examples.xml test2.xml writer.xml test3.xml reader1.res reader3.res tree1.res tree2.res
+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
+noinst_PROGRAMS=xpath1 parse1 parse2 tree1 tree2 testWriter reader1 reader2 reader3 io1
xpath1_SOURCES=xpath1.c
xpath1_LDFLAGS=
@@ -68,14 +68,30 @@ reader3_LDFLAGS=
reader3_DEPENDENCIES= $(DEPS)
reader3_LDADD= @RDL_LIBS@ $(LDADDS)
+io1_SOURCES=io1.c
+io1_LDFLAGS=
+io1_DEPENDENCIES= $(DEPS)
+io1_LDADD= @RDL_LIBS@ $(LDADDS)
+
tests: $(noinst_PROGRAMS)
+ @(echo > .memdump)
@(parse1 test1.xml)
+ @(grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0)
@(parse2 test2.xml)
+ @(grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0)
@(tree1 test2.xml > tree1.tmp ; diff tree1.tmp tree1.res ; rm tree1.tmp)
+ @(grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0)
@(tree2 > tree2.tmp ; diff tree2.tmp tree2.res ; rm tree2.tmp)
+ @(grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0)
@(testWriter ; for i in 1 2 3 4 ; do diff writer.xml writer$$i.res ; done ; rm writer*.res)
+ @(grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0)
@(reader1 test2.xml > reader1.tmp ; diff reader1.tmp reader1.res ; rm reader1.tmp)
+ @(grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0)
@(reader2 test2.xml > reader1.tmp ; diff reader1.tmp reader1.res ; rm reader1.tmp)
+ @(grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0)
@(reader3 > reader3.tmp ; diff reader3.tmp reader3.res ; rm reader3.tmp)
+ @(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)
diff --git a/doc/examples/examples.xml b/doc/examples/examples.xml
index 20e562f0..c7973835 100644
--- a/doc/examples/examples.xml
+++ b/doc/examples/examples.xml
@@ -13,25 +13,27 @@
<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'/>
+ <enum line='225' file='tree' name='XML_ELEMENT_NODE'/>
+ <typedef line='84' file='xpath' name='xmlXPathObjectPtr'/>
+ <function line='50' file='xmlmemory' name='xmlMemoryDump'/>
+ <function line='113' file='xpath' name='xmlXPathEvalExpression'/>
+ <function line='182' file='xpathInternals' name='xmlXPathRegisterNs'/>
+ <function line='125' file='xpath' name='xmlXPathFreeObject'/>
+ <typedef line='82' file='tree' name='xmlDocPtr'/>
+ <typedef line='214' file='tree' name='xmlNsPtr'/>
+ <function line='97' file='xpath' name='xmlXPathNewContext'/>
+ <typedef line='202' file='tree' name='xmlNodePtr'/>
<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'/>
+ <typedef line='83' file='xpath' name='xmlXPathContextPtr'/>
+ <function line='126' 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'/>
+ <function line='152' file='xmlstring' name='xmlStrdup'/>
+ <function line='127' file='tree' name='xmlFreeDoc'/>
+ <function line='176' file='xmlstring' name='xmlStrchr'/>
+ <variable line='189' file='globals' name='xmlFree'/>
+ <function line='90' file='parser' name='xmlParseFile'/>
+ <enum line='213' file='tree' name='XML_NAMESPACE_DECL'/>
</uses>
</example>
<example filename='parse1.c'>
@@ -49,9 +51,10 @@
<uses>
<function line='50' file='parser' name='xmlCleanupParser'/>
<macro line='45' file='xmlversion' name='LIBXML_TEST_VERSION'/>
+ <typedef line='24' file='tree' name='xmlDocPtr'/>
<function line='31' file='tree' name='xmlFreeDoc'/>
<function line='26' file='parser' name='xmlReadFile'/>
- <typedef line='24' file='tree' name='xmlDocPtr'/>
+ <function line='54' file='xmlmemory' name='xmlMemoryDump'/>
</uses>
</example>
<example filename='parse2.c'>
@@ -76,6 +79,7 @@
<function line='35' file='parser' name='xmlCtxtReadFile'/>
<function line='44' file='tree' name='xmlFreeDoc'/>
<typedef line='26' file='tree' name='xmlDocPtr'/>
+ <function line='70' file='xmlmemory' name='xmlMemoryDump'/>
</uses>
</example>
<example filename='tree1.c'>
@@ -113,6 +117,7 @@
</includes>
<uses>
<function line='73' file='tree' name='xmlNewText'/>
+ <function line='108' file='xmlmemory' name='xmlMemoryDump'/>
<function line='94' file='tree' name='xmlSaveFormatFileEnc'/>
<function line='76' file='tree' name='xmlAddChild'/>
<function line='39' file='tree' name='xmlDocSetRootElement'/>
@@ -139,36 +144,39 @@
<include>&lt;libxml/xmlwriter.h&gt;</include>
</includes>
<uses>
- <function line='1075' file='xmlwriter' name='xmlTextWriterEndElement'/>
- <function line='880' file='xmlwriter' name='xmlTextWriterStartDocument'/>
- <function line='1085' file='xmlwriter' name='xmlTextWriterEndDocument'/>
- <function line='925' file='xmlwriter' name='xmlTextWriterWriteFormatComment'/>
- <function line='890' file='xmlwriter' name='xmlTextWriterWriteComment'/>
- <variable line='1147' file='globals' name='xmlRealloc'/>
- <function line='1037' file='xmlwriter' name='xmlTextWriterWriteFormatElement'/>
- <function line='1120' file='encoding' name='xmlFindCharEncodingHandler'/>
- <typedef line='1115' file='encoding' name='xmlCharEncodingHandlerPtr'/>
- <function line='871' file='xmlwriter' name='xmlNewTextWriterTree'/>
- <function line='58' file='xmlwriter' name='xmlNewTextWriterFilename'/>
- <function line='1095' file='tree' name='xmlFreeDoc'/>
- <typedef line='848' file='tree' name='xmlNodePtr'/>
- <typedef line='847' file='tree' name='xmlDocPtr'/>
- <typedef line='320' file='tree' name='xmlBufferPtr'/>
- <function line='603' file='xmlwriter' name='xmlNewTextWriterDoc'/>
- <function line='861' file='tree' name='xmlNewDocNode'/>
- <function line='1093' file='tree' name='xmlSaveFileEnc'/>
- <macro line='852' file='parser' name='XML_DEFAULT_VERSION'/>
- <function line='333' file='xmlwriter' name='xmlNewTextWriterMemory'/>
- <variable line='1144' file='globals' name='xmlFree'/>
- <function line='868' file='tree' name='xmlDocSetRootElement'/>
- <function line='1091' file='xmlwriter' name='xmlFreeTextWriter'/>
- <function line='1060' file='xmlwriter' name='xmlTextWriterStartElement'/>
- <variable line='1130' file='globals' name='xmlMalloc'/>
- <function line='325' file='tree' name='xmlBufferCreate'/>
- <typedef line='846' file='xmlwriter' name='xmlTextWriterPtr'/>
- <function line='1067' file='xmlwriter' name='xmlTextWriterWriteElement'/>
- <function line='916' file='xmlwriter' name='xmlTextWriterWriteAttribute'/>
- <function line='852' file='tree' name='xmlNewDoc'/>
+ <function line='1090' file='xmlwriter' name='xmlTextWriterEndElement'/>
+ <function line='895' file='xmlwriter' name='xmlTextWriterStartDocument'/>
+ <function line='1100' file='xmlwriter' name='xmlTextWriterEndDocument'/>
+ <function line='940' file='xmlwriter' name='xmlTextWriterWriteFormatComment'/>
+ <function line='905' file='xmlwriter' name='xmlTextWriterWriteComment'/>
+ <function line='52' file='parser' name='xmlCleanupParser'/>
+ <variable line='1145' file='globals' name='xmlMalloc'/>
+ <function line='1052' file='xmlwriter' name='xmlTextWriterWriteFormatElement'/>
+ <function line='1135' file='encoding' name='xmlFindCharEncodingHandler'/>
+ <typedef line='1130' file='encoding' name='xmlCharEncodingHandlerPtr'/>
+ <function line='886' file='xmlwriter' name='xmlNewTextWriterTree'/>
+ <function line='73' file='xmlwriter' name='xmlNewTextWriterFilename'/>
+ <function line='1110' file='tree' name='xmlFreeDoc'/>
+ <typedef line='863' file='tree' name='xmlNodePtr'/>
+ <typedef line='862' file='tree' name='xmlDocPtr'/>
+ <typedef line='335' file='tree' name='xmlBufferPtr'/>
+ <function line='618' file='xmlwriter' name='xmlNewTextWriterDoc'/>
+ <function line='876' file='tree' name='xmlNewDocNode'/>
+ <function line='1108' file='tree' name='xmlSaveFileEnc'/>
+ <function line='56' file='xmlmemory' name='xmlMemoryDump'/>
+ <macro line='867' file='parser' name='XML_DEFAULT_VERSION'/>
+ <function line='348' file='xmlwriter' name='xmlNewTextWriterMemory'/>
+ <variable line='1159' file='globals' name='xmlFree'/>
+ <function line='883' file='tree' name='xmlDocSetRootElement'/>
+ <function line='1106' file='xmlwriter' name='xmlFreeTextWriter'/>
+ <function line='1075' file='xmlwriter' name='xmlTextWriterStartElement'/>
+ <macro line='38' file='xmlversion' name='LIBXML_TEST_VERSION'/>
+ <function line='340' file='tree' name='xmlBufferCreate'/>
+ <typedef line='861' file='xmlwriter' name='xmlTextWriterPtr'/>
+ <function line='1082' file='xmlwriter' name='xmlTextWriterWriteElement'/>
+ <function line='931' file='xmlwriter' name='xmlTextWriterWriteAttribute'/>
+ <variable line='1162' file='globals' name='xmlRealloc'/>
+ <function line='867' file='tree' name='xmlNewDoc'/>
</uses>
</example>
<example filename='reader1.c'>
@@ -183,14 +191,13 @@
<include>&lt;libxml/xmlreader.h&gt;</include>
</includes>
<uses>
- <function line='40' file='parser' name='xmlStrlen'/>
- <function line='90' file='parser' name='xmlCleanupParser'/>
+ <function line='40' file='xmlstring' name='xmlStrlen'/>
<function line='33' file='xmlreader' name='xmlTextReaderNodeType'/>
<typedef line='55' file='xmlreader' name='xmlTextReaderPtr'/>
+ <function line='94' file='xmlmemory' name='xmlMemoryDump'/>
<function line='29' file='xmlreader' name='xmlTextReaderConstValue'/>
<function line='32' file='xmlreader' name='xmlTextReaderDepth'/>
<function line='65' file='xmlreader' name='xmlFreeTextReader'/>
- <macro line='85' file='xmlversion' name='LIBXML_TEST_VERSION'/>
<function line='25' file='xmlreader' name='xmlTextReaderConstName'/>
<function line='36' file='xmlreader' name='xmlTextReaderHasValue'/>
<function line='63' file='xmlreader' name='xmlTextReaderRead'/>
@@ -210,7 +217,7 @@
<include>&lt;libxml/xmlreader.h&gt;</include>
</includes>
<uses>
- <function line='41' file='parser' name='xmlStrlen'/>
+ <function line='41' file='xmlstring' name='xmlStrlen'/>
<function line='34' file='xmlreader' name='xmlTextReaderNodeType'/>
<typedef line='56' file='xmlreader' name='xmlTextReaderPtr'/>
<function line='30' file='xmlreader' name='xmlTextReaderConstValue'/>
@@ -249,6 +256,28 @@
<typedef line='72' file='tree' name='xmlDocPtr'/>
</uses>
</example>
+ <example filename='io1.c'>
+ <synopsis>Example of custom Input/Output</synopsis>
+ <purpose>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.</purpose>
+ <usage>io1</usage>
+ <test>io1 &gt; io1.tmp ; diff io1.tmp io1.res ; rm -f io1.tmp</test>
+ <author>Daniel Veillard</author>
+ <copy>see Copyright for the status of this software. </copy>
+ <section>InputOutput</section>
+ <includes>
+ <include>&lt;libxml/parser.h&gt;</include>
+ <include>&lt;libxml/xinclude.h&gt;</include>
+ <include>&lt;libxml/tree.h&gt;</include>
+ <include>&lt;libxml/xmlIO.h&gt;</include>
+ </includes>
+ <uses>
+ <function line='139' file='tree' name='xmlDocDump'/>
+ <function line='132' file='xinclude' name='xmlXIncludeProcess'/>
+ <function line='116' file='xmlIO' name='xmlRegisterInputCallbacks'/>
+ <function line='123' file='parser' name='xmlReadMemory'/>
+ <typedef line='104' file='tree' name='xmlDocPtr'/>
+ </uses>
+ </example>
<symbols>
<symbol name='LIBXML_TEST_VERSION'>
<ref filename='xpath1.c'/>
@@ -256,7 +285,7 @@
<ref filename='parse2.c'/>
<ref filename='tree1.c'/>
<ref filename='tree2.c'/>
- <ref filename='reader1.c'/>
+ <ref filename='testWriter.c'/>
</symbol>
<symbol name='XML_DEFAULT_VERSION'>
<ref filename='testWriter.c'/>
@@ -296,7 +325,7 @@
<ref filename='parse2.c'/>
<ref filename='tree1.c'/>
<ref filename='tree2.c'/>
- <ref filename='reader1.c'/>
+ <ref filename='testWriter.c'/>
</symbol>
<symbol name='xmlCreateIntSubset'>
<ref filename='tree2.c'/>
@@ -306,6 +335,7 @@
</symbol>
<symbol name='xmlDocDump'>
<ref filename='reader3.c'/>
+ <ref filename='io1.c'/>
</symbol>
<symbol name='xmlDocGetRootElement'>
<ref filename='tree1.c'/>
@@ -316,6 +346,7 @@
<ref filename='parse2.c'/>
<ref filename='testWriter.c'/>
<ref filename='reader3.c'/>
+ <ref filename='io1.c'/>
</symbol>
<symbol name='xmlDocSetRootElement'>
<ref filename='tree2.c'/>
@@ -325,6 +356,7 @@
<ref filename='testWriter.c'/>
</symbol>
<symbol name='xmlFree'>
+ <ref filename='xpath1.c'/>
<ref filename='testWriter.c'/>
</symbol>
<symbol name='xmlFreeDoc'>
@@ -352,6 +384,14 @@
<symbol name='xmlMalloc'>
<ref filename='testWriter.c'/>
</symbol>
+ <symbol name='xmlMemoryDump'>
+ <ref filename='xpath1.c'/>
+ <ref filename='parse1.c'/>
+ <ref filename='parse2.c'/>
+ <ref filename='tree2.c'/>
+ <ref filename='testWriter.c'/>
+ <ref filename='reader1.c'/>
+ </symbol>
<symbol name='xmlNewChild'>
<ref filename='tree2.c'/>
</symbol>
@@ -403,6 +443,9 @@
<symbol name='xmlReadFile'>
<ref filename='parse1.c'/>
</symbol>
+ <symbol name='xmlReadMemory'>
+ <ref filename='io1.c'/>
+ </symbol>
<symbol name='xmlReaderForFile'>
<ref filename='reader1.c'/>
<ref filename='reader2.c'/>
@@ -411,6 +454,9 @@
<symbol name='xmlRealloc'>
<ref filename='testWriter.c'/>
</symbol>
+ <symbol name='xmlRegisterInputCallbacks'>
+ <ref filename='io1.c'/>
+ </symbol>
<symbol name='xmlSaveFileEnc'>
<ref filename='testWriter.c'/>
</symbol>
@@ -500,6 +546,9 @@
<symbol name='xmlTextWriterWriteFormatElement'>
<ref filename='testWriter.c'/>
</symbol>
+ <symbol name='xmlXIncludeProcess'>
+ <ref filename='io1.c'/>
+ </symbol>
<symbol name='xmlXPathContextPtr'>
<ref filename='xpath1.c'/>
</symbol>
@@ -523,6 +572,9 @@
</symbol>
</symbols>
<sections>
+ <section name='InputOutput'>
+ <example filename='io1.c'/>
+ </section>
<section name='Parsing'>
<example filename='parse1.c'/>
<example filename='parse2.c'/>
diff --git a/doc/examples/index.html b/doc/examples/index.html
index e2520f5c..728eb718 100644
--- a/doc/examples/index.html
+++ b/doc/examples/index.html
@@ -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>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="#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="#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="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="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: 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#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><li> line 83: 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 32: Macro <a href="../html/libxml-xmlversion.html#LIBXML_TEST_VERSION">LIBXML_TEST_VERSION</a> from xmlversion.h</li><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><li> line 97: Function <a href="../html/libxml-tree.html#xmlFreeDoc">xmlFreeDoc</a> from tree.h</li><li> line 103: Function <a href="../html/libxml-parser.html#xmlCleanupParser">xmlCleanupParser</a> from parser.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 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><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</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 25: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderConstName">xmlTextReaderConstName</a> from xmlreader.h</li><li> line 29: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderConstValue">xmlTextReaderConstValue</a> from xmlreader.h</li><li> line 32: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderDepth">xmlTextReaderDepth</a> from xmlreader.h</li><li> line 33: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderNodeType">xmlTextReaderNodeType</a> from xmlreader.h</li><li> line 35: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderIsEmptyElement">xmlTextReaderIsEmptyElement</a> from xmlreader.h</li><li> line 36: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderHasValue">xmlTextReaderHasValue</a> from xmlreader.h</li><li> line 40: Function <a href="../html/libxml-parser.html#xmlStrlen">xmlStrlen</a> from parser.h</li><li> line 55: Type <a href="../html/libxml-xmlreader.html#xmlTextReaderPtr">xmlTextReaderPtr</a> from xmlreader.h</li><li> line 58: Function <a href="../html/libxml-xmlreader.html#xmlReaderForFile">xmlReaderForFile</a> from xmlreader.h</li><li> line 63: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderRead">xmlTextReaderRead</a> from xmlreader.h</li><li> line 65: Function <a href="../html/libxml-xmlreader.html#xmlFreeTextReader">xmlFreeTextReader</a> from xmlreader.h</li><li> line 85: Macro <a href="../html/libxml-xmlversion.html#LIBXML_TEST_VERSION">LIBXML_TEST_VERSION</a> from xmlversion.h</li><li> line 90: Function <a href="../html/libxml-parser.html#xmlCleanupParser">xmlCleanupParser</a> from parser.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</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 26: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderConstName">xmlTextReaderConstName</a> from xmlreader.h</li><li> line 30: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderConstValue">xmlTextReaderConstValue</a> from xmlreader.h</li><li> line 33: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderDepth">xmlTextReaderDepth</a> from xmlreader.h</li><li> line 34: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderNodeType">xmlTextReaderNodeType</a> from xmlreader.h</li><li> line 36: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderIsEmptyElement">xmlTextReaderIsEmptyElement</a> from xmlreader.h</li><li> line 37: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderHasValue">xmlTextReaderHasValue</a> from xmlreader.h</li><li> line 41: Function <a href="../html/libxml-parser.html#xmlStrlen">xmlStrlen</a> from parser.h</li><li> line 56: Type <a href="../html/libxml-xmlreader.html#xmlTextReaderPtr">xmlTextReaderPtr</a> from xmlreader.h</li><li> line 64: Function <a href="../html/libxml-xmlreader.html#xmlReaderForFile">xmlReaderForFile</a> from xmlreader.h</li><li> line 72: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderRead">xmlTextReaderRead</a> from xmlreader.h</li><li> line 77: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderIsValid">xmlTextReaderIsValid</a> from xmlreader.h</li><li> line 80: 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</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: Type <a href="../html/libxml-xmlreader.html#xmlTextReaderPtr">xmlTextReaderPtr</a> from xmlreader.h</li><li> line 33: Function <a href="../html/libxml-xmlreader.html#xmlReaderForFile">xmlReaderForFile</a> from xmlreader.h</li><li> line 38: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderPreservePattern">xmlTextReaderPreservePattern</a> from xmlreader.h</li><li> line 47: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderRead">xmlTextReaderRead</a> from xmlreader.h</li><li> line 57: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderCurrentDoc">xmlTextReaderCurrentDoc</a> from xmlreader.h</li><li> line 61: Function <a href="../html/libxml-xmlreader.html#xmlFreeTextReader">xmlFreeTextReader</a> from xmlreader.h</li><li> line 72: Type <a href="../html/libxml-tree.html#xmlDocPtr">xmlDocPtr</a> from tree.h</li><li> line 91: 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 58: Function <a href="../html/libxml-xmlwriter.html#xmlNewTextWriterFilename">xmlNewTextWriterFilename</a> from xmlwriter.h</li><li> line 320: Type <a href="../html/libxml-tree.html#xmlBufferPtr">xmlBufferPtr</a> from tree.h</li><li> line 325: Function <a href="../html/libxml-tree.html#xmlBufferCreate">xmlBufferCreate</a> from tree.h</li><li> line 333: Function <a href="../html/libxml-xmlwriter.html#xmlNewTextWriterMemory">xmlNewTextWriterMemory</a> from xmlwriter.h</li><li> line 603: Function <a href="../html/libxml-xmlwriter.html#xmlNewTextWriterDoc">xmlNewTextWriterDoc</a> from xmlwriter.h</li><li> line 846: Type <a href="../html/libxml-xmlwriter.html#xmlTextWriterPtr">xmlTextWriterPtr</a> from xmlwriter.h</li><li> line 847: Type <a href="../html/libxml-tree.html#xmlDocPtr">xmlDocPtr</a> from tree.h</li><li> line 848: Type <a href="../html/libxml-tree.html#xmlNodePtr">xmlNodePtr</a> from tree.h</li><li> line 852: Macro <a href="../html/libxml-parser.html#XML_DEFAULT_VERSION">XML_DEFAULT_VERSION</a> from parser.h</li><li> line 852: Function <a href="../html/libxml-tree.html#xmlNewDoc">xmlNewDoc</a> from tree.h</li><li> line 861: Function <a href="../html/libxml-tree.html#xmlNewDocNode">xmlNewDocNode</a> from tree.h</li><li> line 868: Function <a href="../html/libxml-tree.html#xmlDocSetRootElement">xmlDocSetRootElement</a> from tree.h</li><li> line 871: Function <a href="../html/libxml-xmlwriter.html#xmlNewTextWriterTree">xmlNewTextWriterTree</a> from xmlwriter.h</li><li> line 880: Function <a href="../html/libxml-xmlwriter.html#xmlTextWriterStartDocument">xmlTextWriterStartDocument</a> from xmlwriter.h</li><li> line 890: Function <a href="../html/libxml-xmlwriter.html#xmlTextWriterWriteComment">xmlTextWriterWriteComment</a> from xmlwriter.h</li><li> line 916: Function <a href="../html/libxml-xmlwriter.html#xmlTextWriterWriteAttribute">xmlTextWriterWriteAttribute</a> from xmlwriter.h</li><li> line 925: Function <a href="../html/libxml-xmlwriter.html#xmlTextWriterWriteFormatComment">xmlTextWriterWriteFormatComment</a> from xmlwriter.h</li><li> line 1037: Function <a href="../html/libxml-xmlwriter.html#xmlTextWriterWriteFormatElement">xmlTextWriterWriteFormatElement</a> from xmlwriter.h</li><li> line 1060: Function <a href="../html/libxml-xmlwriter.html#xmlTextWriterStartElement">xmlTextWriterStartElement</a> from xmlwriter.h</li><li> line 1067: Function <a href="../html/libxml-xmlwriter.html#xmlTextWriterWriteElement">xmlTextWriterWriteElement</a> from xmlwriter.h</li><li> line 1075: Function <a href="../html/libxml-xmlwriter.html#xmlTextWriterEndElement">xmlTextWriterEndElement</a> from xmlwriter.h</li><li> line 1085: Function <a href="../html/libxml-xmlwriter.html#xmlTextWriterEndDocument">xmlTextWriterEndDocument</a> from xmlwriter.h</li><li> line 1091: Function <a href="../html/libxml-xmlwriter.html#xmlFreeTextWriter">xmlFreeTextWriter</a> from xmlwriter.h</li><li> line 1093: Function <a href="../html/libxml-tree.html#xmlSaveFileEnc">xmlSaveFileEnc</a> from tree.h</li><li> line 1095: Function <a href="../html/libxml-tree.html#xmlFreeDoc">xmlFreeDoc</a> from tree.h</li><li> line 1115: Type <a href="../html/libxml-encoding.html#xmlCharEncodingHandlerPtr">xmlCharEncodingHandlerPtr</a> from encoding.h</li><li> line 1120: 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>
+</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: 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></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: 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#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><li> line 83: 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 32: Macro <a href="../html/libxml-xmlversion.html#LIBXML_TEST_VERSION">LIBXML_TEST_VERSION</a> from xmlversion.h</li><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><li> line 97: Function <a href="../html/libxml-tree.html#xmlFreeDoc">xmlFreeDoc</a> from tree.h</li><li> line 103: 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>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 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 50: Function <a href="../html/libxml-xmlmemory.html#xmlMemoryDump">xmlMemoryDump</a> from xmlmemory.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 127: Function <a href="../html/libxml-tree.html#xmlFreeDoc">xmlFreeDoc</a> from tree.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</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 25: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderConstName">xmlTextReaderConstName</a> from xmlreader.h</li><li> line 29: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderConstValue">xmlTextReaderConstValue</a> from xmlreader.h</li><li> line 32: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderDepth">xmlTextReaderDepth</a> from xmlreader.h</li><li> line 33: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderNodeType">xmlTextReaderNodeType</a> from xmlreader.h</li><li> line 35: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderIsEmptyElement">xmlTextReaderIsEmptyElement</a> from xmlreader.h</li><li> line 36: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderHasValue">xmlTextReaderHasValue</a> from xmlreader.h</li><li> line 40: Function <a href="../html/libxml-xmlstring.html#xmlStrlen">xmlStrlen</a> from xmlstring.h</li><li> line 55: Type <a href="../html/libxml-xmlreader.html#xmlTextReaderPtr">xmlTextReaderPtr</a> from xmlreader.h</li><li> line 58: Function <a href="../html/libxml-xmlreader.html#xmlReaderForFile">xmlReaderForFile</a> from xmlreader.h</li><li> line 63: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderRead">xmlTextReaderRead</a> from xmlreader.h</li><li> line 65: Function <a href="../html/libxml-xmlreader.html#xmlFreeTextReader">xmlFreeTextReader</a> from xmlreader.h</li><li> line 94: 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</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 26: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderConstName">xmlTextReaderConstName</a> from xmlreader.h</li><li> line 30: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderConstValue">xmlTextReaderConstValue</a> from xmlreader.h</li><li> line 33: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderDepth">xmlTextReaderDepth</a> from xmlreader.h</li><li> line 34: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderNodeType">xmlTextReaderNodeType</a> from xmlreader.h</li><li> line 36: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderIsEmptyElement">xmlTextReaderIsEmptyElement</a> from xmlreader.h</li><li> line 37: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderHasValue">xmlTextReaderHasValue</a> from xmlreader.h</li><li> line 41: Function <a href="../html/libxml-xmlstring.html#xmlStrlen">xmlStrlen</a> from xmlstring.h</li><li> line 56: Type <a href="../html/libxml-xmlreader.html#xmlTextReaderPtr">xmlTextReaderPtr</a> from xmlreader.h</li><li> line 64: Function <a href="../html/libxml-xmlreader.html#xmlReaderForFile">xmlReaderForFile</a> from xmlreader.h</li><li> line 72: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderRead">xmlTextReaderRead</a> from xmlreader.h</li><li> line 77: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderIsValid">xmlTextReaderIsValid</a> from xmlreader.h</li><li> line 80: 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</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: Type <a href="../html/libxml-xmlreader.html#xmlTextReaderPtr">xmlTextReaderPtr</a> from xmlreader.h</li><li> line 33: Function <a href="../html/libxml-xmlreader.html#xmlReaderForFile">xmlReaderForFile</a> from xmlreader.h</li><li> line 38: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderPreservePattern">xmlTextReaderPreservePattern</a> from xmlreader.h</li><li> line 47: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderRead">xmlTextReaderRead</a> from xmlreader.h</li><li> line 57: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderCurrentDoc">xmlTextReaderCurrentDoc</a> from xmlreader.h</li><li> line 61: Function <a href="../html/libxml-xmlreader.html#xmlFreeTextReader">xmlFreeTextReader</a> from xmlreader.h</li><li> line 72: Type <a href="../html/libxml-tree.html#xmlDocPtr">xmlDocPtr</a> from tree.h</li><li> line 91: 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 38: Macro <a href="../html/libxml-xmlversion.html#LIBXML_TEST_VERSION">LIBXML_TEST_VERSION</a> from xmlversion.h</li><li> line 52: Function <a href="../html/libxml-parser.html#xmlCleanupParser">xmlCleanupParser</a> from parser.h</li><li> line 56: Function <a href="../html/libxml-xmlmemory.html#xmlMemoryDump">xmlMemoryDump</a> from xmlmemory.h</li><li> line 73: Function <a href="../html/libxml-xmlwriter.html#xmlNewTextWriterFilename">xmlNewTextWriterFilename</a> from xmlwriter.h</li><li> line 335: Type <a href="../html/libxml-tree.html#xmlBufferPtr">xmlBufferPtr</a> from tree.h</li><li> line 340: Function <a href="../html/libxml-tree.html#xmlBufferCreate">xmlBufferCreate</a> from tree.h</li><li> line 348: Function <a href="../html/libxml-xmlwriter.html#xmlNewTextWriterMemory">xmlNewTextWriterMemory</a> from xmlwriter.h</li><li> line 618: Function <a href="../html/libxml-xmlwriter.html#xmlNewTextWriterDoc">xmlNewTextWriterDoc</a> from xmlwriter.h</li><li> line 861: Type <a href="../html/libxml-xmlwriter.html#xmlTextWriterPtr">xmlTextWriterPtr</a> from xmlwriter.h</li><li> line 862: Type <a href="../html/libxml-tree.html#xmlDocPtr">xmlDocPtr</a> from tree.h</li><li> line 863: Type <a href="../html/libxml-tree.html#xmlNodePtr">xmlNodePtr</a> from tree.h</li><li> line 867: Macro <a href="../html/libxml-parser.html#XML_DEFAULT_VERSION">XML_DEFAULT_VERSION</a> from parser.h</li><li> line 867: Function <a href="../html/libxml-tree.html#xmlNewDoc">xmlNewDoc</a> from tree.h</li><li> line 876: Function <a href="../html/libxml-tree.html#xmlNewDocNode">xmlNewDocNode</a> from tree.h</li><li> line 883: Function <a href="../html/libxml-tree.html#xmlDocSetRootElement">xmlDocSetRootElement</a> from tree.h</li><li> line 886: Function <a href="../html/libxml-xmlwriter.html#xmlNewTextWriterTree">xmlNewTextWriterTree</a> from xmlwriter.h</li><li> line 895: Function <a href="../html/libxml-xmlwriter.html#xmlTextWriterStartDocument">xmlTextWriterStartDocument</a> from xmlwriter.h</li><li> line 905: Function <a href="../html/libxml-xmlwriter.html#xmlTextWriterWriteComment">xmlTextWriterWriteComment</a> from xmlwriter.h</li><li> line 931: Function <a href="../html/libxml-xmlwriter.html#xmlTextWriterWriteAttribute">xmlTextWriterWriteAttribute</a> from xmlwriter.h</li><li> line 940: Function <a href="../html/libxml-xmlwriter.html#xmlTextWriterWriteFormatComment">xmlTextWriterWriteFormatComment</a> from xmlwriter.h</li><li> line 1052: Function <a href="../html/libxml-xmlwriter.html#xmlTextWriterWriteFormatElement">xmlTextWriterWriteFormatElement</a> from xmlwriter.h</li><li> line 1075: Function <a href="../html/libxml-xmlwriter.html#xmlTextWriterStartElement">xmlTextWriterStartElement</a> from xmlwriter.h</li><li> line 1082: Function <a href="../html/libxml-xmlwriter.html#xmlTextWriterWriteElement">xmlTextWriterWriteElement</a> from xmlwriter.h</li><li> line 1090: Function <a href="../html/libxml-xmlwriter.html#xmlTextWriterEndElement">xmlTextWriterEndElement</a> from xmlwriter.h</li><li> line 1100: Function <a href="../html/libxml-xmlwriter.html#xmlTextWriterEndDocument">xmlTextWriterEndDocument</a> from xmlwriter.h</li><li> line 1106: Function <a href="../html/libxml-xmlwriter.html#xmlFreeTextWriter">xmlFreeTextWriter</a> from xmlwriter.h</li><li> line 1108: Function <a href="../html/libxml-tree.html#xmlSaveFileEnc">xmlSaveFileEnc</a> from tree.h</li><li> line 1110: Function <a href="../html/libxml-tree.html#xmlFreeDoc">xmlFreeDoc</a> from tree.h</li><li> line 1130: Type <a href="../html/libxml-encoding.html#xmlCharEncodingHandlerPtr">xmlCharEncodingHandlerPtr</a> from encoding.h</li><li> line 1135: 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/index.py b/doc/examples/index.py
index 1ae3a883..14ec306e 100755
--- a/doc/examples/index.py
+++ b/doc/examples/index.py
@@ -252,8 +252,10 @@ install-data-local:
Makefile = Makefile + "%s_SOURCES=%s.c\n%s_LDFLAGS=\n%s_DEPENDENCIES= $(DEPS)\n%s_LDADD= @RDL_LIBS@ $(LDADDS)\n\n" % (example, example, example,
example, example)
Makefile = Makefile + "tests: $(noinst_PROGRAMS)\n"
+ Makefile = Makefile + "\t@(echo > .memdump)\n"
for test in tests:
Makefile = Makefile + "\t@(%s)\n" % (test)
+ Makefile = Makefile + '\t@(grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0)\n'
Makefile = Makefile + "\n\n"
try:
old = open("Makefile.am", "r").read()
diff --git a/doc/examples/io1.c b/doc/examples/io1.c
new file mode 100644
index 00000000..b505f805
--- /dev/null
+++ b/doc/examples/io1.c
@@ -0,0 +1,154 @@
+/**
+ * section: InputOutput
+ * synopsis: Example of custom Input/Output
+ * purpose: 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.
+ * usage: io1
+ * test: io1 > io1.tmp ; diff io1.tmp io1.res ; rm -f io1.tmp
+ * author: Daniel Veillard
+ * copy: see Copyright for the status of this software.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <libxml/parser.h>
+#include <libxml/tree.h>
+#include <libxml/xinclude.h>
+#include <libxml/xmlIO.h>
+
+static const char *result = "<list><people>a</people><people>b</people></list>";
+static const char *cur = NULL;
+static int rlen;
+
+/**
+ * sqlMatch:
+ * @URI: an URI to test
+ *
+ * Check for an sql: query
+ *
+ * Returns 1 if yes and 0 if another Input module should be used
+ */
+static int
+sqlMatch(const char * URI) {
+ if ((URI != NULL) && (!strncmp(URI, "sql:", 4)))
+ return(1);
+ return(0);
+}
+
+/**
+ * sqlOpen:
+ * @URI: an URI to test
+ *
+ * Return a pointer to the sql: query handler, in this example simply
+ * the current pointer...
+ *
+ * Returns an Input context or NULL in case or error
+ */
+static void *
+sqlOpen(const char * URI) {
+ if ((URI == NULL) || (strncmp(URI, "sql:", 4)))
+ return(NULL);
+ cur = result;
+ rlen = strlen(result);
+ return((void *) cur);
+}
+
+/**
+ * sqlClose:
+ * @context: the read context
+ *
+ * Close the sql: query handler
+ *
+ * Returns 0 or -1 in case of error
+ */
+static int
+sqlClose(void * context) {
+ if (context == NULL) return(-1);
+ cur = NULL;
+ rlen = 0;
+ return(0);
+}
+
+/**
+ * sqlRead:
+ * @context: the read context
+ * @buffer: where to store data
+ * @len: number of bytes to read
+ *
+ * Implement an sql: query read.
+ *
+ * Returns the number of bytes read or -1 in case of error
+ */
+static int
+sqlRead(void * context, char * buffer, int len) {
+ const char *ptr = (const char *) context;
+
+ if ((context == NULL) || (buffer == NULL) || (len < 0))
+ return(-1);
+
+ if (len > rlen) len = rlen;
+ memcpy(buffer, ptr, len);
+ rlen -= len;
+ return(len);
+}
+
+const char *include = "<?xml version='1.0'?>\n\
+<document xmlns:xi=\"http://www.w3.org/2003/XInclude\">\n\
+ <p>List of people:</p>\n\
+ <xi:include href=\"sql:select_name_from_people\"/>\n\
+</document>\n";
+
+int main(void) {
+ xmlDocPtr doc;
+
+ /*
+ * 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
+
+ /*
+ * register the new I/O handlers
+ */
+ if (xmlRegisterInputCallbacks(sqlMatch, sqlOpen, sqlRead, sqlClose) < 0) {
+ fprintf(stderr, "failed to register SQL handler\n");
+ exit(1);
+ }
+ /*
+ * parse include into a document
+ */
+ doc = xmlReadMemory(include, strlen(include), "include.xml", NULL, 0);
+ if (doc == NULL) {
+ fprintf(stderr, "failed to parse the including file\n");
+ exit(1);
+ }
+ /*
+ * apply the XInclude process, this should trigger the I/O just
+ * registered.
+ */
+ if (xmlXIncludeProcess(doc) <= 0) {
+ fprintf(stderr, "XInclude processing failed\n");
+ exit(1);
+ }
+ /*
+ * save the output for checking to stdout
+ */
+ xmlDocDump(stdout, doc);
+ /*
+ * Free the document
+ */
+ xmlFreeDoc(doc);
+
+ /*
+ * Cleanup function for the XML library.
+ */
+ xmlCleanupParser();
+ /*
+ * this is to debug memory for regression tests
+ */
+ xmlMemoryDump();
+ return(0);
+}
diff --git a/doc/examples/io1.res b/doc/examples/io1.res
new file mode 100644
index 00000000..4a4c036a
--- /dev/null
+++ b/doc/examples/io1.res
@@ -0,0 +1,5 @@
+<?xml version="1.0"?>
+<document xmlns:xi="http://www.w3.org/2003/XInclude">
+ <p>List of people:</p>
+ <list><people>a</people><people>b</people></list>
+</document>
diff --git a/doc/examples/parse1.c b/doc/examples/parse1.c
index a21896f4..b44b03be 100644
--- a/doc/examples/parse1.c
+++ b/doc/examples/parse1.c
@@ -48,5 +48,9 @@ int main(int argc, char **argv) {
* Cleanup function for the XML library.
*/
xmlCleanupParser();
+ /*
+ * this is to debug memory for regression tests
+ */
+ xmlMemoryDump();
return(0);
}
diff --git a/doc/examples/parse2.c b/doc/examples/parse2.c
index aaedd4ac..aed76762 100644
--- a/doc/examples/parse2.c
+++ b/doc/examples/parse2.c
@@ -64,5 +64,9 @@ int main(int argc, char **argv) {
* Cleanup function for the XML library.
*/
xmlCleanupParser();
+ /*
+ * this is to debug memory for regression tests
+ */
+ xmlMemoryDump();
return(0);
}
diff --git a/doc/examples/reader1.c b/doc/examples/reader1.c
index 385f1d30..c030e0fa 100644
--- a/doc/examples/reader1.c
+++ b/doc/examples/reader1.c
@@ -88,5 +88,9 @@ int main(int argc, char **argv) {
* Cleanup function for the XML library.
*/
xmlCleanupParser();
+ /*
+ * this is to debug memory for regression tests
+ */
+ xmlMemoryDump();
return(0);
}
diff --git a/doc/examples/reader2.c b/doc/examples/reader2.c
index 784746a7..65c274de 100644
--- a/doc/examples/reader2.c
+++ b/doc/examples/reader2.c
@@ -103,5 +103,9 @@ int main(int argc, char **argv) {
* Cleanup function for the XML library.
*/
xmlCleanupParser();
+ /*
+ * this is to debug memory for regression tests
+ */
+ xmlMemoryDump();
return(0);
}
diff --git a/doc/examples/reader3.c b/doc/examples/reader3.c
index b68adaae..2ccb6ad1 100644
--- a/doc/examples/reader3.c
+++ b/doc/examples/reader3.c
@@ -100,5 +100,9 @@ int main(int argc, char **argv) {
* Cleanup function for the XML library.
*/
xmlCleanupParser();
+ /*
+ * this is to debug memory for regression tests
+ */
+ xmlMemoryDump();
return(0);
}
diff --git a/doc/examples/testWriter.c b/doc/examples/testWriter.c
index c5eaf837..c6bb41a9 100644
--- a/doc/examples/testWriter.c
+++ b/doc/examples/testWriter.c
@@ -27,6 +27,13 @@ xmlChar *ConvertInput(const char *in, const char *encoding);
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
+
/* first, the file version */
testXmlwriterFilename("writer1.res");
@@ -39,6 +46,14 @@ main(void)
/* next, the tree version */
testXmlwriterTree("writer4.res");
+ /*
+ * Cleanup function for the XML library.
+ */
+ xmlCleanupParser();
+ /*
+ * this is to debug memory for regression tests
+ */
+ xmlMemoryDump();
return 0;
}
@@ -53,6 +68,7 @@ testXmlwriterFilename(const char *uri)
{
int rc;
xmlTextWriterPtr writer;
+ xmlChar *tmp;
/* Create a new XmlWriter for uri, with no compression. */
writer = xmlNewTextWriterFilename(uri, 0);
@@ -84,15 +100,15 @@ testXmlwriterFilename(const char *uri)
* Please observe, that the input to the xmlTextWriter functions
* HAS to be in UTF-8, even if the output XML is encoded
* in iso-8859-1 */
- rc = xmlTextWriterWriteComment(writer,
- ConvertInput
- ("This is a comment with special chars: <äöü>",
- MY_ENCODING));
+ tmp = ConvertInput("This is a comment with special chars: <äöü>",
+ MY_ENCODING);
+ rc = xmlTextWriterWriteComment(writer, tmp);
if (rc < 0) {
printf
("testXmlwriterFilename: Error at xmlTextWriterWriteComment\n");
return;
}
+ if (tmp != NULL) xmlFree(tmp);
/* Start an element named "ORDER" as child of EXAMPLE. */
rc = xmlTextWriterStartElement(writer, BAD_CAST "ORDER");
@@ -121,15 +137,16 @@ testXmlwriterFilename(const char *uri)
}
/* Write a comment as child of ORDER */
+ tmp = ConvertInput("<äöü>", MY_ENCODING);
rc = xmlTextWriterWriteFormatComment(writer,
- "This is another comment with special chars: %s",
- ConvertInput("<äöü>",
- MY_ENCODING));
+ "This is another comment with special chars: %s",
+ tmp);
if (rc < 0) {
printf
("testXmlwriterFilename: Error at xmlTextWriterWriteFormatComment\n");
return;
}
+ if (tmp != NULL) xmlFree(tmp);
/* Start an element named "HEADER" as child of ORDER. */
rc = xmlTextWriterStartElement(writer, BAD_CAST "HEADER");
@@ -158,22 +175,24 @@ testXmlwriterFilename(const char *uri)
}
/* Write an element named "NAME_1" as child of HEADER. */
- rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_1",
- ConvertInput("Müller", MY_ENCODING));
+ tmp = ConvertInput("Müller", MY_ENCODING);
+ rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_1", tmp);
if (rc < 0) {
printf
("testXmlwriterFilename: Error at xmlTextWriterWriteElement\n");
return;
}
+ if (tmp != NULL) xmlFree(tmp);
/* Write an element named "NAME_2" as child of HEADER. */
- rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_2",
- ConvertInput("Jörg", MY_ENCODING));
+ tmp = ConvertInput("Jörg", MY_ENCODING);
+ rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_2", tmp);
if (rc < 0) {
printf
("testXmlwriterFilename: Error at xmlTextWriterWriteElement\n");
return;
}
+ if (tmp != NULL) xmlFree(tmp);
/* Close the element named HEADER. */
rc = xmlTextWriterEndElement(writer);
@@ -318,6 +337,7 @@ testXmlwriterMemory(const char *file)
int rc;
xmlTextWriterPtr writer;
xmlBufferPtr buf;
+ xmlChar *tmp;
FILE *fp;
/* Create a new XML buffer, to which the XML document will be
@@ -359,15 +379,15 @@ testXmlwriterMemory(const char *file)
* Please observe, that the input to the xmlTextWriter functions
* HAS to be in UTF-8, even if the output XML is encoded
* in iso-8859-1 */
- rc = xmlTextWriterWriteComment(writer,
- ConvertInput
- ("This is a comment with special chars: <äöü>",
- MY_ENCODING));
+ tmp = ConvertInput("This is a comment with special chars: <äöü>",
+ MY_ENCODING);
+ rc = xmlTextWriterWriteComment(writer, tmp);
if (rc < 0) {
printf
("testXmlwriterMemory: Error at xmlTextWriterWriteComment\n");
return;
}
+ if (tmp != NULL) xmlFree(tmp);
/* Start an element named "ORDER" as child of EXAMPLE. */
rc = xmlTextWriterStartElement(writer, BAD_CAST "ORDER");
@@ -396,15 +416,16 @@ testXmlwriterMemory(const char *file)
}
/* Write a comment as child of ORDER */
+ tmp = ConvertInput("<äöü>", MY_ENCODING);
rc = xmlTextWriterWriteFormatComment(writer,
- "This is another comment with special chars: %s",
- ConvertInput("<äöü>",
- MY_ENCODING));
+ "This is another comment with special chars: %s",
+ tmp);
if (rc < 0) {
printf
("testXmlwriterMemory: Error at xmlTextWriterWriteFormatComment\n");
return;
}
+ if (tmp != NULL) xmlFree(tmp);
/* Start an element named "HEADER" as child of ORDER. */
rc = xmlTextWriterStartElement(writer, BAD_CAST "HEADER");
@@ -433,22 +454,25 @@ testXmlwriterMemory(const char *file)
}
/* Write an element named "NAME_1" as child of HEADER. */
- rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_1",
- ConvertInput("Müller", MY_ENCODING));
+ tmp = ConvertInput("Müller", MY_ENCODING);
+ rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_1", tmp);
if (rc < 0) {
printf
("testXmlwriterMemory: Error at xmlTextWriterWriteElement\n");
return;
}
+ if (tmp != NULL) xmlFree(tmp);
/* Write an element named "NAME_2" as child of HEADER. */
- rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_2",
- ConvertInput("Jörg", MY_ENCODING));
+ tmp = ConvertInput("Jörg", MY_ENCODING);
+ rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_2", tmp);
+
if (rc < 0) {
printf
("testXmlwriterMemory: Error at xmlTextWriterWriteElement\n");
return;
}
+ if (tmp != NULL) xmlFree(tmp);
/* Close the element named HEADER. */
rc = xmlTextWriterEndElement(writer);
@@ -583,6 +607,8 @@ testXmlwriterMemory(const char *file)
fprintf(fp, "%s", (const char *) buf->content);
fclose(fp);
+
+ xmlBufferFree(buf);
}
/**
@@ -596,6 +622,7 @@ testXmlwriterDoc(const char *file)
{
int rc;
xmlTextWriterPtr writer;
+ xmlChar *tmp;
xmlDocPtr doc;
@@ -627,14 +654,14 @@ testXmlwriterDoc(const char *file)
* Please observe, that the input to the xmlTextWriter functions
* HAS to be in UTF-8, even if the output XML is encoded
* in iso-8859-1 */
- rc = xmlTextWriterWriteComment(writer,
- ConvertInput
- ("This is a comment with special chars: <äöü>",
- MY_ENCODING));
+ tmp = ConvertInput("This is a comment with special chars: <äöü>",
+ MY_ENCODING);
+ rc = xmlTextWriterWriteComment(writer, tmp);
if (rc < 0) {
printf("testXmlwriterDoc: Error at xmlTextWriterWriteComment\n");
return;
}
+ if (tmp != NULL) xmlFree(tmp);
/* Start an element named "ORDER" as child of EXAMPLE. */
rc = xmlTextWriterStartElement(writer, BAD_CAST "ORDER");
@@ -660,15 +687,16 @@ testXmlwriterDoc(const char *file)
}
/* Write a comment as child of ORDER */
+ tmp = ConvertInput("<äöü>", MY_ENCODING);
rc = xmlTextWriterWriteFormatComment(writer,
- "This is another comment with special chars: %s",
- ConvertInput("<äöü>",
- MY_ENCODING));
+ "This is another comment with special chars: %s",
+ tmp);
if (rc < 0) {
printf
("testXmlwriterDoc: Error at xmlTextWriterWriteFormatComment\n");
return;
}
+ if (tmp != NULL) xmlFree(tmp);
/* Start an element named "HEADER" as child of ORDER. */
rc = xmlTextWriterStartElement(writer, BAD_CAST "HEADER");
@@ -696,20 +724,22 @@ testXmlwriterDoc(const char *file)
}
/* Write an element named "NAME_1" as child of HEADER. */
- rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_1",
- ConvertInput("Müller", MY_ENCODING));
+ tmp = ConvertInput("Müller", MY_ENCODING);
+ rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_1", tmp);
if (rc < 0) {
printf("testXmlwriterDoc: Error at xmlTextWriterWriteElement\n");
return;
}
+ if (tmp != NULL) xmlFree(tmp);
/* Write an element named "NAME_2" as child of HEADER. */
- rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_2",
- ConvertInput("Jörg", MY_ENCODING));
+ tmp = ConvertInput("Jörg", MY_ENCODING);
+ rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_2", tmp);
if (rc < 0) {
printf("testXmlwriterDoc: Error at xmlTextWriterWriteElement\n");
return;
}
+ if (tmp != NULL) xmlFree(tmp);
/* Close the element named HEADER. */
rc = xmlTextWriterEndElement(writer);
@@ -846,6 +876,7 @@ testXmlwriterTree(const char *file)
xmlTextWriterPtr writer;
xmlDocPtr doc;
xmlNodePtr node;
+ xmlChar *tmp;
/* Create a new XML DOM tree, to which the XML document will be
* written */
@@ -887,14 +918,14 @@ testXmlwriterTree(const char *file)
* Please observe, that the input to the xmlTextWriter functions
* HAS to be in UTF-8, even if the output XML is encoded
* in iso-8859-1 */
- rc = xmlTextWriterWriteComment(writer,
- ConvertInput
- ("This is a comment with special chars: <äöü>",
- MY_ENCODING));
+ tmp = ConvertInput("This is a comment with special chars: <äöü>",
+ MY_ENCODING);
+ rc = xmlTextWriterWriteComment(writer, tmp);
if (rc < 0) {
printf("testXmlwriterTree: Error at xmlTextWriterWriteComment\n");
return;
}
+ if (tmp != NULL) xmlFree(tmp);
/* Start an element named "ORDER" as child of EXAMPLE. */
rc = xmlTextWriterStartElement(writer, BAD_CAST "ORDER");
@@ -922,15 +953,16 @@ testXmlwriterTree(const char *file)
}
/* Write a comment as child of ORDER */
+ tmp = ConvertInput("<äöü>", MY_ENCODING);
rc = xmlTextWriterWriteFormatComment(writer,
- "This is another comment with special chars: %s",
- ConvertInput("<äöü>",
- MY_ENCODING));
+ "This is another comment with special chars: %s",
+ tmp);
if (rc < 0) {
printf
("testXmlwriterTree: Error at xmlTextWriterWriteFormatComment\n");
return;
}
+ if (tmp != NULL) xmlFree(tmp);
/* Start an element named "HEADER" as child of ORDER. */
rc = xmlTextWriterStartElement(writer, BAD_CAST "HEADER");
@@ -958,20 +990,22 @@ testXmlwriterTree(const char *file)
}
/* Write an element named "NAME_1" as child of HEADER. */
- rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_1",
- ConvertInput("Müller", MY_ENCODING));
+ tmp = ConvertInput("Müller", MY_ENCODING);
+ rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_1", tmp);
if (rc < 0) {
printf("testXmlwriterTree: Error at xmlTextWriterWriteElement\n");
return;
}
+ if (tmp != NULL) xmlFree(tmp);
/* Write an element named "NAME_2" as child of HEADER. */
- rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_2",
- ConvertInput("Jörg", MY_ENCODING));
+ tmp = ConvertInput("Jörg", MY_ENCODING);
+ rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_2", tmp);
if (rc < 0) {
printf("testXmlwriterTree: Error at xmlTextWriterWriteElement\n");
return;
}
+ if (tmp != NULL) xmlFree(tmp);
/* Close the element named HEADER. */
rc = xmlTextWriterEndElement(writer);
diff --git a/doc/examples/tree2.c b/doc/examples/tree2.c
index 124898ee..196ffb4d 100644
--- a/doc/examples/tree2.c
+++ b/doc/examples/tree2.c
@@ -102,5 +102,9 @@ main(int argc, char **argv)
*/
xmlCleanupParser();
+ /*
+ * this is to debug memory for regression tests
+ */
+ xmlMemoryDump();
return(0);
}
diff --git a/doc/examples/xpath1.c b/doc/examples/xpath1.c
index f6e939bb..2629c3d3 100644
--- a/doc/examples/xpath1.c
+++ b/doc/examples/xpath1.c
@@ -44,6 +44,10 @@ main(int argc, char **argv) {
/* Shutdown libxml */
xmlCleanupParser();
+ /*
+ * this is to debug memory for regression tests
+ */
+ xmlMemoryDump();
return 0;
}