mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2024-12-28 07:21:26 +03:00
added a test template added a new example, and make valgrind target Daniel
* doc/examples/xpath1.c: added a test template * doc/examples/xpath2.c doc/examples/xpath2.res doc/examples/*: added a new example, and make valgrind target Daniel
This commit is contained in:
parent
688f6694cb
commit
b5eb714320
@ -1,3 +1,9 @@
|
||||
Fri Mar 26 14:53:58 CET 2004 Daniel Veillard <daniel@veillard.com>
|
||||
|
||||
* doc/examples/xpath1.c: added a test template
|
||||
* doc/examples/xpath2.c doc/examples/xpath2.res doc/examples/*:
|
||||
added a new example, and make valgrind target
|
||||
|
||||
Fri Mar 26 11:47:29 CET 2004 Daniel Veillard <daniel@veillard.com>
|
||||
|
||||
* parser.c: apply fix for #136693
|
||||
|
9
NEWS
9
NEWS
@ -4,17 +4,12 @@
|
||||
Note that this is automatically generated from the news webpage at:
|
||||
http://xmlsoft.org/news.html
|
||||
|
||||
|
||||
CVS only : check the Changelog at
|
||||
http://cvs.gnome.org/lxr/source/gnome-xml/ChangeLog
|
||||
file
|
||||
for a really accurate description:
|
||||
Items not finished and worked on, get in touch with the list if you want
|
||||
to test those - More testing on RelaxNG
|
||||
to help those - More testing on RelaxNG
|
||||
- Finishing up XML
|
||||
Schemas
|
||||
|
||||
|
||||
There is the list of public releases:
|
||||
2.6.8: Mar 23 2004:
|
||||
- First step of the cleanup of the serialization code and APIs
|
||||
- XML Schemas: mixed content (Adam Dickmeiss), QName handling fixes (Adam
|
||||
|
@ -13,3 +13,5 @@ reader3
|
||||
io1
|
||||
parse3
|
||||
parse4
|
||||
io2
|
||||
xpath2
|
||||
|
@ -15,9 +15,9 @@ install-data-local:
|
||||
$(mkinstalldirs) $(DESTDIR)$(HTML_DIR)
|
||||
-@INSTALL@ -m 0644 $(srcdir)/*.html $(srcdir)/*.c $(srcdir)/*.xml $(srcdir)/*.xsl $(srcdir)/*.res $(DESTDIR)$(HTML_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 io1.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 io2.res xpath1.res xpath2.res
|
||||
|
||||
noinst_PROGRAMS=xpath1 parse1 parse2 tree1 tree2 testWriter reader1 reader2 reader3 io1 parse3 parse4
|
||||
noinst_PROGRAMS=xpath1 parse1 parse2 tree1 tree2 testWriter reader1 reader2 reader3 io1 parse3 parse4 io2 xpath2
|
||||
|
||||
xpath1_SOURCES=xpath1.c
|
||||
xpath1_LDFLAGS=
|
||||
@ -79,29 +79,48 @@ parse4_LDFLAGS=
|
||||
parse4_DEPENDENCIES= $(DEPS)
|
||||
parse4_LDADD= @RDL_LIBS@ $(LDADDS)
|
||||
|
||||
io2_SOURCES=io2.c
|
||||
io2_LDFLAGS=
|
||||
io2_DEPENDENCIES= $(DEPS)
|
||||
io2_LDADD= @RDL_LIBS@ $(LDADDS)
|
||||
|
||||
xpath2_SOURCES=xpath2.c
|
||||
xpath2_LDFLAGS=
|
||||
xpath2_DEPENDENCIES= $(DEPS)
|
||||
xpath2_LDADD= @RDL_LIBS@ $(LDADDS)
|
||||
|
||||
valgrind:
|
||||
$(MAKE) CHECKER='valgrind -q' tests
|
||||
|
||||
tests: $(noinst_PROGRAMS)
|
||||
@(echo > .memdump)
|
||||
@(./parse1 test1.xml)
|
||||
@($(CHECKER) ././xpath1 test3.xml '//child2' > xpath1.tmp ; diff xpath1.tmp xpath1.res ; rm xpath1.tmp)
|
||||
@(grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0)
|
||||
@(./parse2 test2.xml)
|
||||
@($(CHECKER) ./parse1 test1.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)
|
||||
@($(CHECKER) ./parse2 test2.xml)
|
||||
@(grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0)
|
||||
@(./tree2 > tree2.tmp ; diff tree2.tmp tree2.res ; rm tree2.tmp)
|
||||
@($(CHECKER) ./tree1 test2.xml > tree1.tmp ; diff tree1.tmp tree1.res ; rm tree1.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)
|
||||
@($(CHECKER) ./tree2 > tree2.tmp ; diff tree2.tmp tree2.res ; rm tree2.tmp)
|
||||
@(grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0)
|
||||
@(./reader1 test2.xml > reader1.tmp ; diff reader1.tmp reader1.res ; rm reader1.tmp)
|
||||
@($(CHECKER) ./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)
|
||||
@(./reader2 test2.xml > reader1.tmp ; diff reader1.tmp reader1.res ; rm reader1.tmp)
|
||||
@($(CHECKER) ./reader1 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)
|
||||
@($(CHECKER) ./reader2 test2.xml > reader1.tmp ; diff reader1.tmp reader1.res ; rm reader1.tmp)
|
||||
@(grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0)
|
||||
@(./io1 > io1.tmp ; diff io1.tmp io1.res ; rm -f io1.tmp)
|
||||
@($(CHECKER) ./reader3 > reader3.tmp ; diff reader3.tmp reader3.res ; rm reader3.tmp)
|
||||
@(grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0)
|
||||
@(./parse3)
|
||||
@($(CHECKER) ./io1 > io1.tmp ; diff io1.tmp io1.res ; rm -f io1.tmp)
|
||||
@(grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0)
|
||||
@(./parse4 test3.xml)
|
||||
@($(CHECKER) ./parse3)
|
||||
@(grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0)
|
||||
@($(CHECKER) ./parse4 test3.xml)
|
||||
@(grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0)
|
||||
@($(CHECKER) ./io2 > io2.tmp ; diff io2.tmp io2.res ; rm -f io2.tmp)
|
||||
@(grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0)
|
||||
@($(CHECKER) ./xpath2 test3.xml '//child2' child2 > xpath2.tmp ; diff xpath2.tmp xpath2.res ; rm xpath2.tmp)
|
||||
@(grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0)
|
||||
|
||||
|
||||
|
@ -1,28 +1,40 @@
|
||||
<examples>
|
||||
<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 > io1.tmp ; diff io1.tmp io1.res ; rm -f io1.tmp</test>
|
||||
<author>Daniel Veillard</author>
|
||||
<example filename='xpath1.c'>
|
||||
<synopsis>Evaluate XPath expression and prints result node set.</synopsis>
|
||||
<purpose>Shows how to evaluate XPath expression and register known namespaces in XPath context.</purpose>
|
||||
<usage>xpath1 <xml-file> <xpath-expr> [<known-ns-list>]</usage>
|
||||
<test>./xpath1 test3.xml '//child2' > xpath1.tmp ; diff xpath1.tmp xpath1.res ; rm xpath1.tmp</test>
|
||||
<author>Aleksey Sanin</author>
|
||||
<copy>see Copyright for the status of this software. </copy>
|
||||
<section>InputOutput</section>
|
||||
<section>XPath</section>
|
||||
<includes>
|
||||
<include><libxml/xpath.h></include>
|
||||
<include><libxml/parser.h></include>
|
||||
<include><libxml/xinclude.h></include>
|
||||
<include><libxml/xpathInternals.h></include>
|
||||
<include><libxml/tree.h></include>
|
||||
<include><libxml/xmlIO.h></include>
|
||||
</includes>
|
||||
<uses>
|
||||
<function line='154' file='parser' name='xmlCleanupParser'/>
|
||||
<macro line='117' file='xmlversion' name='LIBXML_TEST_VERSION'/>
|
||||
<function line='143' file='tree' name='xmlDocDump'/>
|
||||
<function line='158' file='xmlmemory' name='xmlMemoryDump'/>
|
||||
<function line='149' file='tree' name='xmlFreeDoc'/>
|
||||
<function line='134' file='xinclude' name='xmlXIncludeProcess'/>
|
||||
<function line='117' file='xmlIO' name='xmlRegisterInputCallbacks'/>
|
||||
<function line='124' file='parser' name='xmlReadMemory'/>
|
||||
<typedef line='105' file='tree' name='xmlDocPtr'/>
|
||||
<enum line='229' file='tree' name='XML_ELEMENT_NODE'/>
|
||||
<typedef line='88' file='xpath' name='xmlXPathObjectPtr'/>
|
||||
<function line='54' file='xmlmemory' name='xmlMemoryDump'/>
|
||||
<function line='117' file='xpath' name='xmlXPathEvalExpression'/>
|
||||
<function line='186' file='xpathInternals' name='xmlXPathRegisterNs'/>
|
||||
<function line='129' file='xpath' name='xmlXPathFreeObject'/>
|
||||
<typedef line='86' file='tree' name='xmlDocPtr'/>
|
||||
<typedef line='218' file='tree' name='xmlNsPtr'/>
|
||||
<function line='101' file='xpath' name='xmlXPathNewContext'/>
|
||||
<typedef line='206' file='tree' name='xmlNodePtr'/>
|
||||
<function line='49' file='parser' name='xmlCleanupParser'/>
|
||||
<macro line='43' file='xmlversion' name='LIBXML_TEST_VERSION'/>
|
||||
<typedef line='87' file='xpath' name='xmlXPathContextPtr'/>
|
||||
<function line='130' file='xpath' name='xmlXPathFreeContext'/>
|
||||
<function line='39' file='parser' name='xmlInitParser'/>
|
||||
<function line='156' file='xmlstring' name='xmlStrdup'/>
|
||||
<function line='131' file='tree' name='xmlFreeDoc'/>
|
||||
<function line='180' file='xmlstring' name='xmlStrchr'/>
|
||||
<variable line='193' file='globals' name='xmlFree'/>
|
||||
<function line='94' file='parser' name='xmlParseFile'/>
|
||||
<enum line='217' file='tree' name='XML_NAMESPACE_DECL'/>
|
||||
</uses>
|
||||
</example>
|
||||
<example filename='parse1.c'>
|
||||
@ -71,90 +83,53 @@
|
||||
<function line='70' file='xmlmemory' name='xmlMemoryDump'/>
|
||||
</uses>
|
||||
</example>
|
||||
<example filename='reader1.c'>
|
||||
<synopsis>Parse an XML file with an xmlReader</synopsis>
|
||||
<purpose>Demonstrate the use of xmlReaderForFile() to parse an XML file and dump the informations about the nodes found in the process. (Note that the XMLReader functions require libxml2 version later than 2.6.)</purpose>
|
||||
<usage>reader1 <filename></usage>
|
||||
<test>reader1 test2.xml > reader1.tmp ; diff reader1.tmp reader1.res ; rm reader1.tmp</test>
|
||||
<author>Daniel Veillard</author>
|
||||
<example filename='tree1.c'>
|
||||
<synopsis>Navigates a tree to print element names</synopsis>
|
||||
<purpose>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.</purpose>
|
||||
<usage>tree1 filename_or_URL</usage>
|
||||
<test>tree1 test2.xml > tree1.tmp ; diff tree1.tmp tree1.res ; rm tree1.tmp</test>
|
||||
<author>Dodji Seketeli</author>
|
||||
<copy>see Copyright for the status of this software. </copy>
|
||||
<section>xmlReader</section>
|
||||
<section>Tree</section>
|
||||
<includes>
|
||||
<include><libxml/xmlreader.h></include>
|
||||
<include><libxml/tree.h></include>
|
||||
<include><libxml/parser.h></include>
|
||||
</includes>
|
||||
<uses>
|
||||
<function line='44' file='xmlstring' name='xmlStrlen'/>
|
||||
<function line='94' file='parser' name='xmlCleanupParser'/>
|
||||
<function line='37' file='xmlreader' name='xmlTextReaderNodeType'/>
|
||||
<typedef line='59' file='xmlreader' name='xmlTextReaderPtr'/>
|
||||
<function line='98' file='xmlmemory' name='xmlMemoryDump'/>
|
||||
<function line='33' file='xmlreader' name='xmlTextReaderConstValue'/>
|
||||
<function line='36' file='xmlreader' name='xmlTextReaderDepth'/>
|
||||
<function line='69' file='xmlreader' name='xmlFreeTextReader'/>
|
||||
<macro line='89' file='xmlversion' name='LIBXML_TEST_VERSION'/>
|
||||
<function line='29' file='xmlreader' name='xmlTextReaderConstName'/>
|
||||
<function line='40' file='xmlreader' name='xmlTextReaderHasValue'/>
|
||||
<function line='67' file='xmlreader' name='xmlTextReaderRead'/>
|
||||
<function line='39' file='xmlreader' name='xmlTextReaderIsEmptyElement'/>
|
||||
<function line='62' file='xmlreader' name='xmlReaderForFile'/>
|
||||
<function line='85' file='parser' name='xmlCleanupParser'/>
|
||||
<macro line='67' file='xmlversion' name='LIBXML_TEST_VERSION'/>
|
||||
<enum line='36' file='tree' name='XML_ELEMENT_NODE'/>
|
||||
<function line='79' file='tree' name='xmlFreeDoc'/>
|
||||
<function line='67' file='parser' name='xmlParseFile'/>
|
||||
<function line='74' file='tree' name='xmlDocGetRootElement'/>
|
||||
</uses>
|
||||
</example>
|
||||
<example filename='reader2.c'>
|
||||
<synopsis>Parse and validate an XML file with an xmlReader</synopsis>
|
||||
<purpose>Demonstrate the use of xmlReaderForFile() to parse an XML file validating the content in the process and activating options like entities substitution, and DTD attributes defaulting. (Note that the XMLReader functions require libxml2 version later than 2.6.)</purpose>
|
||||
<usage>reader2 <valid_xml_filename></usage>
|
||||
<test>reader2 test2.xml > reader1.tmp ; diff reader1.tmp reader1.res ; rm reader1.tmp</test>
|
||||
<author>Daniel Veillard</author>
|
||||
<copy>see Copyright for the status of this software. </copy>
|
||||
<section>xmlReader</section>
|
||||
<example filename='tree2.c'>
|
||||
<synopsis>Creates a tree</synopsis>
|
||||
<purpose>Shows how to create document, nodes and dump it to stdout or file.</purpose>
|
||||
<usage>tree2 <filename> -Default output: stdout</usage>
|
||||
<test>tree2 > tree2.tmp ; diff tree2.tmp tree2.res ; rm tree2.tmp</test>
|
||||
<author>Lucas Brasilino <brasilino@recife.pe.gov.br></author>
|
||||
<copy>see Copyright for the status of this software </copy>
|
||||
<section>Tree</section>
|
||||
<includes>
|
||||
<include><libxml/xmlreader.h></include>
|
||||
<include><libxml/tree.h></include>
|
||||
<include><libxml/parser.h></include>
|
||||
</includes>
|
||||
<uses>
|
||||
<function line='45' file='xmlstring' name='xmlStrlen'/>
|
||||
<function line='109' file='parser' name='xmlCleanupParser'/>
|
||||
<function line='38' file='xmlreader' name='xmlTextReaderNodeType'/>
|
||||
<typedef line='60' file='xmlreader' name='xmlTextReaderPtr'/>
|
||||
<function line='113' file='xmlmemory' name='xmlMemoryDump'/>
|
||||
<function line='34' file='xmlreader' name='xmlTextReaderConstValue'/>
|
||||
<enum line='70' file='parser' name='XML_PARSE_NOENT'/>
|
||||
<function line='37' file='xmlreader' name='xmlTextReaderDepth'/>
|
||||
<enum line='71' file='parser' name='XML_PARSE_DTDVALID'/>
|
||||
<enum line='69' file='parser' name='XML_PARSE_DTDATTR'/>
|
||||
<function line='84' file='xmlreader' name='xmlFreeTextReader'/>
|
||||
<macro line='104' file='xmlversion' name='LIBXML_TEST_VERSION'/>
|
||||
<function line='30' file='xmlreader' name='xmlTextReaderConstName'/>
|
||||
<function line='41' file='xmlreader' name='xmlTextReaderHasValue'/>
|
||||
<function line='76' file='xmlreader' name='xmlTextReaderRead'/>
|
||||
<function line='40' file='xmlreader' name='xmlTextReaderIsEmptyElement'/>
|
||||
<function line='68' file='xmlreader' name='xmlReaderForFile'/>
|
||||
<function line='81' file='xmlreader' name='xmlTextReaderIsValid'/>
|
||||
</uses>
|
||||
</example>
|
||||
<example filename='reader3.c'>
|
||||
<synopsis>Show how to extract subdocuments with xmlReader</synopsis>
|
||||
<purpose>Demonstrate the use of xmlTextReaderPreservePattern() to parse an XML file with the xmlReader while collecting only some subparts of the document. (Note that the XMLReader functions require libxml2 version later than 2.6.)</purpose>
|
||||
<usage>reader3</usage>
|
||||
<test>reader3 > reader3.tmp ; diff reader3.tmp reader3.res ; rm reader3.tmp</test>
|
||||
<author>Daniel Veillard</author>
|
||||
<copy>see Copyright for the status of this software. </copy>
|
||||
<section>xmlReader</section>
|
||||
<includes>
|
||||
<include><libxml/xmlreader.h></include>
|
||||
</includes>
|
||||
<uses>
|
||||
<function line='106' file='parser' name='xmlCleanupParser'/>
|
||||
<typedef line='31' file='xmlreader' name='xmlTextReaderPtr'/>
|
||||
<function line='75' file='tree' name='xmlNewText'/>
|
||||
<function line='110' file='xmlmemory' name='xmlMemoryDump'/>
|
||||
<function line='96' file='tree' name='xmlSaveFormatFileEnc'/>
|
||||
<function line='78' file='tree' name='xmlAddChild'/>
|
||||
<function line='41' file='tree' name='xmlDocSetRootElement'/>
|
||||
<function line='105' file='parser' name='xmlCleanupParser'/>
|
||||
<macro line='34' file='xmlversion' name='LIBXML_TEST_VERSION'/>
|
||||
<function line='89' file='tree' name='xmlNewProp'/>
|
||||
<function line='88' file='tree' name='xmlNewChild'/>
|
||||
<function line='74' file='tree' name='xmlNewNode'/>
|
||||
<function line='46' file='tree' name='xmlCreateIntSubset'/>
|
||||
<function line='99' file='tree' name='xmlFreeDoc'/>
|
||||
<function line='37' file='xmlreader' name='xmlReaderForFile'/>
|
||||
<function line='65' file='xmlreader' name='xmlFreeTextReader'/>
|
||||
<macro line='90' file='xmlversion' name='LIBXML_TEST_VERSION'/>
|
||||
<function line='95' file='tree' name='xmlDocDump'/>
|
||||
<function line='51' file='xmlreader' name='xmlTextReaderRead'/>
|
||||
<function line='61' file='xmlreader' name='xmlTextReaderCurrentDoc'/>
|
||||
<function line='42' file='xmlreader' name='xmlTextReaderPreservePattern'/>
|
||||
<typedef line='76' file='tree' name='xmlDocPtr'/>
|
||||
<function line='39' file='tree' name='xmlNewDoc'/>
|
||||
</uses>
|
||||
</example>
|
||||
<example filename='testWriter.c'>
|
||||
@ -176,6 +151,7 @@
|
||||
<function line='1121' file='xmlwriter' name='xmlTextWriterEndDocument'/>
|
||||
<function line='959' file='xmlwriter' name='xmlTextWriterWriteFormatComment'/>
|
||||
<function line='925' file='xmlwriter' name='xmlTextWriterWriteComment'/>
|
||||
<function line='54' file='parser' name='xmlCleanupParser'/>
|
||||
<variable line='1166' file='globals' name='xmlMalloc'/>
|
||||
<function line='1073' file='xmlwriter' name='xmlTextWriterWriteFormatElement'/>
|
||||
<function line='1156' file='encoding' name='xmlFindCharEncodingHandler'/>
|
||||
@ -189,12 +165,14 @@
|
||||
<function line='632' file='xmlwriter' name='xmlNewTextWriterDoc'/>
|
||||
<function line='894' file='tree' name='xmlNewDocNode'/>
|
||||
<function line='1129' file='tree' name='xmlSaveFileEnc'/>
|
||||
<function line='58' file='xmlmemory' name='xmlMemoryDump'/>
|
||||
<macro line='885' file='parser' name='XML_DEFAULT_VERSION'/>
|
||||
<function line='355' file='xmlwriter' name='xmlNewTextWriterMemory'/>
|
||||
<variable line='1180' file='globals' name='xmlFree'/>
|
||||
<function line='1096' file='xmlwriter' name='xmlTextWriterStartElement'/>
|
||||
<function line='1127' file='xmlwriter' name='xmlFreeTextWriter'/>
|
||||
<function line='347' file='tree' name='xmlBufferCreate'/>
|
||||
<macro line='40' file='xmlversion' name='LIBXML_TEST_VERSION'/>
|
||||
<function line='613' file='tree' name='xmlBufferFree'/>
|
||||
<typedef line='878' file='xmlwriter' name='xmlTextWriterPtr'/>
|
||||
<function line='1103' file='xmlwriter' name='xmlTextWriterWriteElement'/>
|
||||
@ -203,80 +181,103 @@
|
||||
<function line='885' file='tree' name='xmlNewDoc'/>
|
||||
</uses>
|
||||
</example>
|
||||
<example filename='tree1.c'>
|
||||
<synopsis>Navigates a tree to print element names</synopsis>
|
||||
<purpose>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.</purpose>
|
||||
<usage>tree1 filename_or_URL</usage>
|
||||
<test>tree1 test2.xml > tree1.tmp ; diff tree1.tmp tree1.res ; rm tree1.tmp</test>
|
||||
<author>Dodji Seketeli</author>
|
||||
<example filename='reader1.c'>
|
||||
<synopsis>Parse an XML file with an xmlReader</synopsis>
|
||||
<purpose>Demonstrate the use of xmlReaderForFile() to parse an XML file and dump the informations about the nodes found in the process. (Note that the XMLReader functions require libxml2 version later than 2.6.)</purpose>
|
||||
<usage>reader1 <filename></usage>
|
||||
<test>reader1 test2.xml > reader1.tmp ; diff reader1.tmp reader1.res ; rm reader1.tmp</test>
|
||||
<author>Daniel Veillard</author>
|
||||
<copy>see Copyright for the status of this software. </copy>
|
||||
<section>Tree</section>
|
||||
<section>xmlReader</section>
|
||||
<includes>
|
||||
<include><libxml/tree.h></include>
|
||||
<include><libxml/parser.h></include>
|
||||
<include><libxml/xmlreader.h></include>
|
||||
</includes>
|
||||
<uses>
|
||||
<enum line='36' file='tree' name='XML_ELEMENT_NODE'/>
|
||||
<function line='79' file='tree' name='xmlFreeDoc'/>
|
||||
<function line='67' file='parser' name='xmlParseFile'/>
|
||||
<function line='74' file='tree' name='xmlDocGetRootElement'/>
|
||||
<function line='44' file='xmlstring' name='xmlStrlen'/>
|
||||
<function line='37' file='xmlreader' name='xmlTextReaderNodeType'/>
|
||||
<typedef line='59' file='xmlreader' name='xmlTextReaderPtr'/>
|
||||
<function line='98' file='xmlmemory' name='xmlMemoryDump'/>
|
||||
<function line='33' file='xmlreader' name='xmlTextReaderConstValue'/>
|
||||
<function line='36' file='xmlreader' name='xmlTextReaderDepth'/>
|
||||
<function line='69' file='xmlreader' name='xmlFreeTextReader'/>
|
||||
<function line='29' file='xmlreader' name='xmlTextReaderConstName'/>
|
||||
<function line='40' file='xmlreader' name='xmlTextReaderHasValue'/>
|
||||
<function line='67' file='xmlreader' name='xmlTextReaderRead'/>
|
||||
<function line='39' file='xmlreader' name='xmlTextReaderIsEmptyElement'/>
|
||||
<function line='62' file='xmlreader' name='xmlReaderForFile'/>
|
||||
</uses>
|
||||
</example>
|
||||
<example filename='tree2.c'>
|
||||
<synopsis>Creates a tree</synopsis>
|
||||
<purpose>Shows how to create document, nodes and dump it to stdout or file.</purpose>
|
||||
<usage>tree2 <filename> -Default output: stdout</usage>
|
||||
<test>tree2 > tree2.tmp ; diff tree2.tmp tree2.res ; rm tree2.tmp</test>
|
||||
<author>Lucas Brasilino <brasilino@recife.pe.gov.br></author>
|
||||
<copy>see Copyright for the status of this software </copy>
|
||||
<section>Tree</section>
|
||||
<example filename='reader2.c'>
|
||||
<synopsis>Parse and validate an XML file with an xmlReader</synopsis>
|
||||
<purpose>Demonstrate the use of xmlReaderForFile() to parse an XML file validating the content in the process and activating options like entities substitution, and DTD attributes defaulting. (Note that the XMLReader functions require libxml2 version later than 2.6.)</purpose>
|
||||
<usage>reader2 <valid_xml_filename></usage>
|
||||
<test>reader2 test2.xml > reader1.tmp ; diff reader1.tmp reader1.res ; rm reader1.tmp</test>
|
||||
<author>Daniel Veillard</author>
|
||||
<copy>see Copyright for the status of this software. </copy>
|
||||
<section>xmlReader</section>
|
||||
<includes>
|
||||
<include><libxml/tree.h></include>
|
||||
<include><libxml/parser.h></include>
|
||||
<include><libxml/xmlreader.h></include>
|
||||
</includes>
|
||||
<uses>
|
||||
<function line='75' file='tree' name='xmlNewText'/>
|
||||
<function line='96' file='tree' name='xmlSaveFormatFileEnc'/>
|
||||
<function line='78' file='tree' name='xmlAddChild'/>
|
||||
<function line='41' file='tree' name='xmlDocSetRootElement'/>
|
||||
<function line='89' file='tree' name='xmlNewProp'/>
|
||||
<function line='88' file='tree' name='xmlNewChild'/>
|
||||
<function line='74' file='tree' name='xmlNewNode'/>
|
||||
<function line='46' file='tree' name='xmlCreateIntSubset'/>
|
||||
<function line='39' file='tree' name='xmlNewDoc'/>
|
||||
<function line='45' file='xmlstring' name='xmlStrlen'/>
|
||||
<function line='38' file='xmlreader' name='xmlTextReaderNodeType'/>
|
||||
<typedef line='60' file='xmlreader' name='xmlTextReaderPtr'/>
|
||||
<function line='34' file='xmlreader' name='xmlTextReaderConstValue'/>
|
||||
<enum line='70' file='parser' name='XML_PARSE_NOENT'/>
|
||||
<function line='37' file='xmlreader' name='xmlTextReaderDepth'/>
|
||||
<enum line='71' file='parser' name='XML_PARSE_DTDVALID'/>
|
||||
<enum line='69' file='parser' name='XML_PARSE_DTDATTR'/>
|
||||
<function line='84' file='xmlreader' name='xmlFreeTextReader'/>
|
||||
<function line='30' file='xmlreader' name='xmlTextReaderConstName'/>
|
||||
<function line='41' file='xmlreader' name='xmlTextReaderHasValue'/>
|
||||
<function line='76' file='xmlreader' name='xmlTextReaderRead'/>
|
||||
<function line='40' file='xmlreader' name='xmlTextReaderIsEmptyElement'/>
|
||||
<function line='68' file='xmlreader' name='xmlReaderForFile'/>
|
||||
<function line='81' file='xmlreader' name='xmlTextReaderIsValid'/>
|
||||
</uses>
|
||||
</example>
|
||||
<example filename='xpath1.c'>
|
||||
<synopsis>Evaluate XPath expression and prints result node set.</synopsis>
|
||||
<purpose>Shows how to evaluate XPath expression and register known namespaces in XPath context.</purpose>
|
||||
<usage>xpath1 <xml-file> <xpath-expr> [<known-ns-list>]</usage>
|
||||
<author>Aleksey Sanin</author>
|
||||
<example filename='reader3.c'>
|
||||
<synopsis>Show how to extract subdocuments with xmlReader</synopsis>
|
||||
<purpose>Demonstrate the use of xmlTextReaderPreservePattern() to parse an XML file with the xmlReader while collecting only some subparts of the document. (Note that the XMLReader functions require libxml2 version later than 2.6.)</purpose>
|
||||
<usage>reader3</usage>
|
||||
<test>reader3 > reader3.tmp ; diff reader3.tmp reader3.res ; rm reader3.tmp</test>
|
||||
<author>Daniel Veillard</author>
|
||||
<copy>see Copyright for the status of this software. </copy>
|
||||
<section>XPath</section>
|
||||
<section>xmlReader</section>
|
||||
<includes>
|
||||
<include><libxml/xpath.h></include>
|
||||
<include><libxml/parser.h></include>
|
||||
<include><libxml/xpathInternals.h></include>
|
||||
<include><libxml/tree.h></include>
|
||||
<include><libxml/xmlreader.h></include>
|
||||
</includes>
|
||||
<uses>
|
||||
<enum line='228' file='tree' name='XML_ELEMENT_NODE'/>
|
||||
<typedef line='87' file='xpath' name='xmlXPathObjectPtr'/>
|
||||
<function line='116' file='xpath' name='xmlXPathEvalExpression'/>
|
||||
<function line='185' file='xpathInternals' name='xmlXPathRegisterNs'/>
|
||||
<function line='128' file='xpath' name='xmlXPathFreeObject'/>
|
||||
<typedef line='85' file='tree' name='xmlDocPtr'/>
|
||||
<typedef line='217' file='tree' name='xmlNsPtr'/>
|
||||
<function line='100' file='xpath' name='xmlXPathNewContext'/>
|
||||
<typedef line='205' file='tree' name='xmlNodePtr'/>
|
||||
<typedef line='86' file='xpath' name='xmlXPathContextPtr'/>
|
||||
<function line='129' file='xpath' name='xmlXPathFreeContext'/>
|
||||
<function line='38' file='parser' name='xmlInitParser'/>
|
||||
<function line='155' file='xmlstring' name='xmlStrdup'/>
|
||||
<function line='179' file='xmlstring' name='xmlStrchr'/>
|
||||
<variable line='192' file='globals' name='xmlFree'/>
|
||||
<function line='93' file='parser' name='xmlParseFile'/>
|
||||
<enum line='216' file='tree' name='XML_NAMESPACE_DECL'/>
|
||||
<typedef line='31' file='xmlreader' name='xmlTextReaderPtr'/>
|
||||
<function line='37' file='xmlreader' name='xmlReaderForFile'/>
|
||||
<function line='65' file='xmlreader' name='xmlFreeTextReader'/>
|
||||
<function line='95' file='tree' name='xmlDocDump'/>
|
||||
<function line='51' file='xmlreader' name='xmlTextReaderRead'/>
|
||||
<function line='61' file='xmlreader' name='xmlTextReaderCurrentDoc'/>
|
||||
<function line='42' file='xmlreader' name='xmlTextReaderPreservePattern'/>
|
||||
<typedef line='76' 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 > 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><libxml/parser.h></include>
|
||||
<include><libxml/xinclude.h></include>
|
||||
<include><libxml/tree.h></include>
|
||||
<include><libxml/xmlIO.h></include>
|
||||
</includes>
|
||||
<uses>
|
||||
<function line='143' file='tree' name='xmlDocDump'/>
|
||||
<function line='134' file='xinclude' name='xmlXIncludeProcess'/>
|
||||
<function line='117' file='xmlIO' name='xmlRegisterInputCallbacks'/>
|
||||
<function line='124' file='parser' name='xmlReadMemory'/>
|
||||
<typedef line='105' file='tree' name='xmlDocPtr'/>
|
||||
</uses>
|
||||
</example>
|
||||
<example filename='parse3.c'>
|
||||
@ -328,28 +329,55 @@
|
||||
<uses>
|
||||
<function line='27' file='tree' name='xmlNodeSetContent'/>
|
||||
<function line='34' file='tree' name='xmlDocDumpFormatMemory'/>
|
||||
<variable line='41' file='globals' name='xmlFree'/>
|
||||
<variable line='40' file='globals' name='xmlFree'/>
|
||||
<function line='28' file='tree' name='xmlDocSetRootElement'/>
|
||||
<typedef line='17' file='tree' name='xmlNodePtr'/>
|
||||
<function line='25' file='tree' name='xmlNewDoc'/>
|
||||
<function line='26' file='tree' name='xmlNewNode'/>
|
||||
</uses>
|
||||
</example>
|
||||
<example filename='xpath2.c'>
|
||||
<synopsis>Load a document, locate subelements with XPath, modify said elements and save the resulting document.</synopsis>
|
||||
<purpose>Shows how to make a full round-trip from a load/edit/save</purpose>
|
||||
<usage>xpath2 <xml-file> <xpath-expr> <new-value></usage>
|
||||
<test>xpath2 test3.xml '//child2' child2 > xpath2.tmp ; diff xpath2.tmp xpath2.res ; rm xpath2.tmp</test>
|
||||
<author>Aleksey Sanin and Daniel Veillard</author>
|
||||
<copy>see Copyright for the status of this software. </copy>
|
||||
<section>XPath</section>
|
||||
<includes>
|
||||
<include><libxml/xpath.h></include>
|
||||
<include><libxml/parser.h></include>
|
||||
<include><libxml/xpathInternals.h></include>
|
||||
<include><libxml/tree.h></include>
|
||||
</includes>
|
||||
<uses>
|
||||
<function line='161' file='tree' name='xmlNodeSetContent'/>
|
||||
<function line='126' file='tree' name='xmlDocDump'/>
|
||||
<typedef line='87' file='xpath' name='xmlXPathObjectPtr'/>
|
||||
<function line='109' file='xpath' name='xmlXPathEvalExpression'/>
|
||||
<function line='122' file='xpath' name='xmlXPathFreeObject'/>
|
||||
<function line='101' file='xpath' name='xmlXPathNewContext'/>
|
||||
<typedef line='86' file='xpath' name='xmlXPathContextPtr'/>
|
||||
<function line='123' file='xpath' name='xmlXPathFreeContext'/>
|
||||
<function line='40' file='parser' name='xmlInitParser'/>
|
||||
<function line='94' file='parser' name='xmlParseFile'/>
|
||||
</uses>
|
||||
</example>
|
||||
<symbols>
|
||||
<symbol name='LIBXML_TEST_VERSION'>
|
||||
<ref filename='io1.c'/>
|
||||
<ref filename='xpath1.c'/>
|
||||
<ref filename='parse1.c'/>
|
||||
<ref filename='parse2.c'/>
|
||||
<ref filename='reader1.c'/>
|
||||
<ref filename='reader2.c'/>
|
||||
<ref filename='reader3.c'/>
|
||||
<ref filename='tree1.c'/>
|
||||
<ref filename='tree2.c'/>
|
||||
<ref filename='testWriter.c'/>
|
||||
</symbol>
|
||||
<symbol name='XML_DEFAULT_VERSION'>
|
||||
<ref filename='testWriter.c'/>
|
||||
</symbol>
|
||||
<symbol name='XML_ELEMENT_NODE'>
|
||||
<ref filename='tree1.c'/>
|
||||
<ref filename='xpath1.c'/>
|
||||
<ref filename='tree1.c'/>
|
||||
</symbol>
|
||||
<symbol name='XML_NAMESPACE_DECL'>
|
||||
<ref filename='xpath1.c'/>
|
||||
@ -380,12 +408,12 @@
|
||||
<ref filename='testWriter.c'/>
|
||||
</symbol>
|
||||
<symbol name='xmlCleanupParser'>
|
||||
<ref filename='io1.c'/>
|
||||
<ref filename='xpath1.c'/>
|
||||
<ref filename='parse1.c'/>
|
||||
<ref filename='parse2.c'/>
|
||||
<ref filename='reader1.c'/>
|
||||
<ref filename='reader2.c'/>
|
||||
<ref filename='reader3.c'/>
|
||||
<ref filename='tree1.c'/>
|
||||
<ref filename='tree2.c'/>
|
||||
<ref filename='testWriter.c'/>
|
||||
</symbol>
|
||||
<symbol name='xmlCreateIntSubset'>
|
||||
<ref filename='tree2.c'/>
|
||||
@ -397,8 +425,9 @@
|
||||
<ref filename='parse2.c'/>
|
||||
</symbol>
|
||||
<symbol name='xmlDocDump'>
|
||||
<ref filename='io1.c'/>
|
||||
<ref filename='reader3.c'/>
|
||||
<ref filename='io1.c'/>
|
||||
<ref filename='xpath2.c'/>
|
||||
</symbol>
|
||||
<symbol name='xmlDocDumpFormatMemory'>
|
||||
<ref filename='io2.c'/>
|
||||
@ -407,33 +436,33 @@
|
||||
<ref filename='tree1.c'/>
|
||||
</symbol>
|
||||
<symbol name='xmlDocPtr'>
|
||||
<ref filename='io1.c'/>
|
||||
<ref filename='xpath1.c'/>
|
||||
<ref filename='parse1.c'/>
|
||||
<ref filename='parse2.c'/>
|
||||
<ref filename='reader3.c'/>
|
||||
<ref filename='testWriter.c'/>
|
||||
<ref filename='xpath1.c'/>
|
||||
<ref filename='reader3.c'/>
|
||||
<ref filename='io1.c'/>
|
||||
</symbol>
|
||||
<symbol name='xmlDocSetRootElement'>
|
||||
<ref filename='testWriter.c'/>
|
||||
<ref filename='tree2.c'/>
|
||||
<ref filename='testWriter.c'/>
|
||||
<ref filename='io2.c'/>
|
||||
</symbol>
|
||||
<symbol name='xmlFindCharEncodingHandler'>
|
||||
<ref filename='testWriter.c'/>
|
||||
</symbol>
|
||||
<symbol name='xmlFree'>
|
||||
<ref filename='testWriter.c'/>
|
||||
<ref filename='xpath1.c'/>
|
||||
<ref filename='testWriter.c'/>
|
||||
<ref filename='io2.c'/>
|
||||
</symbol>
|
||||
<symbol name='xmlFreeDoc'>
|
||||
<ref filename='io1.c'/>
|
||||
<ref filename='xpath1.c'/>
|
||||
<ref filename='parse1.c'/>
|
||||
<ref filename='parse2.c'/>
|
||||
<ref filename='reader3.c'/>
|
||||
<ref filename='testWriter.c'/>
|
||||
<ref filename='tree1.c'/>
|
||||
<ref filename='tree2.c'/>
|
||||
<ref filename='testWriter.c'/>
|
||||
</symbol>
|
||||
<symbol name='xmlFreeParserCtxt'>
|
||||
<ref filename='parse2.c'/>
|
||||
@ -449,24 +478,25 @@
|
||||
</symbol>
|
||||
<symbol name='xmlInitParser'>
|
||||
<ref filename='xpath1.c'/>
|
||||
<ref filename='xpath2.c'/>
|
||||
</symbol>
|
||||
<symbol name='xmlMalloc'>
|
||||
<ref filename='testWriter.c'/>
|
||||
</symbol>
|
||||
<symbol name='xmlMemoryDump'>
|
||||
<ref filename='io1.c'/>
|
||||
<ref filename='xpath1.c'/>
|
||||
<ref filename='parse1.c'/>
|
||||
<ref filename='parse2.c'/>
|
||||
<ref filename='tree2.c'/>
|
||||
<ref filename='testWriter.c'/>
|
||||
<ref filename='reader1.c'/>
|
||||
<ref filename='reader2.c'/>
|
||||
<ref filename='reader3.c'/>
|
||||
</symbol>
|
||||
<symbol name='xmlNewChild'>
|
||||
<ref filename='tree2.c'/>
|
||||
</symbol>
|
||||
<symbol name='xmlNewDoc'>
|
||||
<ref filename='testWriter.c'/>
|
||||
<ref filename='tree2.c'/>
|
||||
<ref filename='testWriter.c'/>
|
||||
<ref filename='io2.c'/>
|
||||
</symbol>
|
||||
<symbol name='xmlNewDocNode'>
|
||||
@ -498,12 +528,13 @@
|
||||
<ref filename='testWriter.c'/>
|
||||
</symbol>
|
||||
<symbol name='xmlNodePtr'>
|
||||
<ref filename='testWriter.c'/>
|
||||
<ref filename='xpath1.c'/>
|
||||
<ref filename='testWriter.c'/>
|
||||
<ref filename='io2.c'/>
|
||||
</symbol>
|
||||
<symbol name='xmlNodeSetContent'>
|
||||
<ref filename='io2.c'/>
|
||||
<ref filename='xpath2.c'/>
|
||||
</symbol>
|
||||
<symbol name='xmlNsPtr'>
|
||||
<ref filename='xpath1.c'/>
|
||||
@ -512,8 +543,9 @@
|
||||
<ref filename='parse4.c'/>
|
||||
</symbol>
|
||||
<symbol name='xmlParseFile'>
|
||||
<ref filename='tree1.c'/>
|
||||
<ref filename='xpath1.c'/>
|
||||
<ref filename='tree1.c'/>
|
||||
<ref filename='xpath2.c'/>
|
||||
</symbol>
|
||||
<symbol name='xmlParserCtxtPtr'>
|
||||
<ref filename='parse2.c'/>
|
||||
@ -631,21 +663,27 @@
|
||||
</symbol>
|
||||
<symbol name='xmlXPathContextPtr'>
|
||||
<ref filename='xpath1.c'/>
|
||||
<ref filename='xpath2.c'/>
|
||||
</symbol>
|
||||
<symbol name='xmlXPathEvalExpression'>
|
||||
<ref filename='xpath1.c'/>
|
||||
<ref filename='xpath2.c'/>
|
||||
</symbol>
|
||||
<symbol name='xmlXPathFreeContext'>
|
||||
<ref filename='xpath1.c'/>
|
||||
<ref filename='xpath2.c'/>
|
||||
</symbol>
|
||||
<symbol name='xmlXPathFreeObject'>
|
||||
<ref filename='xpath1.c'/>
|
||||
<ref filename='xpath2.c'/>
|
||||
</symbol>
|
||||
<symbol name='xmlXPathNewContext'>
|
||||
<ref filename='xpath1.c'/>
|
||||
<ref filename='xpath2.c'/>
|
||||
</symbol>
|
||||
<symbol name='xmlXPathObjectPtr'>
|
||||
<ref filename='xpath1.c'/>
|
||||
<ref filename='xpath2.c'/>
|
||||
</symbol>
|
||||
<symbol name='xmlXPathRegisterNs'>
|
||||
<ref filename='xpath1.c'/>
|
||||
@ -668,6 +706,7 @@
|
||||
</section>
|
||||
<section name='XPath'>
|
||||
<example filename='xpath1.c'/>
|
||||
<example filename='xpath2.c'/>
|
||||
</section>
|
||||
<section name='xmlReader'>
|
||||
<example filename='reader1.c'/>
|
||||
|
File diff suppressed because one or more lines are too long
@ -249,10 +249,11 @@ install-data-local:
|
||||
for example in examples:
|
||||
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 + "valgrind: \n\t$(MAKE) CHECKER='valgrind -q' tests\n\n"
|
||||
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@($(CHECKER) %s)\n" % (test)
|
||||
Makefile = Makefile + '\t@(grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0)\n'
|
||||
Makefile = Makefile + "\n\n"
|
||||
try:
|
||||
|
@ -4,6 +4,7 @@
|
||||
* purpose: Shows how to evaluate XPath expression and register
|
||||
* known namespaces in XPath context.
|
||||
* usage: xpath1 <xml-file> <xpath-expr> [<known-ns-list>]
|
||||
* test: ./xpath1 test3.xml '//child2' > xpath1.tmp ; diff xpath1.tmp xpath1.res ; rm xpath1.tmp
|
||||
* author: Aleksey Sanin
|
||||
* copy: see Copyright for the status of this software.
|
||||
*/
|
||||
|
170
doc/examples/xpath2.c
Normal file
170
doc/examples/xpath2.c
Normal file
@ -0,0 +1,170 @@
|
||||
/**
|
||||
* section: XPath
|
||||
* synopsis: Load a document, locate subelements with XPath, modify
|
||||
* said elements and save the resulting document.
|
||||
* purpose: Shows how to make a full round-trip from a load/edit/save
|
||||
* usage: xpath2 <xml-file> <xpath-expr> <new-value>
|
||||
* test: xpath2 test3.xml '//child2' child2 > xpath2.tmp ; diff xpath2.tmp xpath2.res ; rm xpath2.tmp
|
||||
* author: Aleksey Sanin and Daniel Veillard
|
||||
* copy: see Copyright for the status of this software.
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <libxml/tree.h>
|
||||
#include <libxml/parser.h>
|
||||
#include <libxml/xpath.h>
|
||||
#include <libxml/xpathInternals.h>
|
||||
|
||||
#ifdef LIBXML_XPATH_ENABLED
|
||||
|
||||
|
||||
static void usage(const char *name);
|
||||
static int example4(const char *filename, const xmlChar * xpathExpr,
|
||||
const xmlChar * value);
|
||||
static void update_xpath_nodes(xmlNodeSetPtr nodes, const xmlChar * value);
|
||||
|
||||
|
||||
int
|
||||
main(int argc, char **argv) {
|
||||
/* Parse command line and process file */
|
||||
if (argc != 4) {
|
||||
fprintf(stderr, "Error: wrong number of arguments.\n");
|
||||
usage(argv[0]);
|
||||
return(-1);
|
||||
}
|
||||
|
||||
/* Init libxml */
|
||||
xmlInitParser();
|
||||
LIBXML_TEST_VERSION
|
||||
|
||||
/* Do the main job */
|
||||
if (example4(argv[1], BAD_CAST argv[2], BAD_CAST argv[3])) {
|
||||
usage(argv[0]);
|
||||
return(-1);
|
||||
}
|
||||
|
||||
/* Shutdown libxml */
|
||||
xmlCleanupParser();
|
||||
|
||||
/*
|
||||
* this is to debug memory for regression tests
|
||||
*/
|
||||
xmlMemoryDump();
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* usage:
|
||||
* @name: the program name.
|
||||
*
|
||||
* Prints usage information.
|
||||
*/
|
||||
void
|
||||
usage(const char *name) {
|
||||
assert(name);
|
||||
|
||||
fprintf(stderr, "Usage: %s <xml-file> <xpath-expr> <value>\n", name);
|
||||
}
|
||||
|
||||
/**
|
||||
* example4:
|
||||
* @filename: the input XML filename.
|
||||
* @xpathExpr: the xpath expression for evaluation.
|
||||
* @value: the new node content.
|
||||
*
|
||||
* Parses input XML file, evaluates XPath expression and update the nodes
|
||||
* then print the result.
|
||||
*
|
||||
* Returns 0 on success and a negative value otherwise.
|
||||
*/
|
||||
static int
|
||||
example4(const char* filename, const xmlChar* xpathExpr, const xmlChar* value) {
|
||||
xmlDocPtr doc;
|
||||
xmlXPathContextPtr xpathCtx;
|
||||
xmlXPathObjectPtr xpathObj;
|
||||
|
||||
assert(filename);
|
||||
assert(xpathExpr);
|
||||
assert(value);
|
||||
|
||||
/* Load XML document */
|
||||
doc = xmlParseFile(filename);
|
||||
if (doc == NULL) {
|
||||
fprintf(stderr, "Error: unable to parse file \"%s\"\n", filename);
|
||||
return(-1);
|
||||
}
|
||||
|
||||
/* Create xpath evaluation context */
|
||||
xpathCtx = xmlXPathNewContext(doc);
|
||||
if(xpathCtx == NULL) {
|
||||
fprintf(stderr,"Error: unable to create new XPath context\n");
|
||||
xmlFreeDoc(doc);
|
||||
return(-1);
|
||||
}
|
||||
|
||||
/* Evaluate xpath expression */
|
||||
xpathObj = xmlXPathEvalExpression(xpathExpr, xpathCtx);
|
||||
if(xpathObj == NULL) {
|
||||
fprintf(stderr,"Error: unable to evaluate xpath expression \"%s\"\n", xpathExpr);
|
||||
xmlXPathFreeContext(xpathCtx);
|
||||
xmlFreeDoc(doc);
|
||||
return(-1);
|
||||
}
|
||||
|
||||
/* update selected nodes */
|
||||
update_xpath_nodes(xpathObj->nodesetval, value);
|
||||
|
||||
|
||||
/* Cleanup of XPath data */
|
||||
xmlXPathFreeObject(xpathObj);
|
||||
xmlXPathFreeContext(xpathCtx);
|
||||
|
||||
/* dump the resulting document */
|
||||
xmlDocDump(stdout, doc);
|
||||
|
||||
|
||||
/* free the document */
|
||||
xmlFreeDoc(doc);
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* update_xpath_nodes:
|
||||
* @nodes: the nodes set.
|
||||
* @value: the new value for the node(s)
|
||||
*
|
||||
* Prints the @nodes content to @output.
|
||||
*/
|
||||
static void
|
||||
update_xpath_nodes(xmlNodeSetPtr nodes, const xmlChar* value) {
|
||||
int size;
|
||||
int i;
|
||||
|
||||
assert(value);
|
||||
size = (nodes) ? nodes->nodeNr : 0;
|
||||
|
||||
/*
|
||||
* NOTE: the nodes are processed in reverse order, i.e. reverse document
|
||||
* order because xmlNodeSetContent can actually free up descendant
|
||||
* of the node and such nodes may have been selected too ! Handling
|
||||
* in reverse order ensure that descendant are accessed first, before
|
||||
* they get removed. Mixing XPath and modifications on a tree must be
|
||||
* done carefully !
|
||||
*/
|
||||
for(i = size - 1; i >= 0; i--) {
|
||||
assert(nodes->nodeTab[i]);
|
||||
|
||||
xmlNodeSetContent(nodes->nodeTab[i], value);
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
int main(void) {
|
||||
fprintf(stderr, "XPath support not compiled in\n");
|
||||
exit(1);
|
||||
}
|
||||
#endif
|
38
doc/examples/xpath2.res
Normal file
38
doc/examples/xpath2.res
Normal file
@ -0,0 +1,38 @@
|
||||
<?xml version="1.0"?>
|
||||
<doc>
|
||||
<parent>
|
||||
<discarded>
|
||||
<discarded/>
|
||||
</discarded>
|
||||
<preserved/>
|
||||
This text node must be discarded
|
||||
<discarded>
|
||||
<discarded/>
|
||||
</discarded>
|
||||
<preserved>
|
||||
content1
|
||||
<child1/>
|
||||
<child2>child2</child2>
|
||||
<preserved>too</preserved>
|
||||
<child2>child2</child2>
|
||||
<preserved/>
|
||||
<child2>child2</child2>
|
||||
<preserved/>
|
||||
<child2>child2</child2>
|
||||
content6
|
||||
</preserved>
|
||||
This text node must be discarded
|
||||
<discarded>
|
||||
<discarded/>
|
||||
</discarded>
|
||||
This text node must be discarded
|
||||
<preserved/>
|
||||
This text node must be discarded
|
||||
<preserved/>
|
||||
This text node must be discarded
|
||||
<discarded>
|
||||
<discarded/>
|
||||
</discarded>
|
||||
This text node must be discarded
|
||||
</parent>
|
||||
</doc>
|
Loading…
Reference in New Issue
Block a user