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
This commit is contained in:
Daniel Veillard 2003-01-23 18:29:16 +00:00
parent 814a76db87
commit 6eadf63ca6
81 changed files with 3316 additions and 6 deletions

View File

@ -1,3 +1,11 @@
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

View File

@ -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 -)

View File

@ -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

62
include/libxml/relaxng.h Normal file
View File

@ -0,0 +1,62 @@
/*
* 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__ */

2662
relaxng.c Normal file

File diff suppressed because it is too large Load Diff

1
result/relaxng/spec1_1 Normal file
View File

@ -0,0 +1 @@
./test/relaxng/spec1_1.xml validates

View File

@ -0,0 +1,5 @@
xmlRelaxNGValidateDefinition(): validated empty
xmlRelaxNGValidateDefinition(): validated bar1 : 0
xmlRelaxNGValidateDefinition(): validated empty
xmlRelaxNGValidateDefinition(): validated bar2 : 0
xmlRelaxNGValidateDefinition(): validated foo : 0

View File

@ -0,0 +1 @@
./test/relaxng/tutor1_1_1.xml validates

View File

@ -0,0 +1,7 @@
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

View File

@ -0,0 +1 @@
./test/relaxng/tutor1_2_1.xml validates

View File

@ -0,0 +1,7 @@
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

View File

@ -0,0 +1 @@
./test/relaxng/tutor1_3_1.xml validates

View File

@ -0,0 +1,7 @@
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

View File

@ -0,0 +1 @@
./test/relaxng/tutor1_4_1.xml validates

View File

@ -0,0 +1,7 @@
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

View File

@ -0,0 +1 @@
./test/relaxng/tutor2_1_1.xml validates

View File

@ -0,0 +1,8 @@
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

View File

@ -0,0 +1 @@
./test/relaxng/tutor3_1_1.xml validates

View File

@ -0,0 +1,4 @@
xmlRelaxNGValidateAttribute(email): 0
xmlRelaxNGValidateAttribute(name): 0
xmlRelaxNGValidateDefinition(): validated card : 0
xmlRelaxNGValidateDefinition(): validated addressBook : 0

View File

@ -0,0 +1 @@
./test/relaxng/tutor3_1_2.xml validates

View File

@ -0,0 +1,4 @@
xmlRelaxNGValidateAttribute(email): 0
xmlRelaxNGValidateAttribute(name): 0
xmlRelaxNGValidateDefinition(): validated card : 0
xmlRelaxNGValidateDefinition(): validated addressBook : 0

View File

@ -0,0 +1,3 @@
Expecting element name, got email
Extra content for element card
./test/relaxng/tutor3_2_1.xml validation generated an internal error

View File

@ -0,0 +1,3 @@
error detected at relaxng.c:2365
error detected at relaxng.c:2413
xmlRelaxNGValidateDefinition(): validated card : -1

View File

@ -0,0 +1 @@
./test/relaxng/tutor3_3_1.xml validates

View File

@ -0,0 +1,9 @@
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

View File

@ -0,0 +1 @@
./test/relaxng/tutor3_4_1.xml validates

View File

@ -0,0 +1,9 @@
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

View File

@ -0,0 +1 @@
./test/relaxng/tutor3_5_1.xml validates

View File

@ -0,0 +1,16 @@
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

View File

@ -0,0 +1,2 @@
Extra content for element addressBook
./test/relaxng/tutor3_5_2.xml validation generated an internal error

View File

@ -0,0 +1,5 @@
xmlRelaxNGValidateAttribute(name): -1
xmlRelaxNGValidateDefinition(): validated email : 0
xmlRelaxNGValidateDefinition(): validated card : -1
error detected at relaxng.c:2413
xmlRelaxNGValidateDefinition(): validated addressBook : -1

View File

@ -0,0 +1 @@
./test/relaxng/tutor3_6_1.xml validates

View File

@ -0,0 +1,3 @@
xmlRelaxNGValidateAttribute(email): 0
xmlRelaxNGValidateDefinition(): validated card : 0
xmlRelaxNGValidateDefinition(): validated addressBook : 0

View File

@ -0,0 +1 @@
Relax-NG schema ./test/relaxng/tutor3_7.rng failed to compile

View File

@ -0,0 +1 @@
xmlRelaxNGParseElement: element has no content

View File

@ -0,0 +1 @@
./test/relaxng/tutor3_8_1.xml validates

View File

@ -0,0 +1,9 @@
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

View File

@ -0,0 +1 @@
./test/relaxng/tutor3_9_1.xml validates

View File

@ -0,0 +1,2 @@
xmlRelaxNGValidateAttribute(email): 0
xmlRelaxNGValidateDefinition(): validated card : 0

View File

@ -0,0 +1 @@
./test/relaxng/tutor4_1_1.xml validates

View File

@ -0,0 +1,8 @@
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

View File

@ -0,0 +1 @@
./test/relaxng/tutor4_2_1.xml validates

View File

@ -0,0 +1,8 @@
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

14
test/relaxng/spec1.rng Normal file
View File

@ -0,0 +1,14 @@
<?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>

3
test/relaxng/spec1_1.xml Normal file
View File

@ -0,0 +1,3 @@
<?xml version="1.0"?>
<foo><pre1:bar1 xmlns:pre1="http://www.example.com/n1"/><pre2:bar2 xmlns:pre2="http://www.example.com/n2"/></foo>

12
test/relaxng/tutor1_1.rng Normal file
View File

@ -0,0 +1,12 @@
<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>

View File

@ -0,0 +1,10 @@
<addressBook>
<card>
<name>John Smith</name>
<email>js@example.com</email>
</card>
<card>
<name>Fred Bloggs</name>
<email>fb@example.net</email>
</card>
</addressBook>

12
test/relaxng/tutor1_2.rng Normal file
View File

@ -0,0 +1,12 @@
<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>

View File

@ -0,0 +1,10 @@
<addressBook>
<card>
<name>John Smith</name>
<email>js@example.com</email>
</card>
<card>
<name>Fred Bloggs</name>
<email>fb@example.net</email>
</card>
</addressBook>

17
test/relaxng/tutor1_3.rng Normal file
View File

@ -0,0 +1,17 @@
<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>

View File

@ -0,0 +1,10 @@
<addressBook>
<card>
<name>John Smith</name>
<email>js@example.com</email>
</card>
<card>
<name>Fred Bloggs</name>
<email>fb@example.net</email>
</card>
</addressBook>

12
test/relaxng/tutor1_4.rng Normal file
View File

@ -0,0 +1,12 @@
<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>

View File

@ -0,0 +1,10 @@
<addressBook>
<card>
<name>John Smith</name>
<email>js@example.com</email>
</card>
<card>
<name>Fred Bloggs</name>
<email>fb@example.net</email>
</card>
</addressBook>

27
test/relaxng/tutor2_1.rng Normal file
View File

@ -0,0 +1,27 @@
<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>

View File

@ -0,0 +1,11 @@
<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>

12
test/relaxng/tutor3_1.rng Normal file
View File

@ -0,0 +1,12 @@
<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>

View File

@ -0,0 +1,3 @@
<addressBook>
<card name="John Smith" email="js@example.com"/>
</addressBook>

View File

@ -0,0 +1,3 @@
<addressBook>
<card email="js@example.com" name="John Smith"/>
</addressBook>

View File

@ -0,0 +1,8 @@
<element name="card" xmlns="http://relaxng.org/ns/structure/1.0">
<element name="name">
<text/>
</element>
<element name="email">
<text/>
</element>
</element>

View File

@ -0,0 +1 @@
<card><email>js@example.com</email><name>John Smith</name></card>

17
test/relaxng/tutor3_3.rng Normal file
View File

@ -0,0 +1,17 @@
<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>

View File

@ -0,0 +1,4 @@
<addressBook>
<card name="foo" email="bar"/>
<card name="foo2" note="second" email="bar2"/>
</addressBook>

22
test/relaxng/tutor3_4.rng Normal file
View File

@ -0,0 +1,22 @@
<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>

View File

@ -0,0 +1,4 @@
<addressBook>
<card name="foo" email="bar"/>
<card givenName="d" familyName="v" email="bar"/>
</addressBook>

22
test/relaxng/tutor3_5.rng Normal file
View File

@ -0,0 +1,22 @@
<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>

View File

@ -0,0 +1,7 @@
<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>

View File

@ -0,0 +1,3 @@
<addressBook>
<card><email>js@example.com</email><name>John Smith</name></card>
</addressBook>

View File

@ -0,0 +1,8 @@
<element name="addressBook" xmlns="http://relaxng.org/ns/structure/1.0">
<zeroOrMore>
<element name="card">
<attribute name="email"/>
</element>
</zeroOrMore>
</element>

View File

@ -0,0 +1,3 @@
<addressBook>
<card email="js@example.com"/>
</addressBook>

View File

@ -0,0 +1,2 @@
<element name="x" xmlns="http://relaxng.org/ns/structure/1.0"/>

View File

@ -0,0 +1 @@
<x/>

17
test/relaxng/tutor3_8.rng Normal file
View File

@ -0,0 +1,17 @@
<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>

View File

@ -0,0 +1,4 @@
<addressBook>
<card><name>foo</name><email>bar</email><prefersHTML/></card>
<card><name>foo</name><email>bar</email></card>
</addressBook>

View File

@ -0,0 +1,5 @@
<element name="card" xmlns="http://relaxng.org/ns/structure/1.0">
<attribute name="email">
<text/>
</attribute>
</element>

View File

@ -0,0 +1 @@
<card email="foo"/>

22
test/relaxng/tutor4_1.rng Normal file
View File

@ -0,0 +1,22 @@
<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>
<element name="email">
<text/>
</element>
</define>
</grammar>

View File

@ -0,0 +1,4 @@
<addressBook>
<card><name>John Smith</name><email>js@example.com"</email></card>
<card><name>John Smith2</name><email>js2@example.com"</email></card>
</addressBook>

34
test/relaxng/tutor4_2.rng Normal file
View File

@ -0,0 +1,34 @@
<grammar xmlns="http://relaxng.org/ns/structure/1.0">
<start>
<ref name="AddressBook"/>
</start>
<define name="AddressBook">
<element name="addressBook">
<zeroOrMore>
<ref name="Card"/>
</zeroOrMore>
</element>
</define>
<define name="Card">
<element name="card">
<ref name="Name"/>
<ref name="Email"/>
</element>
</define>
<define name="Name">
<element name="name">
<text/>
</element>
</define>
<define name="Email">
<element name="email">
<text/>
</element>
</define>
</grammar>

View File

@ -0,0 +1,4 @@
<addressBook>
<card><name>John Smith</name><email>js@example.com"</email></card>
<card><name>John Smith2</name><email>js2@example.com"</email></card>
</addressBook>

19
test/relaxng/tutor4_3.rng Normal file
View File

@ -0,0 +1,19 @@
<define name="inline" xmlns="http://relaxng.org/ns/structure/1.0">
<zeroOrMore>
<choice>
<text/>
<element name="bold">
<ref name="inline"/>
</element>
<element name="italic">
<ref name="inline"/>
</element>
<element name="span">
<optional>
<attribute name="style"/>
</optional>
<ref name="inline"/>
</element>
</choice>
</zeroOrMore>
</define>

20
test/relaxng/tutor4_4.rng Normal file
View File

@ -0,0 +1,20 @@
<define name="inline">
<choice>
<text/>
<element name="bold">
<ref name="inline"/>
</element>
<element name="italic">
<ref name="inline"/>
</element>
<element name="span">
<optional>
<attribute name="style"/>
</optional>
<ref name="inline"/>
</element>
</choice>
<optional>
<ref name="inline"/>
</optional>
</define>