Commit b5eb7143 authored by Daniel Veillard's avatar Daniel Veillard
Browse files

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
parent 688f6694
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
......
......@@ -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)
@($(CHECKER) ./parse1 test1.xml)
@(grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0)
@($(CHECKER) ./parse2 test2.xml)
@(grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0)
@($(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)
@(./parse2 test2.xml)
@($(CHECKER) ./tree2 > tree2.tmp ; diff tree2.tmp tree2.res ; rm tree2.tmp)
@(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) ./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)
@(./tree2 > tree2.tmp ; diff tree2.tmp tree2.res ; rm tree2.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)
@(./testWriter ; for i in 1 2 3 4 ; do diff writer.xml writer$$i.res ; done ; rm writer*.res)
@($(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)
@(./reader1 test2.xml > reader1.tmp ; diff reader1.tmp reader1.res ; rm reader1.tmp)
@($(CHECKER) ./reader3 > reader3.tmp ; diff reader3.tmp reader3.res ; rm reader3.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)
@($(CHECKER) ./io1 > io1.tmp ; diff io1.tmp io1.res ; rm -f io1.tmp)
@(grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0)
@(./reader3 > reader3.tmp ; diff reader3.tmp reader3.res ; rm reader3.tmp)
@($(CHECKER) ./parse3)
@(grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0)
@(./io1 > io1.tmp ; diff io1.tmp io1.res ; rm -f io1.tmp)
@($(CHECKER) ./parse4 test3.xml)
@(grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0)
@(./parse3)
@($(CHECKER) ./io2 > io2.tmp ; diff io2.tmp io2.res ; rm -f io2.tmp)
@(grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0)
@(./parse4 test3.xml)
@($(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)
This diff is collapsed.
This diff is collapsed.
......@@ -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.
*/
......
/**
* 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
<?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>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment