Commit 6eadf63c authored by Daniel Veillard's avatar Daniel Veillard

First commit of the new Relax-NG validation code, not generally useful

* Makefile.am configure.in relaxng.c include/libxml/relaxng.h:
  First commit of the new Relax-NG validation code, not generally
  useful yet.
* test/relaxng/* result/relaxng/*: current state of the regression
  tests
Daniel
parent 814a76db
Thu Jan 23 19:26:20 CET 2003 Daniel Veillard <daniel@veillard.com>
* Makefile.am configure.in relaxng.c include/libxml/relaxng.h:
First commit of the new Relax-NG validation code, not generally
useful yet.
* test/relaxng/* result/relaxng/*: current state of the regression
tests
Thu Jan 23 19:22:54 CET 2003 Daniel Veillard <daniel@veillard.com>
* tree.c: minimized the memory allocated for GetContent
......
......@@ -7,8 +7,9 @@ DIST_SUBDIRS = include . doc example python
INCLUDES = -I$(top_builddir)/include -I@srcdir@/include @THREAD_CFLAGS@ @Z_CFLAGS@
noinst_PROGRAMS=testSchemas testSAX testHTML testXPath testURI testDocbook \
testThreads testC14N testAutomata testRegexp testReader
noinst_PROGRAMS=testSchemas testRelax testSAX testHTML testXPath testURI \
testDocbook testThreads testC14N testAutomata testRegexp \
testReader
bin_PROGRAMS = xmllint xmlcatalog
......@@ -26,7 +27,7 @@ libxml2_la_SOURCES = SAX.c entities.c encoding.c error.c parserInternals.c \
xpointer.c xinclude.c nanohttp.c nanoftp.c DOCBparser.c \
catalog.c globals.c threads.c c14n.c \
xmlregexp.c xmlschemas.c xmlschemastypes.c xmlunicode.c \
triostr.c trio.c xmlreader.c
triostr.c trio.c xmlreader.c relaxng.c
else
libxml2_la_SOURCES = SAX.c entities.c encoding.c error.c parserInternals.c \
parser.c tree.c hash.c list.c xmlIO.c xmlmemory.c uri.c \
......@@ -34,7 +35,7 @@ libxml2_la_SOURCES = SAX.c entities.c encoding.c error.c parserInternals.c \
xpointer.c xinclude.c nanohttp.c nanoftp.c DOCBparser.c \
catalog.c globals.c threads.c c14n.c \
xmlregexp.c xmlschemas.c xmlschemastypes.c xmlunicode.c \
xmlreader.c
xmlreader.c relaxng.c
endif
DEPS = $(top_builddir)/libxml2.la
......@@ -105,6 +106,11 @@ testSchemas_LDFLAGS =
testSchemas_DEPENDENCIES = $(DEPS)
testSchemas_LDADD= $(LDADDS)
testRelax_SOURCES=testRelax.c
testRelax_LDFLAGS =
testRelax_DEPENDENCIES = $(DEPS)
testRelax_LDADD= $(LDADDS)
testReader_SOURCES=testReader.c
testReader_LDFLAGS =
testReader_DEPENDENCIES = $(DEPS)
......@@ -680,6 +686,36 @@ Schemastests: testSchemas$(EXEEXT)
fi ; \
done; done)
Relaxtests: testRelax$(EXEEXT)
@(echo > .memdump)
@echo "##"
@echo "## Relax-NG regression tests"
@echo "##"
-@(for i in $(srcdir)/test/relaxng/*.rng ; do \
name=`basename $$i | sed 's+\.rng++'`; \
for j in $(srcdir)/test/relaxng/"$$name"_*.xml ; do \
if [ -f $$j ] ; then \
xno=`basename $$j | sed 's+.*_\(.*\).xml+\1+'`; \
if [ ! -f $(srcdir)/result/relaxng/"$$name"_"$$xno" ]; \
then \
echo New test file "$$name"_"$$xno" ; \
$(CHECKER) $(top_builddir)/testRelax $$i $$j \
> $(srcdir)/result/relaxng/"$$name"_"$$xno" \
2> $(srcdir)/result/relaxng/"$$name"_"$$xno".err; \
else \
echo Testing "$$name"_"$$xno" ; \
$(CHECKER) $(top_builddir)/testRelax $$i $$j \
> res.$$name 2> err.$$name;\
grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0";\
diff $(srcdir)/result/relaxng/"$$name"_"$$xno" \
res.$$name;\
diff $(srcdir)/result/relaxng/"$$name"_"$$xno".err \
err.$$name;\
grep Unimplemented err.$$name; \
rm res.$$name err.$$name ; \
fi ; fi ; \
done; done)
dist-hook: libxml.spec
-cp libxml.spec $(distdir)
(cd $(srcdir) ; tar -cf - --exclude CVS win32 macos vms test result SAXresult ) | (cd $(distdir); tar xf -)
......
......@@ -581,9 +581,9 @@ AC_SUBST(WITH_ICONV)
AC_ARG_WITH(schemas, [ --with-schemas Add experimental Schemas support (off)])
if test "$with_schemas" = "yes" ; then
echo Enabling Schemas support
echo "Enabling Schemas/Relax-NG support"
WITH_SCHEMAS=1
TEST_SCHEMAS="Schemastests"
TEST_SCHEMAS="Schemastests Relaxtests"
with_regexps=yes
else
WITH_SCHEMAS=0
......
/*
* relaxng.h: header for the implementation of the Relax-NG validation
*
* See Copyright for the status of this software.
*
* daniel@veillard.com
*/
#ifndef __XML_RELAX_NG__
#define __XML_RELAX_NG__
#include <libxml/hash.h>
typedef struct _xmlRelaxNG xmlRelaxNG;
typedef xmlRelaxNG *xmlRelaxNGPtr;
/**
* A schemas validation context
*/
typedef void (*xmlRelaxNGValidityErrorFunc) (void *ctx, const char *msg, ...);
typedef void (*xmlRelaxNGValidityWarningFunc) (void *ctx, const char *msg, ...);
typedef struct _xmlRelaxNGParserCtxt xmlRelaxNGParserCtxt;
typedef xmlRelaxNGParserCtxt *xmlRelaxNGParserCtxtPtr;
typedef struct _xmlRelaxNGValidCtxt xmlRelaxNGValidCtxt;
typedef xmlRelaxNGValidCtxt *xmlRelaxNGValidCtxtPtr;
/*
* Interfaces for parsing.
*/
xmlRelaxNGParserCtxtPtr xmlRelaxNGNewParserCtxt (const char *URL);
xmlRelaxNGParserCtxtPtr xmlRelaxNGNewMemParserCtxt(const char *buffer,
int size);
void xmlRelaxNGFreeParserCtxt (xmlRelaxNGParserCtxtPtr ctxt);
void xmlRelaxNGSetParserErrors(xmlRelaxNGParserCtxtPtr ctxt,
xmlRelaxNGValidityErrorFunc err,
xmlRelaxNGValidityWarningFunc warn,
void *ctx);
xmlRelaxNGPtr xmlRelaxNGParse (xmlRelaxNGParserCtxtPtr ctxt);
void xmlRelaxNGFree (xmlRelaxNGPtr schema);
void xmlRelaxNGDump (FILE *output,
xmlRelaxNGPtr schema);
/*
* Interfaces for validating
*/
void xmlRelaxNGSetValidErrors(xmlRelaxNGValidCtxtPtr ctxt,
xmlRelaxNGValidityErrorFunc err,
xmlRelaxNGValidityWarningFunc warn,
void *ctx);
xmlRelaxNGValidCtxtPtr xmlRelaxNGNewValidCtxt (xmlRelaxNGPtr schema);
void xmlRelaxNGFreeValidCtxt (xmlRelaxNGValidCtxtPtr ctxt);
int xmlRelaxNGValidateDoc (xmlRelaxNGValidCtxtPtr ctxt,
xmlDocPtr instance);
int xmlRelaxNGValidateStream(xmlRelaxNGValidCtxtPtr ctxt,
xmlParserInputBufferPtr input,
xmlCharEncoding enc,
xmlSAXHandlerPtr sax,
void *user_data);
void xmlRelaxNGCleanupTypes (void);
#endif /* __XML_RELAX_NG__ */
This diff is collapsed.
./test/relaxng/spec1_1.xml validates
xmlRelaxNGValidateDefinition(): validated empty
xmlRelaxNGValidateDefinition(): validated bar1 : 0
xmlRelaxNGValidateDefinition(): validated empty
xmlRelaxNGValidateDefinition(): validated bar2 : 0
xmlRelaxNGValidateDefinition(): validated foo : 0
./test/relaxng/tutor1_1_1.xml validates
xmlRelaxNGValidateDefinition(): validated name : 0
xmlRelaxNGValidateDefinition(): validated email : 0
xmlRelaxNGValidateDefinition(): validated card : 0
xmlRelaxNGValidateDefinition(): validated name : 0
xmlRelaxNGValidateDefinition(): validated email : 0
xmlRelaxNGValidateDefinition(): validated card : 0
xmlRelaxNGValidateDefinition(): validated addressBook : 0
./test/relaxng/tutor1_2_1.xml validates
xmlRelaxNGValidateDefinition(): validated name : 0
xmlRelaxNGValidateDefinition(): validated email : 0
xmlRelaxNGValidateDefinition(): validated card : 0
xmlRelaxNGValidateDefinition(): validated name : 0
xmlRelaxNGValidateDefinition(): validated email : 0
xmlRelaxNGValidateDefinition(): validated card : 0
xmlRelaxNGValidateDefinition(): validated addressBook : 0
./test/relaxng/tutor1_3_1.xml validates
xmlRelaxNGValidateDefinition(): validated name : 0
xmlRelaxNGValidateDefinition(): validated email : 0
xmlRelaxNGValidateDefinition(): validated card : 0
xmlRelaxNGValidateDefinition(): validated name : 0
xmlRelaxNGValidateDefinition(): validated email : 0
xmlRelaxNGValidateDefinition(): validated card : 0
xmlRelaxNGValidateDefinition(): validated addressBook : 0
./test/relaxng/tutor1_4_1.xml validates
xmlRelaxNGValidateDefinition(): validated name : 0
xmlRelaxNGValidateDefinition(): validated email : 0
xmlRelaxNGValidateDefinition(): validated card : 0
xmlRelaxNGValidateDefinition(): validated name : 0
xmlRelaxNGValidateDefinition(): validated email : 0
xmlRelaxNGValidateDefinition(): validated card : 0
xmlRelaxNGValidateDefinition(): validated addressBook : 0
./test/relaxng/tutor2_1_1.xml validates
xmlRelaxNGValidateDefinition(): validated givenName : 0
xmlRelaxNGValidateDefinition(): validated familyName : 0
xmlRelaxNGValidateDefinition(): validated email : 0
xmlRelaxNGValidateDefinition(): validated card : 0
xmlRelaxNGValidateDefinition(): validated name : 0
xmlRelaxNGValidateDefinition(): validated email : 0
xmlRelaxNGValidateDefinition(): validated card : 0
xmlRelaxNGValidateDefinition(): validated addressBook : 0
./test/relaxng/tutor3_1_1.xml validates
xmlRelaxNGValidateAttribute(email): 0
xmlRelaxNGValidateAttribute(name): 0
xmlRelaxNGValidateDefinition(): validated card : 0
xmlRelaxNGValidateDefinition(): validated addressBook : 0
./test/relaxng/tutor3_1_2.xml validates
xmlRelaxNGValidateAttribute(email): 0
xmlRelaxNGValidateAttribute(name): 0
xmlRelaxNGValidateDefinition(): validated card : 0
xmlRelaxNGValidateDefinition(): validated addressBook : 0
Expecting element name, got email
Extra content for element card
./test/relaxng/tutor3_2_1.xml validation generated an internal error
error detected at relaxng.c:2365
error detected at relaxng.c:2413
xmlRelaxNGValidateDefinition(): validated card : -1
./test/relaxng/tutor3_3_1.xml validates
xmlRelaxNGValidateAttribute(email): 0
xmlRelaxNGValidateAttribute(name): 0
xmlRelaxNGValidateAttribute(note): -1
xmlRelaxNGValidateDefinition(): validated card : 0
xmlRelaxNGValidateAttribute(email): 0
xmlRelaxNGValidateAttribute(name): 0
xmlRelaxNGValidateAttribute(note): 0
xmlRelaxNGValidateDefinition(): validated card : 0
xmlRelaxNGValidateDefinition(): validated addressBook : 0
./test/relaxng/tutor3_4_1.xml validates
xmlRelaxNGValidateAttribute(email): 0
xmlRelaxNGValidateAttribute(name): 0
xmlRelaxNGValidateDefinition(): validated card : 0
xmlRelaxNGValidateAttribute(email): 0
xmlRelaxNGValidateAttribute(name): -1
xmlRelaxNGValidateAttribute(givenName): 0
xmlRelaxNGValidateAttribute(familyName): 0
xmlRelaxNGValidateDefinition(): validated card : 0
xmlRelaxNGValidateDefinition(): validated addressBook : 0
./test/relaxng/tutor3_5_1.xml validates
xmlRelaxNGValidateAttribute(name): 0
xmlRelaxNGValidateAttribute(email): 0
xmlRelaxNGValidateDefinition(): validated card : 0
xmlRelaxNGValidateAttribute(name): 0
xmlRelaxNGValidateAttribute(email): 0
xmlRelaxNGValidateDefinition(): validated card : 0
xmlRelaxNGValidateDefinition(): validated name : 0
xmlRelaxNGValidateAttribute(email): 0
xmlRelaxNGValidateDefinition(): validated card : 0
xmlRelaxNGValidateAttribute(name): 0
xmlRelaxNGValidateDefinition(): validated email : 0
xmlRelaxNGValidateDefinition(): validated card : 0
xmlRelaxNGValidateDefinition(): validated name : 0
xmlRelaxNGValidateDefinition(): validated email : 0
xmlRelaxNGValidateDefinition(): validated card : 0
xmlRelaxNGValidateDefinition(): validated addressBook : 0
Extra content for element addressBook
./test/relaxng/tutor3_5_2.xml validation generated an internal error
xmlRelaxNGValidateAttribute(name): -1
xmlRelaxNGValidateDefinition(): validated email : 0
xmlRelaxNGValidateDefinition(): validated card : -1
error detected at relaxng.c:2413
xmlRelaxNGValidateDefinition(): validated addressBook : -1
./test/relaxng/tutor3_6_1.xml validates
xmlRelaxNGValidateAttribute(email): 0
xmlRelaxNGValidateDefinition(): validated card : 0
xmlRelaxNGValidateDefinition(): validated addressBook : 0
Relax-NG schema ./test/relaxng/tutor3_7.rng failed to compile
xmlRelaxNGParseElement: element has no content
./test/relaxng/tutor3_8_1.xml validates
xmlRelaxNGValidateDefinition(): validated name : 0
xmlRelaxNGValidateDefinition(): validated email : 0
xmlRelaxNGValidateDefinition(): validated empty
xmlRelaxNGValidateDefinition(): validated prefersHTML : 0
xmlRelaxNGValidateDefinition(): validated card : 0
xmlRelaxNGValidateDefinition(): validated name : 0
xmlRelaxNGValidateDefinition(): validated email : 0
xmlRelaxNGValidateDefinition(): validated card : 0
xmlRelaxNGValidateDefinition(): validated addressBook : 0
./test/relaxng/tutor3_9_1.xml validates
xmlRelaxNGValidateAttribute(email): 0
xmlRelaxNGValidateDefinition(): validated card : 0
./test/relaxng/tutor4_1_1.xml validates
xmlRelaxNGParseGrammar()
xmlRelaxNGValidateDefinition(): validated name : 0
xmlRelaxNGValidateDefinition(): validated email : 0
xmlRelaxNGValidateDefinition(): validated card : 0
xmlRelaxNGValidateDefinition(): validated name : 0
xmlRelaxNGValidateDefinition(): validated email : 0
xmlRelaxNGValidateDefinition(): validated card : 0
xmlRelaxNGValidateDefinition(): validated addressBook : 0
./test/relaxng/tutor4_2_1.xml validates
xmlRelaxNGParseGrammar()
xmlRelaxNGValidateDefinition(): validated name : 0
xmlRelaxNGValidateDefinition(): validated email : 0
xmlRelaxNGValidateDefinition(): validated card : 0
xmlRelaxNGValidateDefinition(): validated name : 0
xmlRelaxNGValidateDefinition(): validated email : 0
xmlRelaxNGValidateDefinition(): validated card : 0
xmlRelaxNGValidateDefinition(): validated addressBook : 0
<?xml version="1.0"?>
<element name="foo"
xmlns="http://relaxng.org/ns/structure/1.0"
xmlns:a="http://relaxng.org/ns/annotation/1.0"
xmlns:ex1="http://www.example.com/n1"
xmlns:ex2="http://www.example.com/n2">
<a:documentation>A foo element.</a:documentation>
<element name="ex1:bar1">
<empty/>
</element>
<element name="ex2:bar2">
<empty/>
</element>
</element>
<?xml version="1.0"?>
<foo><pre1:bar1 xmlns:pre1="http://www.example.com/n1"/><pre2:bar2 xmlns:pre2="http://www.example.com/n2"/></foo>
<element name="addressBook" xmlns="http://relaxng.org/ns/structure/1.0">
<zeroOrMore>
<element name="card">
<element name="name">
<text/>
</element>
<element name="email">
<text/>
</element>
</element>
</zeroOrMore>
</element>
<addressBook>
<card>
<name>John Smith</name>
<email>js@example.com</email>
</card>
<card>
<name>Fred Bloggs</name>
<email>fb@example.net</email>
</card>
</addressBook>
<element name="addressBook" xmlns="http://relaxng.org/ns/structure/1.0">
<oneOrMore>
<element name="card">
<element name="name">
<text/>
</element>
<element name="email">
<text/>
</element>
</element>
</oneOrMore>
</element>
<addressBook>
<card>
<name>John Smith</name>
<email>js@example.com</email>
</card>
<card>
<name>Fred Bloggs</name>
<email>fb@example.net</email>
</card>
</addressBook>
<element name="addressBook" xmlns="http://relaxng.org/ns/structure/1.0">
<zeroOrMore>
<element name="card">
<element name="name">
<text/>
</element>
<element name="email">
<text/>
</element>
<optional>
<element name="note">
<text/>
</element>
</optional>
</element>
</zeroOrMore>
</element>
<addressBook>
<card>
<name>John Smith</name>
<email>js@example.com</email>
</card>
<card>
<name>Fred Bloggs</name>
<email>fb@example.net</email>
</card>
</addressBook>
<rng:element name="addressBook" xmlns:rng="http://relaxng.org/ns/structure/1.0">
<rng:zeroOrMore>
<rng:element name="card">
<rng:element name="name">
<rng:text/>
</rng:element>
<rng:element name="email">
<rng:text/>
</rng:element>
</rng:element>
</rng:zeroOrMore>
</rng:element>
<addressBook>
<card>
<name>John Smith</name>
<email>js@example.com</email>
</card>
<card>
<name>Fred Bloggs</name>
<email>fb@example.net</email>
</card>
</addressBook>
<element name="addressBook" xmlns="http://relaxng.org/ns/structure/1.0">
<zeroOrMore>
<element name="card">
<choice>
<element name="name">
<text/>
</element>
<group>
<element name="givenName">
<text/>
</element>
<element name="familyName">
<text/>
</element>
</group>
</choice>
<element name="email">
<text/>
</element>
<optional>
<element name="note">
<text/>
</element>
</optional>
</element>
</zeroOrMore>
</element>
<addressBook>
<card>
<givenName>John</givenName>
<familyName>Smith</familyName>
<email>js@example.com</email>
</card>
<card>
<name>Fred Bloggs</name>
<email>fb@example.net</email>
</card>
</addressBook>
<element name="addressBook" xmlns="http://relaxng.org/ns/structure/1.0">
<zeroOrMore>
<element name="card">
<attribute name="name">
<text/>
</attribute>
<attribute name="email">
<text/>
</attribute>
</element>
</zeroOrMore>
</element>
<addressBook>
<card name="John Smith" email="js@example.com"/>
</addressBook>
<addressBook>
<card email="js@example.com" name="John Smith"/>
</addressBook>
<element name="card" xmlns="http://relaxng.org/ns/structure/1.0">
<element name="name">
<text/>
</element>
<element name="email">
<text/>
</element>
</element>
<card><email>js@example.com</email><name>John Smith</name></card>
<element name="addressBook" xmlns="http://relaxng.org/ns/structure/1.0">
<zeroOrMore>
<element name="card">
<attribute name="name">
<text/>
</attribute>
<attribute name="email">
<text/>
</attribute>
<optional>
<attribute name="note">
<text/>
</attribute>
</optional>
</element>
</zeroOrMore>
</element>
<addressBook>
<card name="foo" email="bar"/>
<card name="foo2" note="second" email="bar2"/>
</addressBook>
<element name="addressBook" xmlns="http://relaxng.org/ns/structure/1.0">
<zeroOrMore>
<element name="card">
<choice>
<attribute name="name">
<text/>
</attribute>
<group>
<attribute name="givenName">
<text/>
</attribute>
<attribute name="familyName">
<text/>
</attribute>
</group>
</choice>
<attribute name="email">
<text/>
</attribute>
</element>
</zeroOrMore>
</element>
<addressBook>
<card name="foo" email="bar"/>
<card givenName="d" familyName="v" email="bar"/>
</addressBook>
<element name="addressBook" xmlns="http://relaxng.org/ns/structure/1.0">
<zeroOrMore>
<element name="card">
<choice>
<element name="name">
<text/>
</element>
<attribute name="name">
<text/>
</attribute>
</choice>
<choice>
<element name="email">
<text/>
</element>
<attribute name="email">
<text/>
</attribute>
</choice>
</element>
</zeroOrMore>
</element>
<addressBook>
<card name="John Smith" email="js@example.com"/>
<card email="js@example.com" name="John Smith"/>
<card email="js@example.com"><name>John Smith</name></card>
<card name="John Smith"><email>js@example.com</email></card>
<card><name>John Smith</name><email>js@example.com</email></card>
</addressBook>
<addressBook>
<card><email>js@example.com</email><name>John Smith</name></card>
</addressBook>
<element name="addressBook" xmlns="http://relaxng.org/ns/structure/1.0">
<zeroOrMore>
<element name="card">
<attribute name="email"/>
</element>
</zeroOrMore>
</element>
<addressBook>
<card email="js@example.com"/>
</addressBook>
<element name="x" xmlns="http://relaxng.org/ns/structure/1.0"/>
<element name="addressBook" xmlns="http://relaxng.org/ns/structure/1.0">
<zeroOrMore>
<element name="card">
<element name="name">
<text/>
</element>
<element name="email">
<text/>
</element>
<optional>
<element name="prefersHTML">
<empty/>
</element>
</optional>
</element>
</zeroOrMore>
</element>
<addressBook>
<card><name>foo</name><email>bar</email><prefersHTML/></card>
<card><name>foo</name><email>bar</email></card>
</addressBook>
<element name="card" xmlns="http://relaxng.org/ns/structure/1.0">
<attribute name="email">
<text/>
</attribute>
</element>
<grammar xmlns="http://relaxng.org/ns/structure/1.0">
<start>
<element name="addressBook">
<zeroOrMore>
<element name="card">
<ref name="cardContent"/>
</element>
</zeroOrMore>
</element>
</start>
<define name="cardContent">
<element name="name">
<text/>
</element>