-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathspec-20011203.html
1389 lines (1307 loc) · 136 KB
/
spec-20011203.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<html><head>
<META http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>RELAX NG Specification</title><link rel="stylesheet" href="tr.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.40"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="article"><div class="titlepage"><p class="logo"><a href="http://www.oasis-open.org/"><img src="oasis.png" alt="OASIS" border="0"></a></p><div><h1 class="title"><a name="IDAHAYR"></a>RELAX NG Specification</h1></div><div><h2>Committee Specification 3 December 2001</h2></div><div><dl><dt>This version:</dt><dd>Committee Specification: 3 December 2001</dd></dl><dl><dt>Previous versions:</dt><dd>Committee Specification: 11 August 2001</dd></dl></div><div><dl><dt>Editors:</dt><dd>James Clark <tt><<a href="mailto:[email protected]">[email protected]</a>></tt>, MURATA Makoto <tt><<a href="mailto:[email protected]">[email protected]</a>></tt></dd></dl></div><div></div><div><div class="legalnotice"><p>Copyright © The Organization for the Advancement of
Structured Information Standards [OASIS] 2001. All Rights
Reserved.</p><p>This document and translations of it may be copied and furnished
to others, and derivative works that comment on or otherwise explain
it or assist in its implementation may be prepared, copied, published
and distributed, in whole or in part, without restriction of any kind,
provided that the above copyright notice and this paragraph are
included on all such copies and derivative works. However, this
document itself may not be modified in any way, such as by removing
the copyright notice or references to OASIS, except as needed for the
purpose of developing OASIS specifications, in which case the
procedures for copyrights defined in the OASIS Intellectual Property
Rights document must be followed, or as required to translate it into
languages other than English.</p><p>The limited permissions granted above are perpetual and will not
be revoked by OASIS or its successors or assigns.</p><p>This document and the information contained herein is provided
on an "AS IS" basis and OASIS DISCLAIMS ALL WARRANTIES,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE
USE OF THE INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY
IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
PURPOSE.</p></div></div><div><hr><div class="abstract"><h2><a name="IDANCYR"></a>Abstract</h2><p>This is the definitive specification of RELAX NG, a simple
schema language for XML, based on <a href="#relax" title="[RELAX]">[RELAX]</a> and <a href="#trex" title="[TREX]">[TREX]</a>. A RELAX NG schema specifies a pattern for the
structure and content of an XML document. A RELAX NG schema is itself
an XML document.</p></div></div><div><div class="legalnotice"><h2>Status of this Document</h2><p>This Committee Specification was approved for publication by the
OASIS RELAX NG technical committee. It is a stable document which
represents the consensus of the committee. Comments on this document
may be sent to <a href="mailto:[email protected]" target="_top">[email protected]</a>.</p><p>A list of known errors in this document is available at <a href="http://www.oasis-open.org/committees/relax-ng/spec-20011203-errata.html" target="_top">http://www.oasis-open.org/committees/relax-ng/spec-20011203-errata.html</a>.</p></div></div></div><div class="toc"><h2>Table of Contents</h2><dl><dt>1 <a href="#IDAGDYR">Introduction</a></dt><dt>2 <a href="#data-model">Data model</a></dt><dd><dl><dt>2.1 <a href="#data-model-example">Example</a></dt></dl></dd><dt>3 <a href="#full-syntax">Full syntax</a></dt><dd><dl><dt>3.1 <a href="#full-syntax-example">Example</a></dt></dl></dd><dt>4 <a href="#simplification">Simplification</a></dt><dd><dl><dt>4.1 <a href="#IDARXYR">Annotations</a></dt><dt>4.2 <a href="#IDADYYR">Whitespace</a></dt><dt>4.3 <a href="#IDAXYYR"><tt>datatypeLibrary</tt> attribute</a></dt><dt>4.4 <a href="#IDA0ZYR"><tt>type</tt> attribute of <tt>value</tt> element</a></dt><dt>4.5 <a href="#href"><tt>href</tt> attribute</a></dt><dt>4.6 <a href="#IDAJ2YR"><tt>externalRef</tt> element</a></dt><dt>4.7 <a href="#IDAG3YR"><tt>include</tt> element</a></dt><dt>4.8 <a href="#IDAEAZR"><tt>name</tt> attribute of <tt>element</tt>
and <tt>attribute</tt> elements</a></dt><dt>4.9 <a href="#IDAEBZR"><tt>ns</tt> attribute</a></dt><dt>4.10 <a href="#IDA4CZR">QNames</a></dt><dt>4.11 <a href="#IDAODZR"><tt>div</tt> element</a></dt><dt>4.12 <a href="#number-child-elements">Number of child elements</a></dt><dt>4.13 <a href="#IDA0FZR"><tt>mixed</tt> element</a></dt><dt>4.14 <a href="#IDAQGZR"><tt>optional</tt> element</a></dt><dt>4.15 <a href="#IDAGHZR"><tt>zeroOrMore</tt> element</a></dt><dt>4.16 <a href="#constraints">Constraints</a></dt><dt>4.17 <a href="#IDA0KZR"><tt>combine</tt> attribute</a></dt><dt>4.18 <a href="#IDASNZR"><tt>grammar</tt> element</a></dt><dt>4.19 <a href="#define-ref"><tt>define</tt> and <tt>ref</tt> elements</a></dt><dt>4.20 <a href="#notAllowed"><tt>notAllowed</tt> element</a></dt><dt>4.21 <a href="#IDA1UZR"><tt>empty</tt> element</a></dt></dl></dd><dt>5 <a href="#simple-syntax">Simple syntax</a></dt><dd><dl><dt>5.1 <a href="#simple-syntax-example">Example</a></dt></dl></dd><dt>6 <a href="#semantics">Semantics</a></dt><dd><dl><dt>6.1 <a href="#name-classes">Name classes</a></dt><dt>6.2 <a href="#IDAME0R">Patterns</a></dt><dd><dl><dt>6.2.1 <a href="#choice-pattern"><tt>choice</tt> pattern</a></dt><dt>6.2.2 <a href="#IDAEK0R"><tt>group</tt> pattern</a></dt><dt>6.2.3 <a href="#empty-pattern"><tt>empty</tt> pattern</a></dt><dt>6.2.4 <a href="#text-pattern"><tt>text</tt> pattern</a></dt><dt>6.2.5 <a href="#IDALU0R"><tt>oneOrMore</tt> pattern</a></dt><dt>6.2.6 <a href="#IDA2Z0R"><tt>interleave</tt> pattern</a></dt><dt>6.2.7 <a href="#element-pattern"><tt>element</tt> and <tt>attribute</tt> pattern</a></dt><dt>6.2.8 <a href="#data-pattern"><tt>data</tt> and <tt>value</tt> pattern</a></dt><dt>6.2.9 <a href="#built-in-datatype">Built-in datatype library</a></dt><dt>6.2.10 <a href="#IDACKAS"><tt>list</tt> pattern</a></dt></dl></dd><dt>6.3 <a href="#validity">Validity</a></dt><dt>6.4 <a href="#IDAHPAS">Example</a></dt></dl></dd><dt>7 <a href="#restriction">Restrictions</a></dt><dd><dl><dt>7.1 <a href="#contextual-restriction">Contextual restrictions</a></dt><dd><dl><dt>7.1.1 <a href="#IDA3LBS"><tt>attribute</tt> pattern</a></dt><dt>7.1.2 <a href="#IDAPMBS"><tt>oneOrMore</tt> pattern</a></dt><dt>7.1.3 <a href="#list-restrictions"><tt>list</tt> pattern</a></dt><dt>7.1.4 <a href="#context-data-except"><tt>except</tt> in <tt>data</tt> pattern</a></dt><dt>7.1.5 <a href="#context-start"><tt>start</tt> element</a></dt></dl></dd><dt>7.2 <a href="#string-sequences">String sequences</a></dt><dt>7.3 <a href="#attribute-restrictions">Restrictions on attributes</a></dt><dt>7.4 <a href="#interleave-restrictions">Restrictions on <tt>interleave</tt></a></dt></dl></dd><dt>8 <a href="#conformance">Conformance</a></dt></dl><h3>Appendixes</h3><dl><dt>A <a href="#IDA5MCS">RELAX NG schema for RELAX NG</a></dt><dt>B <a href="#IDAGNCS">Changes since version 0.9</a></dt><dt>C <a href="#IDAPRCS">RELAX NG TC (Non-Normative)</a></dt><dt><a href="#IDAPSCS">References</a></dt></dl></div><hr><div class="section"><a name="IDAGDYR"></a><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="IDAGDYR"></a>1. Introduction</h2></div></div><p>This document specifies</p><div class="itemizedlist"><ul><li><a name="IDAMDYR"></a>when an XML document is a correct RELAX NG
schema</li><li><a name="IDAPDYR"></a>when an XML document is valid with respect to a
correct RELAX NG schema</li></ul></div><p>An XML document that is being validated with respect to a RELAX NG
schema is referred to as an instance.</p><p>The structure of this document is as follows. <a href="#data-model" title="2. Data model">Section 2</a> describes the data model, which is the
abstraction of an XML document used throughout the rest of the
document. <a href="#full-syntax" title="3. Full syntax">Section 3</a> describes the syntax of a
RELAX NG schema; any correct RELAX NG schema must conform to this
syntax. <a href="#simplification" title="4. Simplification">Section 4</a> describes a sequence of
transformations that are applied to simplify a RELAX NG schema;
applying the transformations also involves checking certain
restrictions that must be satisfied by a correct RELAX NG
schema. <a href="#simple-syntax" title="5. Simple syntax">Section 5</a> describes the syntax that
results from applying the transformations; this simple syntax is a
subset of the full syntax. <a href="#semantics" title="6. Semantics">Section 6</a> describes the
semantics of a correct RELAX NG schema that uses the simple syntax;
the semantics specify when an element is valid with respect to a RELAX
NG schema. <a href="#restriction" title="7. Restrictions">Section 7</a> describes restrictions in
terms of the simple syntax; a correct RELAX NG schema must be such
that, after transformation into the simple form, it satisfies these
restrictions. Finally, <a href="#conformance" title="8. Conformance">Section 8</a> describes
conformance requirements for RELAX NG validators.</p><p>A tutorial is available separately (see <a href="#tutorial" title="[Tutorial]">[Tutorial]</a>).</p></div><div class="section"><a name="data-model"></a><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="data-model"></a>2. Data model</h2></div></div><p>RELAX NG deals with XML documents representing both schemas and
instances through an abstract data model. XML documents representing
schemas and instances must be well-formed in conformance with <a href="#xml-rec" title="[XML 1.0]">[XML 1.0]</a> and must conform to the constraints of <a href="#xml-names" title="[XML Namespaces]">[XML Namespaces]</a>.</p><p>An XML document is represented by an element. An element consists
of</p><div class="itemizedlist"><ul><li><a name="IDACFYR"></a>a name</li><li><a name="IDAFFYR"></a>a context</li><li><a name="IDAIFYR"></a>a set of attributes</li><li><a name="IDALFYR"></a>an ordered sequence of zero or more children; each
child is either an element or a non-empty string; the sequence never contains
two consecutive strings</li></ul></div><p>A name consists of</p><div class="itemizedlist"><ul><li><a name="IDASFYR"></a>a string representing the namespace URI; the empty
string has special significance, representing the absence of any
namespace</li><li><a name="IDAVFYR"></a>a string representing the local name; this string matches the NCName
production of <a href="#xml-names" title="[XML Namespaces]">[XML Namespaces]</a></li></ul></div><p>A context consists of</p><div class="itemizedlist"><ul><li><a name="IDA4FYR"></a>a base URI</li><li><a name="IDABGYR"></a>a namespace map; this maps prefixes to namespace URIs,
and also may specify a default namespace URI (as declared
by the <tt>xmlns</tt> attribute)</li></ul></div><p>An attribute consists of</p><div class="itemizedlist"><ul><li><a name="IDAKGYR"></a>a name</li><li><a name="IDANGYR"></a>a string representing the value</li></ul></div><p>A string consists of a sequence of zero or more characters,
where a character is as defined in <a href="#xml-rec" title="[XML 1.0]">[XML 1.0]</a>.</p><p>The element for an XML document is constructed from an instance
of the <a href="#infoset" title="[XML Infoset]">[XML Infoset]</a> as follows. We use the notation
[<i><tt>x</tt></i>] to refer to the value of the
<i><tt>x</tt></i> property of an information item. An
element is constructed from a document information item by
constructing an element from the [document element]. An element is
constructed from an element information item by constructing the name
from the [namespace name] and [local name], the context from the [base
URI] and [in-scope namespaces], the attributes from the [attributes],
and the children from the [children]. The attributes of an element
are constructed from the unordered set of attribute information items
by constructing an attribute for each attribute information item. The
children of an element are constructed from the list of child
information items first by removing information items other than
element information items and character information items, and then by
constructing an element for each element information item in the list
and a string for each maximal sequence of character information items.
An attribute is constructed from an attribute information item by
constructing the name from the [namespace name] and [local name], and
the value from the [normalized value]. When constructing the name of
an element or attribute from the [namespace name] and [local name], if
the [namespace name] property is not present, then the name is
constructed from an empty string and the [local name]. A string is
constructed from a sequence of character information items by
constructing a character from the [character code] of each character
information item.</p><p>It is possible for there to be multiple distinct infosets for a
single XML document. This is because XML parsers are not required to
process all DTD declarations or expand all external parsed general
entities. Amongst these multiple infosets, there is exactly one
infoset for which [all declarations processed] is true and which does
not contain any unexpanded entity reference information items. This
is the infoset that is the basis for defining the RELAX NG data
model.</p><div class="section"><a name="data-model-example"></a><div class="titlepage"><div><h3 class="title"><a name="data-model-example"></a>2.1. Example</h3></div></div><p>Suppose the document
<tt>http://www.example.com/doc.xml</tt> is as
follows:</p><pre class="programlisting"><?xml version="1.0"?>
<foo><pre1:bar1 xmlns:pre1="http://www.example.com/n1"/><pre2:bar2
xmlns:pre2="http://www.example.com/n2"/></foo>
</pre><p>The element representing this document has</p><div class="itemizedlist"><ul><li><a name="IDAQHYR"></a>a name which has<div class="itemizedlist"><ul><li><a name="IDAUHYR"></a>the empty string as the namespace URI, representing
the absence of any namespace</li><li><a name="IDAXHYR"></a><tt>foo</tt> as the local
name</li></ul></div></li><li><a name="IDA4HYR"></a>a context which has<div class="itemizedlist"><ul><li><a name="IDAFQYR"></a><tt>http://www.example.com/doc.xml</tt> as the base
URI</li><li><a name="IDAKQYR"></a>a namespace map which<div class="itemizedlist"><ul><li><a name="IDAOQYR"></a>maps the prefix <tt>xml</tt> to the
namespace URI
<tt>http://www.w3.org/XML/1998/namespace</tt>
(the <tt>xml</tt> prefix is implicitly declared
by every XML document)</li><li><a name="IDAXQYR"></a>specifies the empty string as the default namespace
URI</li></ul></div></li></ul></div></li><li><a name="IDA4QYR"></a>an empty set of attributes</li><li><a name="IDABRYR"></a>a sequence of children consisting
of an element which has<div class="itemizedlist"><ul><li><a name="IDAFRYR"></a>a name which has<div class="itemizedlist"><ul><li><a name="IDAJRYR"></a><tt>http://www.example.com/n1</tt> as the
namespace URI</li><li><a name="IDAORYR"></a><tt>bar1</tt> as the local
name</li></ul></div></li><li><a name="IDAVRYR"></a>a context which has<div class="itemizedlist"><ul><li><a name="IDAZRYR"></a><tt>http://www.example.com/doc.xml</tt> as the base
URI</li><li><a name="IDA4RYR"></a>a namespace map which<div class="itemizedlist"><ul><li><a name="IDACSYR"></a>maps the prefix <tt>pre1</tt> to the
namespace URI
<tt>http://www.example.com/n1</tt></li><li><a name="IDAISYR"></a>maps the prefix <tt>xml</tt> to the
namespace URI
<tt>http://www.w3.org/XML/1998/namespace</tt></li><li><a name="IDAOSYR"></a>specifies the empty string as the default namespace
URI</li></ul></div></li></ul></div></li><li><a name="IDAVSYR"></a>an empty set of attributes</li><li><a name="IDAYSYR"></a>an empty sequence of children</li></ul></div><p>followed by an element which has</p><div class="itemizedlist"><ul><li><a name="IDA5SYR"></a>a name which has<div class="itemizedlist"><ul><li><a name="IDADTYR"></a><tt>http://www.example.com/n2</tt> as the
namespace URI</li><li><a name="IDAITYR"></a><tt>bar2</tt> as the local
name</li></ul></div></li><li><a name="IDAPTYR"></a>a context which has<div class="itemizedlist"><ul><li><a name="IDATTYR"></a><tt>http://www.example.com/doc.xml</tt> as the base
URI</li><li><a name="IDAYTYR"></a>a namespace map which<div class="itemizedlist"><ul><li><a name="IDA2TYR"></a>maps the prefix <tt>pre2</tt> to the
namespace URI
<tt>http://www.example.com/n2</tt></li><li><a name="IDACUYR"></a>maps the prefix <tt>xml</tt> to the
namespace URI
<tt>http://www.w3.org/XML/1998/namespace</tt></li><li><a name="IDAIUYR"></a>specifies the empty string as the default namespace
URI</li></ul></div></li></ul></div></li><li><a name="IDAPUYR"></a>an empty set of attributes</li><li><a name="IDASUYR"></a>an empty sequence of children</li></ul></div></li></ul></div></div></div><div class="section"><a name="full-syntax"></a><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="full-syntax"></a>3. Full syntax</h2></div></div><p>The following grammar summarizes the syntax of RELAX NG.
Although we use a notation based on the XML representation of an RELAX
NG schema as a sequence of characters, the grammar must be understood
as operating at the data model level. For example, although the
syntax uses <tt><text/></tt>, an instance or
schema can use <tt><text></text></tt> instead,
because they both represent the same element at the data model level.
All elements shown in the grammar are qualified with the namespace
URI:</p><pre class="programlisting">http://relaxng.org/ns/structure/1.0</pre><p>The symbols QName and NCName are defined in <a href="#xml-names" title="[XML Namespaces]">[XML Namespaces]</a>. The anyURI symbol has the same meaning as the
anyURI datatype of <a href="#xmlschema-2" title="[W3C XML Schema Datatypes]">[W3C XML Schema Datatypes]</a>: it indicates a
string that, after escaping of disallowed values as described in
Section 5.4 of <a href="#xlink" title="[XLink]">[XLink]</a>, is a URI reference as defined
in <a href="#rfc2396" title="[RFC 2396]">[RFC 2396]</a> (as modified by <a href="#rfc2732" title="[RFC 2732]">[RFC 2732]</a>). The symbol string matches any string.</p><p>In addition to the attributes shown explicitly, any element can
have an <tt>ns</tt> attribute and any element can have a
<tt>datatypeLibrary</tt> attribute. The
<tt>ns</tt> attribute can have any value. The value of the
<tt>datatypeLibrary</tt> attribute must match the anyURI
symbol as described in the previous paragraph; in addition, it must
not use the relative form of URI reference and must not have a
fragment identifier; as an exception to this, the value may be the
empty string.</p><p>Any element can also have foreign attributes in addition to the
attributes shown in the grammar. A foreign attribute is an attribute
with a name whose namespace URI is neither the empty string nor the
RELAX NG namespace URI. Any element that cannot have string children
(that is, any element other than <tt>value</tt>, <tt>param</tt>
and <tt>name</tt>) may have foreign child elements in addition
to the child elements shown in the grammar. A foreign element is an
element with a name whose namespace URI is not the RELAX NG namespace
URI. There are no constraints on the relative position of foreign
child elements with respect to other child elements.</p><p>Any element can also have as children strings that consist
entirely of whitespace characters, where a whitespace character is one
of #x20, #x9, #xD or #xA. There are no constraints on the relative
position of whitespace string children with respect to child
elements.</p><p>Leading and trailing whitespace is allowed for value of each
<tt>name</tt>, <tt>type</tt> and
<tt>combine</tt> attribute and for the content of each
<tt>name</tt> element.</p><table><tr valign="baseline"><td>pattern</td><td> ::= </td><td><code><element</code> <code>name="</code><i>QName</i><code>"</code><code>> </code><i>pattern</i>+<code> </element></code><br>| <code><element</code><code>> </code><i>nameClass</i> <i>pattern</i>+<code> </element></code><br>| <code><attribute</code> <code>name="</code><i>QName</i><code>"</code><code>> </code>[<i>pattern</i>]<code> </attribute></code><br>| <code><attribute</code><code>> </code><i>nameClass</i> [<i>pattern</i>]<code> </attribute></code><br>| <code><group</code><code>> </code><i>pattern</i>+<code> </group></code><br>| <code><interleave</code><code>> </code><i>pattern</i>+<code> </interleave></code><br>| <code><choice</code><code>> </code><i>pattern</i>+<code> </choice></code><br>| <code><optional</code><code>> </code><i>pattern</i>+<code> </optional></code><br>| <code><zeroOrMore</code><code>> </code><i>pattern</i>+<code> </zeroOrMore></code><br>| <code><oneOrMore</code><code>> </code><i>pattern</i>+<code> </oneOrMore></code><br>| <code><list</code><code>> </code><i>pattern</i>+<code> </list></code><br>| <code><mixed</code><code>> </code><i>pattern</i>+<code> </mixed></code><br>| <code><ref</code> <code>name="</code><i>NCName</i><code>"</code><code>/></code><br>| <code><parentRef</code> <code>name="</code><i>NCName</i><code>"</code><code>/></code><br>| <code><empty</code><code>/></code><br>| <code><text</code><code>/></code><br>| <code><value</code> [<code>type="</code><i>NCName</i><code>"</code>]<code>> </code><i>string</i><code> </value></code><br>| <code><data</code> <code>type="</code><i>NCName</i><code>"</code><code>> </code><i>param</i>* [<i>exceptPattern</i>]<code> </data></code><br>| <code><notAllowed</code><code>/></code><br>| <code><externalRef</code> <code>href="</code><i>anyURI</i><code>"</code><code>/></code><br>| <code><grammar</code><code>> </code><i>grammarContent</i>*<code> </grammar></code></td></tr><tr valign="baseline"><td>param</td><td> ::= </td><td><code><param</code> <code>name="</code><i>NCName</i><code>"</code><code>> </code><i>string</i><code> </param></code></td></tr><tr valign="baseline"><td>exceptPattern</td><td> ::= </td><td><code><except</code><code>> </code><i>pattern</i>+<code> </except></code></td></tr><tr valign="baseline"><td>grammarContent</td><td> ::= </td><td><i>start</i><br>| <i>define</i><br>| <code><div</code><code>> </code><i>grammarContent</i>*<code> </div></code><br>| <code><include</code> <code>href="</code><i>anyURI</i><code>"</code><code>> </code><i>includeContent</i>*<code> </include></code></td></tr><tr valign="baseline"><td>includeContent</td><td> ::= </td><td><i>start</i><br>| <i>define</i><br>| <code><div</code><code>> </code><i>includeContent</i>*<code> </div></code></td></tr><tr valign="baseline"><td>start</td><td> ::= </td><td><code><start</code> [<code>combine="</code><i>method</i><code>"</code>]<code>> </code><i>pattern</i><code> </start></code></td></tr><tr valign="baseline"><td>define</td><td> ::= </td><td><code><define</code> <code>name="</code><i>NCName</i><code>"</code> [<code>combine="</code><i>method</i><code>"</code>]<code>> </code><i>pattern</i>+<code> </define></code></td></tr><tr valign="baseline"><td>method</td><td> ::= </td><td><code>choice</code><br>| <code>interleave</code></td></tr><tr valign="baseline"><td>nameClass</td><td> ::= </td><td><code><name</code><code>> </code><i>QName</i><code> </name></code><br>| <code><anyName</code><code>> </code>[<i>exceptNameClass</i>]<code> </anyName></code><br>| <code><nsName</code><code>> </code>[<i>exceptNameClass</i>]<code> </nsName></code><br>| <code><choice</code><code>> </code><i>nameClass</i>+<code> </choice></code></td></tr><tr valign="baseline"><td>exceptNameClass</td><td> ::= </td><td><code><except</code><code>> </code><i>nameClass</i>+<code> </except></code></td></tr></table><div class="section"><a name="full-syntax-example"></a><div class="titlepage"><div><h3 class="title"><a name="full-syntax-example"></a>3.1. Example</h3></div></div><p>Here is an example of a schema in the full syntax for the
document in <a href="#data-model-example" title="2.1. Example">Section 2.1</a>.</p><pre class="programlisting"><?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:document>
<element name="ex1:bar1">
<empty/>
</element>
<element name="ex2:bar2">
<empty/>
</element>
</element></pre></div></div><div class="section"><a name="simplification"></a><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="simplification"></a>4. Simplification</h2></div></div><p>The full syntax given in the previous section is transformed
into a simpler syntax by applying the following transformation rules
in order. The effect must be as if each rule was applied to all
elements in the schema before the next rule is applied. A
transformation rule may also specify constraints that must be
satisfied by a correct schema. The transformation rules are applied
at the data model level. Before the transformations are applied, the
schema is parsed into an instance of the data model.</p><div class="section"><a name="IDARXYR"></a><div class="titlepage"><div><h3 class="title"><a name="IDARXYR"></a>4.1. Annotations</h3></div></div><p>Foreign attributes and elements are removed.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title"><a name="IDAWXYR"></a>Note</h3><p>It is safe to remove <tt>xml:base</tt>
attributes at this stage because <tt>xml:base</tt>
attributes are used in determining the [base URI] of an element
information item, which is in turn used to construct the base URI of
the context of an element. Thus, after a document has been parsed
into an instance of the data model, <tt>xml:base</tt>
attributes can be discarded.</p></div></div><div class="section"><a name="IDADYYR"></a><div class="titlepage"><div><h3 class="title"><a name="IDADYYR"></a>4.2. Whitespace</h3></div></div><p>For each element other than <tt>value</tt> and
<tt>param</tt>, each child that is a string containing only
whitespace characters is removed.</p><p>Leading and trailing whitespace characters are removed from the
value of each <tt>name</tt>, <tt>type</tt> and
<tt>combine</tt> attribute and from the content of each
<tt>name</tt> element.</p></div><div class="section"><a name="IDAXYYR"></a><div class="titlepage"><div><h3 class="title"><a name="IDAXYYR"></a>4.3. <tt>datatypeLibrary</tt> attribute</h3></div></div><p>The value of each <tt>datatypeLibary</tt> attribute is
transformed by escaping disallowed characters as specified in Section
5.4 of <a href="#xlink" title="[XLink]">[XLink]</a>.</p><p>For any <tt>data</tt> or <tt>value</tt>
element that does not have a <tt>datatypeLibrary</tt>
attribute, a <tt>datatypeLibrary</tt> attribute is
added. The value of the added <tt>datatypeLibrary</tt>
attribute is the value of the <tt>datatypeLibrary</tt>
attribute of the nearest ancestor element that has a
<tt>datatypeLibrary</tt> attribute, or the empty string if
there is no such ancestor. Then, any <tt>datatypeLibrary</tt>
attribute that is on an element other than <tt>data</tt> or
<tt>value</tt> is removed.</p></div><div class="section"><a name="IDA0ZYR"></a><div class="titlepage"><div><h3 class="title"><a name="IDA0ZYR"></a>4.4. <tt>type</tt> attribute of <tt>value</tt> element</h3></div></div><p>For any <tt>value</tt> element that does not have a
<tt>type</tt> attribute, a <tt>type</tt> attribute
is added with value <tt>token</tt> and the value of the
<tt>datatypeLibrary</tt> attribute is changed to the empty
string.</p></div><div class="section"><a name="href"></a><div class="titlepage"><div><h3 class="title"><a name="href"></a>4.5. <tt>href</tt> attribute</h3></div></div><p>The value of the <tt>href</tt> attribute on an
<tt>externalRef</tt> or <tt>include</tt> element
is first transformed by escaping disallowed characters as specified in
Section 5.4 of <a href="#xlink" title="[XLink]">[XLink]</a>. The URI reference is then
resolved into an absolute form as described in section 5.2 of <a href="#rfc2396" title="[RFC 2396]">[RFC 2396]</a> using the base URI from the context of the element
that bears the <tt>href</tt> attribute.</p><p>The value of the <tt>href</tt> attribute will be used
to construct an element (as specified in <a href="#data-model" title="2. Data model">Section 2</a>). This must be done as follows. The URI
reference consists of the URI itself and an optional fragment
identifier. The resource identified by the URI is retrieved. The
result is a MIME entity: a sequence of bytes labeled with a MIME
media type. The media type determines how an element is constructed
from the MIME entity and optional fragment identifier. When the media
type is <tt>application/xml</tt> or
<tt>text/xml</tt>, the MIME entity must be parsed as an XML
document in accordance with the applicable RFC (at the term of writing
<a href="#rfc3023" title="[RFC 3023]">[RFC 3023]</a>) and an element constructed from the result
of the parse as specified in <a href="#data-model" title="2. Data model">Section 2</a>. In
particular, the <tt>charset</tt> parameter must be handled
as specified by the RFC. This specification does not define the
handling of media types other than <tt>application/xml</tt>
and <tt>text/xml</tt>. The <tt>href</tt> attribute
must not include a fragment identifier unless the registration of the
media type of the resource identified by the attribute defines the
interpretation of fragment identifiers for that media type.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title"><a name="IDA41YR"></a>Note</h3><p><a href="#rfc3023" title="[RFC 3023]">[RFC 3023]</a> does not define the
interpretation of fragment identifiers for
<tt>application/xml</tt> or
<tt>text/xml</tt>.</p></div></div><div class="section"><a name="IDAJ2YR"></a><div class="titlepage"><div><h3 class="title"><a name="IDAJ2YR"></a>4.6. <tt>externalRef</tt> element</h3></div></div><p>An <tt>externalRef</tt> element is transformed as
follows. An element is constructed using the URI reference that is
the value of <tt>href</tt> attribute as specified in <a href="#href" title="4.5. href attribute">Section 4.5</a>. This element must match the syntax for pattern. The
element is transformed by recursively applying the rules from this
subsection and from previous subsections of this section. This must
not result in a loop. In other words, the transformation of the
referenced element must not require the dereferencing of an
<tt>externalRef</tt> attribute with an
<tt>href</tt> attribute with the same value.</p><p>Any <tt>ns</tt> attribute on the
<tt>externalRef</tt> element is transferred to the
referenced element if the referenced element does not already have an
<tt>ns</tt> attribute. The <tt>externalRef</tt>
element is then replaced by the referenced element.</p></div><div class="section"><a name="IDAG3YR"></a><div class="titlepage"><div><h3 class="title"><a name="IDAG3YR"></a>4.7. <tt>include</tt> element</h3></div></div><p>An <tt>include</tt> element is transformed as follows.
An element is constructed using the URI reference that is the value of
<tt>href</tt> attribute as specified in <a href="#href" title="4.5. href attribute">Section 4.5</a>. This element must be a <tt>grammar</tt>
element, matching the syntax for grammar.</p><p>This <tt>grammar</tt> element is transformed by
recursively applying the rules from this subsection and from previous
subsections of this section. This must not result in a loop. In other
words, the transformation of the <tt>grammar</tt> element
must not require the dereferencing of an <tt>include</tt>
attribute with an <tt>href</tt> attribute with the same
value.</p><p>Define the <i>components</i> of an element to
be the children of the element together with the components of any
<tt>div</tt> child elements. If the
<tt>include</tt> element has a <tt>start</tt>
component, then the <tt>grammar</tt> element must have a
<tt>start</tt> component. If the <tt>include</tt>
element has a <tt>start</tt> component, then all
<tt>start</tt> components are removed from the
<tt>grammar</tt> element. If the <tt>include</tt>
element has a <tt>define</tt> component, then the
<tt>grammar</tt> element must have a
<tt>define</tt> component with the same name. For every
<tt>define</tt> component of the <tt>include</tt>
element, all <tt>define</tt> components with the same name
are removed from the <tt>grammar</tt> element.</p><p>The <tt>include</tt> element is transformed into a
<tt>div</tt> element. The attributes of the
<tt>div</tt> element are the attributes of the
<tt>include</tt> element other than the
<tt>href</tt> attribute. The children of the
<tt>div</tt> element are the <tt>grammar</tt>
element (after the removal of the <tt>start</tt> and
<tt>define</tt> components described by the preceding
paragraph) followed by the children of the <tt>include</tt>
element. The <tt>grammar</tt> element is then renamed to
<tt>div</tt>.</p></div><div class="section"><a name="IDAEAZR"></a><div class="titlepage"><div><h3 class="title"><a name="IDAEAZR"></a>4.8. <tt>name</tt> attribute of <tt>element</tt>
and <tt>attribute</tt> elements</h3></div></div><p>The <tt>name</tt> attribute on an
<tt>element</tt> or <tt>attribute</tt> element is
transformed into a <tt>name</tt> child element.</p><p>If an <tt>attribute</tt> element has a
<tt>name</tt> attribute but no <tt>ns</tt>
attribute, then an <tt>ns=""</tt> attribute is added to the
<tt>name</tt> child element.</p></div><div class="section"><a name="IDAEBZR"></a><div class="titlepage"><div><h3 class="title"><a name="IDAEBZR"></a>4.9. <tt>ns</tt> attribute</h3></div></div><p>For any <tt>name</tt>, <tt>nsName</tt> or
<tt>value</tt> element that does not have an
<tt>ns</tt> attribute, an <tt>ns</tt> attribute is
added. The value of the added <tt>ns</tt> attribute is the
value of the <tt>ns</tt> attribute of the nearest ancestor
element that has an <tt>ns</tt> attribute, or the empty
string if there is no such ancestor. Then, any <tt>ns</tt>
attribute that is on an element other than <tt>name</tt>,
<tt>nsName</tt> or <tt>value</tt> is
removed.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title"><a name="IDADCZR"></a>Note</h3><p>The value of the <tt>ns</tt> attribute is
<i>not</i> transformed either by escaping
disallowed characters, or in any other way, because the value of the
<tt>ns</tt> attribute is compared against namespace URIs in
the instance, which are not subject to any
transformation.</p></div><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title"><a name="IDAOCZR"></a>Note</h3><p>Since <tt>include</tt> and
<tt>externalRef</tt> elements are resolved after
<tt>datatypeLibrary</tt> attributes are added but before
<tt>ns</tt> attributes are added, <tt>ns</tt>
attributes are inherited into external schemas but
<tt>datatypeLibrary</tt> attributes are not.</p></div></div><div class="section"><a name="IDA4CZR"></a><div class="titlepage"><div><h3 class="title"><a name="IDA4CZR"></a>4.10. QNames</h3></div></div><p>For any <tt>name</tt> element containing a prefix, the
prefix is removed and an <tt>ns</tt> attribute is added
replacing any existing <tt>ns</tt> attribute. The value of
the added <tt>ns</tt> attribute is the value to which the
namespace map of the context of the <tt>name</tt> element
maps the prefix. The context must have a mapping for the
prefix.</p></div><div class="section"><a name="IDAODZR"></a><div class="titlepage"><div><h3 class="title"><a name="IDAODZR"></a>4.11. <tt>div</tt> element</h3></div></div><p>Each <tt>div</tt> element is replaced by its
children.</p></div><div class="section"><a name="number-child-elements"></a><div class="titlepage"><div><h3 class="title"><a name="number-child-elements"></a>4.12. Number of child elements</h3></div></div><p>A <tt>define</tt>, <tt>oneOrMore</tt>,
<tt>zeroOrMore</tt>, <tt>optional</tt>, <tt>list</tt> or
<tt>mixed</tt> element is transformed so that it has exactly
one child element. If it has more than one child element, then its
child elements are wrapped in a <tt>group</tt>
element. Similarly, an <tt>element</tt> element is transformed so
that it has exactly two child elements, the first being a name class
and the second being a pattern. If it has more than two child elements,
then the child elements other than the first are wrapped in a
<tt>group</tt> element.</p><p>A <tt>except</tt> element is transformed
so that it has exactly one child element. If it has more
than one child element, then its child elements are wrapped
in a <tt>choice</tt> element.</p><p>If an <tt>attribute</tt> element has only one child
element (a name class), then a <tt>text</tt> element is
added.</p><p>A <tt>choice</tt>, <tt>group</tt> or
<tt>interleave</tt> element is transformed so that it has
exactly two child elements. If it has one child element, then it is
replaced by its child element. If it has more than two child
elements, then the first two child elements are combined into a new
element with the same name as the parent element and with the first
two child elements as its children. For example,</p><pre class="programlisting"><choice> <i><tt>p1</tt></i> <i><tt>p2</tt></i> <i><tt>p3</tt></i> </choice></pre><p>is transformed to</p><pre class="programlisting"><choice> <choice> <i><tt>p1</tt></i> <i><tt>p2</tt></i> </choice> <i><tt>p3</tt></i> </choice></pre><p>This reduces the number of child elements by one. The
transformation is applied repeatedly until there are exactly two child
elements.</p></div><div class="section"><a name="IDA0FZR"></a><div class="titlepage"><div><h3 class="title"><a name="IDA0FZR"></a>4.13. <tt>mixed</tt> element</h3></div></div><p>A <tt>mixed</tt> element is transformed into an
interleaving with a <tt>text</tt> element:</p><pre class="programlisting"><mixed> <i><tt>p</tt></i> </mixed></pre><p>is transformed into</p><pre class="programlisting"><interleave> <i><tt>p</tt></i> <text/> </interleave></pre></div><div class="section"><a name="IDAQGZR"></a><div class="titlepage"><div><h3 class="title"><a name="IDAQGZR"></a>4.14. <tt>optional</tt> element</h3></div></div><p>An <tt>optional</tt> element is transformed into
a choice with <tt>empty</tt>:</p><pre class="programlisting"><optional> <i><tt>p</tt></i> </optional></pre><p>is transformed into</p><pre class="programlisting"><choice> <i><tt>p</tt></i> <empty/> </choice></pre></div><div class="section"><a name="IDAGHZR"></a><div class="titlepage"><div><h3 class="title"><a name="IDAGHZR"></a>4.15. <tt>zeroOrMore</tt> element</h3></div></div><p>A <tt>zeroOrMore</tt> element is transformed into a choice
between <tt>oneOrMore</tt> and
<tt>empty</tt>:</p><pre class="programlisting"><zeroOrMore> <i><tt>p</tt></i> </zeroOrMore></pre><p>is transformed into</p><pre class="programlisting"><choice> <oneOrMore> <i><tt>p</tt></i> </oneOrMore> <empty/> </choice></pre></div><div class="section"><a name="constraints"></a><div class="titlepage"><div><h3 class="title"><a name="constraints"></a>4.16. Constraints</h3></div></div><p>In this rule, no transformation is performed, but various
constraints are checked.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title"><a name="IDAIIZR"></a>Note</h3><p>The constraints in this section, unlike the constraints
specified in <a href="#restriction" title="7. Restrictions">Section 7</a>, can be checked without
resolving any <tt>ref</tt> elements, and are accordingly
applied even to patterns that will disappear during later stages of
simplification because they are not reachable (see <a href="#define-ref" title="4.19. define and ref elements">Section 4.19</a>) or because of <tt>notAllowed</tt>
(see <a href="#notAllowed" title="4.20. notAllowed element">Section 4.20</a>).</p></div><p>An <tt>except</tt> element that is a child of an
<tt>anyName</tt> element must not have any
<tt>anyName</tt> descendant elements. An
<tt>except</tt> element that is a child of an
<tt>nsName</tt> element must not have any
<tt>nsName</tt> or <tt>anyName</tt> descendant
elements.</p><p>A <tt>name</tt> element that occurs as the first child
of an <tt>attribute</tt> element or as the descendant of the
first child of an <tt>attribute</tt> element and that has an
<tt>ns</tt> attribute with value equal to the empty string
must not have content equal to <tt>xmlns</tt>.</p><p>A <tt>name</tt> or <tt>nsName</tt> element
that occurs as the first child of an <tt>attribute</tt>
element or as the descendant of the first child of an
<tt>attribute</tt> element must not have an
<tt>ns</tt> attribute with value
<tt>http://www.w3.org/2000/xmlns</tt>.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title"><a name="IDACKZR"></a>Note</h3><p>The <a href="#infoset" title="[XML Infoset]">[XML Infoset]</a> defines the namespace URI of
namespace declaration attributes to be
<tt>http://www.w3.org/2000/xmlns</tt>.</p></div><p>A <tt>data</tt> or <tt>value</tt> element
must be correct in its use of datatypes. Specifically, the
<tt>type</tt> attribute must identify a datatype within the
datatype library identified by the value of the
<tt>datatypeLibrary</tt> attribute. For a
<tt>data</tt> element, the parameter list must be one that
is allowed by the datatype (see <a href="#data-pattern" title="6.2.8. data and value pattern">Section 6.2.8</a>).</p></div><div class="section"><a name="IDA0KZR"></a><div class="titlepage"><div><h3 class="title"><a name="IDA0KZR"></a>4.17. <tt>combine</tt> attribute</h3></div></div><p>For each <tt>grammar</tt> element, all
<tt>define</tt> elements with the same name are combined
together. For any name, there must not be more than one
<tt>define</tt> element with that name that does not have a
<tt>combine</tt> attribute. For any name, if there is a
<tt>define</tt> element with that name that has a
<tt>combine</tt> attribute with the value
<tt>choice</tt>, then there must not also be a
<tt>define</tt> element with that name that has a
<tt>combine</tt> attribute with the value
<tt>interleave</tt>. Thus, for any name, if there is more
than one <tt>define</tt> element with that name, then there
is a unique value for the <tt>combine</tt> attribute for
that name. After determining this unique value, the
<tt>combine</tt> attributes are removed. A pair of
definitions</p><pre class="programlisting"><define name="<i><tt>n</tt></i>">
<i><tt>p1</tt></i>
</define>
<define name="<i><tt>n</tt></i>">
<i><tt>p2</tt></i>
</define></pre><p>is combined into</p><pre class="programlisting"><define name="<i><tt>n</tt></i>">
<<i><tt>c</tt></i>>
<i><tt>p1</tt></i>
<i><tt>p2</tt></i>
</<i><tt>c</tt></i>>
</define></pre><p>where <i><tt>c</tt></i> is the value of the
<tt>combine</tt> attribute. Pairs of definitions are
combined until there is exactly one <tt>define</tt> element
for each name.</p><p>Similarly, for each <tt>grammar</tt> element all
<tt>start</tt> elements are combined together. There must
not be more than one <tt>start</tt> element that does not
have a <tt>combine</tt> attribute. If there is a
<tt>start</tt> element that has a <tt>combine</tt>
attribute with the value <tt>choice</tt>, there must not
also be a <tt>start</tt> element that has a
<tt>combine</tt> attribute with the value
<tt>interleave</tt>.</p></div><div class="section"><a name="IDASNZR"></a><div class="titlepage"><div><h3 class="title"><a name="IDASNZR"></a>4.18. <tt>grammar</tt> element</h3></div></div><p>In this rule, the schema is transformed so that its top-level
element is <tt>grammar</tt> and so that it has no other
<tt>grammar</tt> elements.</p><p>Define the <i>in-scope grammar</i> for an
element to be the nearest ancestor <tt>grammar</tt> element. A
<tt>ref</tt> element <i>refers to</i> a
<tt>define</tt> element if the value of their
<tt>name</tt> attributes is the same and their in-scope
grammars are the same. A <tt>parentRef</tt> element
<i>refers to</i> a <tt>define</tt> element
if the value of their <tt>name</tt> attributes is the same
and the in-scope grammar of the in-scope grammar of the
<tt>parentRef</tt> element is the same as the in-scope
grammar of the <tt>define</tt> element. Every
<tt>ref</tt> or <tt>parentRef</tt> element must
refer to a <tt>define</tt> element. A
<tt>grammar</tt> must have a <tt>start</tt> child
element.</p><p>First, transform the top-level pattern
<i><tt>p</tt></i> into
<tt><grammar><start><i><tt>p</tt></i></start></grammar></tt>.
Next, rename <tt>define</tt> elements so that no two
<tt>define</tt> elements anywhere in the schema have the
same name. To rename a <tt>define</tt> element, change the
value of its <tt>name</tt> attribute and change the value of
the <tt>name</tt> attribute of all <tt>ref</tt>
and <tt>parentRef</tt> elements that refer to that
<tt>define</tt> element. Next, move all
<tt>define</tt> elements to be children of the top-level
<tt>grammar</tt> element, replace each nested
<tt>grammar</tt> element by the child of its
<tt>start</tt> element and rename each
<tt>parentRef</tt> element to <tt>ref</tt>.</p></div><div class="section"><a name="define-ref"></a><div class="titlepage"><div><h3 class="title"><a name="define-ref"></a>4.19. <tt>define</tt> and <tt>ref</tt> elements</h3></div></div><p>In this rule, the grammar is transformed so that every
<tt>element</tt> element is the child of a
<tt>define</tt> element, and the child of every
<tt>define</tt> element is an <tt>element</tt>
element.</p><p>First, remove any <tt>define</tt> element that is not
<i>reachable</i>. A <tt>define</tt> element
is reachable if there is reachable <tt>ref</tt> element
referring to it. A <tt>ref</tt> element is reachable if it
is the descendant of the <tt>start</tt> element or of a
reachable <tt>define</tt> element. Now, for
each <tt>element</tt> element that is not the child of a
<tt>define</tt> element, add a <tt>define</tt>
element to the <tt>grammar</tt> element, and replace the
<tt>element</tt> element by a <tt>ref</tt> element
referring to the added <tt>define</tt> element. The value of
the <tt>name</tt> attribute of the added
<tt>define</tt> element must be different from value of the
<tt>name</tt> attribute of all other
<tt>define</tt> elements. The child of the added
<tt>define</tt> element is the <tt>element</tt>
element.</p><p>Define a <tt>ref</tt> element to be
<i>expandable</i> if it refers to a
<tt>define</tt> element whose child is not an
<tt>element</tt> element. For each <tt>ref</tt>
element that is expandable and is a descendant of a
<tt>start</tt> element or an <tt>element</tt>
element, expand it by replacing the <tt>ref</tt> element by
the child of the <tt>define</tt> element to which it refers and
then recursively expanding any expandable <tt>ref</tt>
elements in this replacement. This must not result in a loop.
In other words expanding the replacement of a
<tt>ref</tt> element having a <tt>name</tt> with
value <i><tt>n</tt></i> must not require the expansion of
<tt>ref</tt> element also having a <tt>name</tt>
with value <i><tt>n</tt></i>. Finally, remove any
<tt>define</tt> element whose child is not an
<tt>element</tt> element.</p></div><div class="section"><a name="notAllowed"></a><div class="titlepage"><div><h3 class="title"><a name="notAllowed"></a>4.20. <tt>notAllowed</tt> element</h3></div></div><p>In this rule, the grammar is transformed so that a
<tt>notAllowed</tt> element occurs only as the child of
a <tt>start</tt> or <tt>element</tt> element. An
<tt>attribute</tt>, <tt>list</tt>,
<tt>group</tt>, <tt>interleave</tt>,
or <tt>oneOrMore</tt> element that has a
<tt>notAllowed</tt> child element is transformed into a
<tt>notAllowed</tt> element. A <tt>choice</tt>
element that has two <tt>notAllowed</tt> child elements is
transformed into a <tt>notAllowed</tt> element. A
<tt>choice</tt> element that has one
<tt>notAllowed</tt> child element is transformed into its
other child element. An <tt>except</tt> element that has a
<tt>notAllowed</tt> child element is removed.
The preceding transformations are applied
repeatedly until none of them is applicable any more.
Any <tt>define</tt> element that is no longer reachable
is removed.</p></div><div class="section"><a name="IDA1UZR"></a><div class="titlepage"><div><h3 class="title"><a name="IDA1UZR"></a>4.21. <tt>empty</tt> element</h3></div></div><p>In this rule, the grammar is transformed so that an
<tt>empty</tt> element does not occur as a child of a
<tt>group</tt>, <tt>interleave</tt>, or
<tt>oneOrMore</tt> element or as the second child of
a <tt>choice</tt> element. A <tt>group</tt>,
<tt>interleave</tt> or <tt>choice</tt> element
that has two <tt>empty</tt> child elements is transformed
into an <tt>empty</tt> element. A <tt>group</tt>
or <tt>interleave</tt> element that has one
<tt>empty</tt> child element is transformed into its other
child element. A <tt>choice</tt> element whose
second child element is an <tt>empty</tt> element is
transformed by interchanging its two child elements. A
<tt>oneOrMore</tt> element that has an
<tt>empty</tt> child element is transformed into an
<tt>empty</tt> element. The preceding transformations are applied
repeatedly until none of them is applicable any more.</p></div></div><div class="section"><a name="simple-syntax"></a><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="simple-syntax"></a>5. Simple syntax</h2></div></div><p>After applying all the rules in <a href="#simplification" title="4. Simplification">Section 4</a>, the schema will match the following
grammar:</p><table><tr valign="baseline"><td>grammar</td><td> ::= </td><td><code><grammar</code><code>> </code><code><start</code><code>> </code><i>top</i><code> </start></code> <i>define</i>*<code> </grammar></code></td></tr><tr valign="baseline"><td>define</td><td> ::= </td><td><code><define</code> <code>name="</code><i>NCName</i><code>"</code><code>> </code><code><element</code><code>> </code><i>nameClass</i> <i>top</i><code> </element></code><code> </define></code></td></tr><tr valign="baseline"><td>top</td><td> ::= </td><td><code><notAllowed</code><code>/></code><br>| <i>pattern</i></td></tr><tr valign="baseline"><td>pattern</td><td> ::= </td><td><code><empty</code><code>/></code><br>| <i>nonEmptyPattern</i></td></tr><tr valign="baseline"><td>nonEmptyPattern</td><td> ::= </td><td><code><text</code><code>/></code><br>| <code><data</code> <code>type="</code><i>NCName</i><code>"</code> <code>datatypeLibrary="</code><i>anyURI</i><code>"</code><code>> </code><i>param</i>* [<i>exceptPattern</i>]<code> </data></code><br>| <code><value</code> <code>datatypeLibrary="</code><i>anyURI</i><code>"</code> <code>type="</code><i>NCName</i><code>"</code> <code>ns="</code><i>string</i><code>"</code><code>> </code><i>string</i><code> </value></code><br>| <code><list</code><code>> </code><i>pattern</i><code> </list></code><br>| <code><attribute</code><code>> </code><i>nameClass</i> <i>pattern</i><code> </attribute></code><br>| <code><ref</code> <code>name="</code><i>NCName</i><code>"</code><code>/></code><br>| <code><oneOrMore</code><code>> </code><i>nonEmptyPattern</i><code> </oneOrMore></code><br>| <code><choice</code><code>> </code><i>pattern</i> <i>nonEmptyPattern</i><code> </choice></code><br>| <code><group</code><code>> </code><i>nonEmptyPattern</i> <i>nonEmptyPattern</i><code> </group></code><br>| <code><interleave</code><code>> </code><i>nonEmptyPattern</i> <i>nonEmptyPattern</i><code> </interleave></code></td></tr><tr valign="baseline"><td>param</td><td> ::= </td><td><code><param</code> <code>name="</code><i>NCName</i><code>"</code><code>> </code><i>string</i><code> </param></code></td></tr><tr valign="baseline"><td>exceptPattern</td><td> ::= </td><td><code><except</code><code>> </code><i>pattern</i><code> </except></code></td></tr><tr valign="baseline"><td>nameClass</td><td> ::= </td><td><code><anyName</code><code>> </code>[<i>exceptNameClass</i>]<code> </anyName></code><br>| <code><nsName</code> <code>ns="</code><i>string</i><code>"</code><code>> </code>[<i>exceptNameClass</i>]<code> </nsName></code><br>| <code><name</code> <code>ns="</code><i>string</i><code>"</code><code>> </code><i>NCName</i><code> </name></code><br>| <code><choice</code><code>> </code><i>nameClass</i> <i>nameClass</i><code> </choice></code></td></tr><tr valign="baseline"><td>exceptNameClass</td><td> ::= </td><td><code><except</code><code>> </code><i>nameClass</i><code> </except></code></td></tr></table><p>With this grammar, no elements or attributes are allowed other
than those explicitly shown.</p><div class="section"><a name="simple-syntax-example"></a><div class="titlepage"><div><h3 class="title"><a name="simple-syntax-example"></a>5.1. Example</h3></div></div><p>The following is an example of how the schema in <a href="#full-syntax-example" title="3.1. Example">Section 3.1</a> can be transformed into the simple
syntax:</p><pre class="programlisting"><?xml version="1.0"?>
<grammar xmlns="http://relaxng.org/ns/structure/1.0">
<start>
<ref name="foo.element"/>
</start>
<define name="foo.element">
<element>
<name ns="">foo</name>
<group>
<ref name="bar1.element"/>
<ref name="bar2.element"/>
</group>
</element>
</define>
<define name="bar1.element">
<element>
<name ns="http://www.example.com/n1">bar1</name>
<empty/>
</element>
</define>
<define name="bar2.element">
<element>
<name ns="http://www.example.com/n2">bar2</name>
<empty/>
</element>
</define>
</grammar></pre><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title"><a name="IDAEXZR"></a>Note</h3><p>Strictly speaking, the result of simplification is an
instance of the data model rather than an XML document. For
convenience, we use an XML document to represent an instance of the
data model.</p></div></div></div><div class="section"><a name="semantics"></a><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="semantics"></a>6. Semantics</h2></div></div><p>In this section, we define the semantics of a correct RELAX NG
schema that has been transformed into the simple syntax. The
semantics of a RELAX NG schema consist of a specification of what XML
documents are valid with respect to that schema. The semantics are
described formally. The formalism uses axioms and inference rules.
Axioms are propositions that are provable unconditionally. An
inference rule consists of one or more antecedents and exactly one
consequent. An antecedent is either positive or negative. If all the
positive antecedents of an inference rule are provable and none of the
negative antecedents are provable, then the consequent of the
inference rule is provable. An XML document is valid with respect to a
RELAX NG schema if and only if the proposition that it is valid is
provable in the formalism specified in this section.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title"><a name="IDAQXZR"></a>Note</h3><p>This kind of formalism is similar to a proof system.
However, a traditional proof system only has positive
antecedents.</p></div><p>The notation for inference rules separates the antecedents from
the consequent by a horizontal line: the antecedents are above the
line; the consequent is below the line. If an antecedent is of the
form not(<i><tt>p</tt></i>), then it is a negative
antecedent; otherwise, it is a positive antecedent. Both axioms and
inferences
rules may use variables. A variable has a name and optionally a
subscript. The name of a variable is italicized. Each variable has a
range that is determined by its name. Axioms and inference rules are
implicitly universally quantified over the variables they contain. We
explain this further below.</p><p>The possibility that an inference rule or axiom may contain more
than one occurrence of a particular variable requires that an identity
relation be defined on each kind of object over which a variable can
range. The identity relation for all kinds of object is value-based.
Two objects of a particular kind are identical if the constituents of
the objects are identical. For example, two attributes are considered
the same if they have the same name and the same value. Two characters
are identical if their Unicode character codes are the same.</p><div class="section"><a name="name-classes"></a><div class="titlepage"><div><h3 class="title"><a name="name-classes"></a>6.1. Name classes</h3></div></div><p>The main semantic concept for name classes is that of a name
belonging to a name class. A name class is an element that matches the
production nameClass. A name is as defined in <a href="#data-model" title="2. Data model">Section 2</a>: it consists of a namespace URI and a local
name.</p><p>We use the following notation:</p><div class="variablelist"><dl><dt><a name="IDAJYZR"></a><span class="term"><i>n</i></span></dt><dd><a name="IDANYZR"></a>is a variable
that ranges over names</dd><dt><a name="IDAQYZR"></a><span class="term"><i>nc</i></span></dt><dd><a name="IDAUYZR"></a>ranges over name classes</dd><dt><a name="IDAXYZR"></a><span class="term"><i>n</i> in <i>nc</i></span></dt><dd><a name="IDACZZR"></a>
asserts that name <i>n</i> is a member of name class <i>nc</i>
</dd></dl></div><p>We are now ready for our first axiom, which is called "anyName
1":</p>
<table cellspacing="20"><tr valign="middle"><td>(anyName 1)</td><td><table cellpadding="0" cellspacing="0"><tr align="center"><td colspan="0"><i>n</i> in <code><anyName</code><code>/></code></td></tr></table></td></tr></table>
<p>This says for any name <i>n</i>, <i>n</i> belongs to the name class <code><anyName</code><code>/></code>,
in other words <code><anyName</code><code>/></code> matches any name. Note the
effect of the implicit universal quantification over the variables in
the axiom: this is what makes the axiom apply for any name <i>n</i>.</p><p>Our first inference rule is almost as simple:</p>
<table cellspacing="20"><tr valign="middle"><td>(anyName 2)</td><td><table cellpadding="0" cellspacing="0"><tr align="center" valign="baseline"><td>not(<i>n</i> in <i>nc</i>)</td></tr><tr><td colspan="1"><hr noshade></td></tr><tr align="center"><td colspan="1"><i>n</i> in <code><anyName</code><code>></code> <code><except</code><code>></code> <i>nc</i> <code></except></code> <code></anyName></code></td></tr></table></td></tr></table>
<p>This says that for any name <i>n</i>
and for any name class <i>nc</i>,
if <i>n</i> does not belong to <i>nc</i>,
then <i>n</i> belongs to
<code><anyName</code><code>></code> <code><except</code><code>></code> <i>nc</i> <code></except></code> <code></anyName></code>. In other words, <code><anyName</code><code>></code> <code><except</code><code>></code> <i>nc</i> <code></except></code> <code></anyName></code> matches any name that does not match <i>nc</i>.</p><p>We now need the following additional notation:</p><div class="variablelist"><dl><dt><a name="IDAC3ZR"></a><span class="term"><i>ln</i></span></dt><dd><a name="IDAH3ZR"></a>ranges over local names; a local name is a string that
matches the NCName production of <a href="#xml-names" title="[XML Namespaces]">[XML Namespaces]</a>, that is,
a name with no colons</dd><dt><a name="IDAO3ZR"></a><span class="term"><i>u</i></span></dt><dd><a name="IDAS3ZR"></a>ranges over URIs</dd><dt><a name="IDAV3ZR"></a><span class="term">
name( <i>u</i>, <i>ln</i> )
</span></dt><dd><a name="IDAC4ZR"></a>constructs a name with URI <i>u</i> and local
name <i>ln</i></dd></dl></div><p>The remaining axioms and inference rules for name classes are as
follows:</p>
<table cellspacing="20"><tr valign="middle"><td>(nsName 1)</td><td><table cellpadding="0" cellspacing="0"><tr align="center"><td colspan="0">name( <i>u</i>, <i>ln</i> ) in <code><nsName</code><code> ns="</code><i>u</i><code>"</code><code>/></code></td></tr></table></td></tr></table>
<table cellspacing="20"><tr valign="middle"><td>(nsName 2)</td><td><table cellpadding="0" cellspacing="0"><tr align="center" valign="baseline"><td>not(name( <i>u</i>, <i>ln</i> ) in <i>nc</i>)</td></tr><tr><td colspan="1"><hr noshade></td></tr><tr align="center"><td colspan="1">name( <i>u</i>, <i>ln</i> ) in <code><nsName</code><code> ns="</code><i>u</i><code>"</code><code>></code> <code><except</code><code>></code> <i>nc</i> <code></except></code> <code></nsName></code></td></tr></table></td></tr></table>
<table cellspacing="20"><tr valign="middle"><td>(name)</td><td><table cellpadding="0" cellspacing="0"><tr align="center"><td colspan="0">name( <i>u</i>, <i>ln</i> ) in <code><name</code><code> ns="</code><i>u</i><code>"</code><code>></code> <i>ln</i> <code></name></code></td></tr></table></td></tr></table>
<table cellspacing="20"><tr valign="middle"><td>(name choice 1)</td><td><table cellpadding="0" cellspacing="0"><tr align="center" valign="baseline"><td><i>n</i> in <i>nc</i><sub>1</sub></td></tr><tr><td colspan="1"><hr noshade></td></tr><tr align="center"><td colspan="1"><i>n</i> in <code><choice</code><code>></code> <i>nc</i><sub>1</sub> <i>nc</i><sub>2</sub> <code></choice></code></td></tr></table></td></tr></table>
<table cellspacing="20"><tr valign="middle"><td>(name choice 2)</td><td><table cellpadding="0" cellspacing="0"><tr align="center" valign="baseline"><td><i>n</i> in <i>nc</i><sub>2</sub></td></tr><tr><td colspan="1"><hr noshade></td></tr><tr align="center"><td colspan="1"><i>n</i> in <code><choice</code><code>></code> <i>nc</i><sub>1</sub> <i>nc</i><sub>2</sub> <code></choice></code></td></tr></table></td></tr></table>
</div><div class="section"><a name="IDAME0R"></a><div class="titlepage"><div><h3 class="title"><a name="IDAME0R"></a>6.2. Patterns</h3></div></div><p>The axioms and inference rules for patterns use the following
notation:</p><div class="variablelist"><dl><dt><a name="IDASE0R"></a><span class="term"><i>cx</i></span></dt><dd><a name="IDAWE0R"></a>ranges
over contexts (as defined in <a href="#data-model" title="2. Data model">Section 2</a>)</dd><dt><a name="IDA2E0R"></a><span class="term"><i>a</i></span></dt><dd><a name="IDAAF0R"></a>ranges over
sets of attributes; a set with a single member
is considered the same as that member</dd><dt><a name="IDADF0R"></a><span class="term"><i>m</i></span></dt><dd><a name="IDAHF0R"></a>ranges over sequences of
elements and strings; a sequence with a single member is considered
the same as that member; the sequences ranged over by <i>m</i> may contain consecutive strings and may contain strings
that are empty; thus, there are sequences ranged over by <i>m</i> that cannot occur as the children of an
element</dd><dt><a name="IDAQF0R"></a><span class="term"><i>p</i></span></dt><dd><a name="IDAUF0R"></a>ranges
over patterns (elements matching the pattern
production)</dd><dt><a name="IDAXF0R"></a><span class="term"><i>cx</i> |- <i>a</i>; <i>m</i> =~ <i>p</i></span></dt><dd><a name="IDAIG0R"></a>
asserts that with respect to context <i>cx</i>, the
attributes <i>a</i> and the sequence of elements and
strings <i>m</i> matches the pattern <i>p</i></dd></dl></div><div class="section"><a name="choice-pattern"></a><div class="titlepage"><div><h4 class="title"><a name="choice-pattern"></a>6.2.1. <tt>choice</tt> pattern</h4></div></div><p>The semantics of the <tt>choice</tt> pattern are as follows:</p>
<table cellspacing="20"><tr valign="middle"><td>(choice 1)</td><td><table cellpadding="0" cellspacing="0"><tr align="center" valign="baseline"><td><i>cx</i> |- <i>a</i>; <i>m</i> =~ <i>p</i><sub>1</sub></td></tr><tr><td colspan="1"><hr noshade></td></tr><tr align="center"><td colspan="1"><i>cx</i> |- <i>a</i>; <i>m</i> =~ <code><choice</code><code>></code> <i>p</i><sub>1</sub> <i>p</i><sub>2</sub> <code></choice></code></td></tr></table></td></tr></table>
<table cellspacing="20"><tr valign="middle"><td>(choice 2)</td><td><table cellpadding="0" cellspacing="0"><tr align="center" valign="baseline"><td><i>cx</i> |- <i>a</i>; <i>m</i> =~ <i>p</i><sub>2</sub></td></tr><tr><td colspan="1"><hr noshade></td></tr><tr align="center"><td colspan="1"><i>cx</i> |- <i>a</i>; <i>m</i> =~ <code><choice</code><code>></code> <i>p</i><sub>1</sub> <i>p</i><sub>2</sub> <code></choice></code></td></tr></table></td></tr></table>
</div><div class="section"><a name="IDAEK0R"></a><div class="titlepage"><div><h4 class="title"><a name="IDAEK0R"></a>6.2.2. <tt>group</tt> pattern</h4></div></div><p>We use the following additional notation:</p><div class="variablelist"><dl><dt><a name="IDAMK0R"></a><span class="term"><i>m</i><sub>1</sub>, <i>m</i><sub>2</sub></span></dt><dd><a name="IDAZK0R"></a>represents the concatenation of the sequences <i>m</i><sub>1</sub> and <i>m</i><sub>2</sub>
</dd><dt><a name="IDAEL0R"></a><span class="term"><i>a</i><sub>1</sub> + <i>a</i><sub>2</sub></span></dt><dd><a name="IDARL0R"></a>represents the union of <i>a</i><sub>1</sub>
and <i>a</i><sub>2</sub></dd></dl></div><p>The semantics of the <tt>group</tt> pattern are as follows:</p>
<table cellspacing="20"><tr valign="middle"><td>(group)</td><td><table cellpadding="0" cellspacing="0"><tr align="center" valign="baseline"><td><i>cx</i> |- <i>a</i><sub>1</sub>; <i>m</i><sub>1</sub> =~ <i>p</i><sub>1</sub></td><td> <i>cx</i> |- <i>a</i><sub>2</sub>; <i>m</i><sub>2</sub> =~ <i>p</i><sub>2</sub></td></tr><tr><td colspan="2"><hr noshade></td></tr><tr align="center"><td colspan="2"><i>cx</i> |- <i>a</i><sub>1</sub> + <i>a</i><sub>2</sub>; <i>m</i><sub>1</sub>, <i>m</i><sub>2</sub> =~ <code><group</code><code>></code> <i>p</i><sub>1</sub> <i>p</i><sub>2</sub> <code></group></code></td></tr></table></td></tr></table>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title"><a name="IDAZO0R"></a>Note</h3><p>The restriction in <a href="#attribute-restrictions" title="7.3. Restrictions on attributes">Section 7.3</a>
ensures that the set of attributes constructed in the consequent will
not have multiple attributes with the same name.</p></div></div><div class="section"><a name="empty-pattern"></a><div class="titlepage"><div><h4 class="title"><a name="empty-pattern"></a>6.2.3. <tt>empty</tt> pattern</h4></div></div><p>We use the following additional notation:</p><div class="variablelist"><dl><dt><a name="IDAKP0R"></a><span class="term">( )</span></dt><dd><a name="IDAOP0R"></a>represents an empty sequence</dd><dt><a name="IDARP0R"></a><span class="term">{ }</span></dt><dd><a name="IDAVP0R"></a>represents an empty set</dd></dl></div><p>The semantics of the <tt>empty</tt> pattern are as follows:</p>
<table cellspacing="20"><tr valign="middle"><td>(empty)</td><td><table cellpadding="0" cellspacing="0"><tr align="center"><td colspan="0"><i>cx</i> |- { }; ( ) =~ <code><empty</code><code>/></code></td></tr></table></td></tr></table>
</div><div class="section"><a name="text-pattern"></a><div class="titlepage"><div><h4 class="title"><a name="text-pattern"></a>6.2.4. <tt>text</tt> pattern</h4></div></div><p>We use the following additional notation:</p><div class="variablelist"><dl><dt><a name="IDAHR0R"></a><span class="term"><i>s</i></span></dt><dd><a name="IDALR0R"></a>ranges
over strings</dd></dl></div><p>The semantics of the <tt>text</tt> pattern are as follows:</p>
<table cellspacing="20"><tr valign="middle"><td>(text 1)</td><td><table cellpadding="0" cellspacing="0"><tr align="center"><td colspan="0"><i>cx</i> |- { }; ( ) =~ <code><text</code><code>/></code></td></tr></table></td></tr></table>
<table cellspacing="20"><tr valign="middle"><td>(text 2)</td><td><table cellpadding="0" cellspacing="0"><tr align="center" valign="baseline"><td><i>cx</i> |- { }; <i>m</i> =~ <code><text</code><code>/></code></td></tr><tr><td colspan="1"><hr noshade></td></tr><tr align="center"><td colspan="1"><i>cx</i> |- { }; <i>m</i>, <i>s</i> =~ <code><text</code><code>/></code></td></tr></table></td></tr></table>
<p>The effect of the above rule is that a <tt>text</tt>
element matches zero or more strings.</p></div><div class="section"><a name="IDALU0R"></a><div class="titlepage"><div><h4 class="title"><a name="IDALU0R"></a>6.2.5. <tt>oneOrMore</tt> pattern</h4></div></div><p>We use the following additional notation:</p><div class="variablelist"><dl><dt><a name="IDATU0R"></a><span class="term">disjoint(<i>a</i><sub>1</sub>, <i>a</i><sub>2</sub>)</span></dt><dd><a name="IDAAV0R"></a>
asserts that there is no name that is
the name of both an attribute in <i>a</i><sub>1</sub>
and of an attribute in <i>a</i><sub>2</sub>
</dd></dl></div><p>The semantics of the <tt>oneOrMore</tt> pattern are as follows:</p>
<table cellspacing="20"><tr valign="middle"><td>(oneOrMore 1)</td><td><table cellpadding="0" cellspacing="0"><tr align="center" valign="baseline"><td><i>cx</i> |- <i>a</i>; <i>m</i> =~ <i>p</i></td></tr><tr><td colspan="1"><hr noshade></td></tr><tr align="center"><td colspan="1"><i>cx</i> |- <i>a</i>; <i>m</i> =~ <code><oneOrMore</code><code>></code> <i>p</i> <code></oneOrMore></code></td></tr></table></td></tr></table>
<table cellspacing="20"><tr valign="middle"><td>(oneOrMore 2)</td><td><table cellpadding="0" cellspacing="0"><tr align="center" valign="baseline"><td><i>cx</i> |- <i>a</i><sub>1</sub>; <i>m</i><sub>1</sub> =~ <i>p</i></td><td> <i>cx</i> |- <i>a</i><sub>2</sub>; <i>m</i><sub>2</sub> =~ <code><oneOrMore</code><code>></code> <i>p</i> <code></oneOrMore></code></td><td> disjoint(<i>a</i><sub>1</sub>, <i>a</i><sub>2</sub>)</td></tr><tr><td colspan="3"><hr noshade></td></tr><tr align="center"><td colspan="3"><i>cx</i> |- <i>a</i><sub>1</sub> + <i>a</i><sub>2</sub>; <i>m</i><sub>1</sub>, <i>m</i><sub>2</sub> =~ <code><oneOrMore</code><code>></code> <i>p</i> <code></oneOrMore></code></td></tr></table></td></tr></table>
</div><div class="section"><a name="IDA2Z0R"></a><div class="titlepage"><div><h4 class="title"><a name="IDA2Z0R"></a>6.2.6. <tt>interleave</tt> pattern</h4></div></div><p>We use the following additional notation:</p><div class="variablelist"><dl><dt><a name="IDAE00R"></a><span class="term"><i>m</i><sub>1</sub> interleaves <i>m</i><sub>2</sub>; <i>m</i><sub>3</sub></span></dt><dd><a name="IDAV00R"></a>
asserts that <i>m</i><sub>1</sub>
is an interleaving of <i>m</i><sub>2</sub>
and <i>m</i><sub>3</sub>
</dd></dl></div><p>The semantics of interleaving are defined by the following rules.</p>
<table cellspacing="20"><tr valign="middle"><td>(interleaves 1)</td><td><table cellpadding="0" cellspacing="0"><tr align="center"><td colspan="0">( ) interleaves ( ); ( )</td></tr></table></td></tr></table>
<table cellspacing="20"><tr valign="middle"><td>(interleaves 2)</td><td><table cellpadding="0" cellspacing="0"><tr align="center" valign="baseline"><td><i>m</i><sub>1</sub> interleaves <i>m</i><sub>2</sub>; <i>m</i><sub>3</sub></td></tr><tr><td colspan="1"><hr noshade></td></tr><tr align="center"><td colspan="1"><i>m</i><sub>4</sub>, <i>m</i><sub>1</sub> interleaves <i>m</i><sub>4</sub>, <i>m</i><sub>2</sub>; <i>m</i><sub>3</sub></td></tr></table></td></tr></table>
<table cellspacing="20"><tr valign="middle"><td>(interleaves 3)</td><td><table cellpadding="0" cellspacing="0"><tr align="center" valign="baseline"><td><i>m</i><sub>1</sub> interleaves <i>m</i><sub>2</sub>; <i>m</i><sub>3</sub></td></tr><tr><td colspan="1"><hr noshade></td></tr><tr align="center"><td colspan="1"><i>m</i><sub>4</sub>, <i>m</i><sub>1</sub> interleaves <i>m</i><sub>2</sub>; <i>m</i><sub>4</sub>, <i>m</i><sub>3</sub></td></tr></table></td></tr></table>
<p>For example, the interleavings of
<tt><a/><a/></tt> and
<tt><b/></tt> are
<tt><a/><a/><b/></tt>,
<tt><a/><b/><a/></tt>, and
<tt><b/><a/><a/></tt>.</p><p>The semantics of the <tt>interleave</tt> pattern are
as follows:</p>
<table cellspacing="20"><tr valign="middle"><td>(interleave)</td><td><table cellpadding="0" cellspacing="0"><tr align="center" valign="baseline"><td><i>cx</i> |- <i>a</i><sub>1</sub>; <i>m</i><sub>1</sub> =~ <i>p</i><sub>1</sub></td><td> <i>cx</i> |- <i>a</i><sub>2</sub>; <i>m</i><sub>2</sub> =~ <i>p</i><sub>2</sub></td><td> <i>m</i><sub>3</sub> interleaves <i>m</i><sub>1</sub>; <i>m</i><sub>2</sub></td></tr><tr><td colspan="3"><hr noshade></td></tr><tr align="center"><td colspan="3"><i>cx</i> |- <i>a</i><sub>1</sub> + <i>a</i><sub>2</sub>; <i>m</i><sub>3</sub> =~ <code><interleave</code><code>></code> <i>p</i><sub>1</sub> <i>p</i><sub>2</sub> <code></interleave></code></td></tr></table></td></tr></table>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title"><a name="IDAZC1R"></a>Note</h3><p>The restriction in <a href="#attribute-restrictions" title="7.3. Restrictions on attributes">Section 7.3</a>
ensures that the set of attributes constructed in the consequent will
not have multiple attributes with the same name.</p></div></div><div class="section"><a name="element-pattern"></a><div class="titlepage"><div><h4 class="title"><a name="element-pattern"></a>6.2.7. <tt>element</tt> and <tt>attribute</tt> pattern</h4></div></div><p>The value of an attribute is always a single string, which may
be empty. Thus, the empty sequence is not a possible attribute value.
On the hand, the children of an element can be an empty sequence and
cannot consist of an empty string. In order to ensure that validation
handles attributes and elements consistently, we introduce a variant
of matching called <i>weak matching</i>. Weak
matching is used when matching the pattern for the value of an
attribute or for the attributes and children of an element. We use
the following notation to define weak matching.</p><div class="variablelist"><dl><dt><a name="IDAOD1R"></a><span class="term"><code>""</code></span></dt><dd><a name="IDASD1R"></a>represents an empty
string</dd><dt><a name="IDAVD1R"></a><span class="term"><i>ws</i></span></dt><dd><a name="IDAZD1R"></a>ranges over the empty
sequence and strings that consist entirely of
whitespace</dd><dt><a name="IDA2D1R"></a><span class="term"><i>cx</i> |- <i>a</i>; <i>m</i> =~<sub>weak</sub> <i>p</i></span></dt><dd><a name="IDANE1R"></a>
asserts that with respect to context <i>cx</i>, the
attributes <i>a</i> and the sequence of elements and
strings <i>m</i> weakly matches the pattern <i>p</i></dd></dl></div><p>The semantics of weak matching are as follows:</p>
<table cellspacing="20"><tr valign="middle"><td>(weak match 1)</td><td><table cellpadding="0" cellspacing="0"><tr align="center" valign="baseline"><td><i>cx</i> |- <i>a</i>; <i>m</i> =~ <i>p</i></td></tr><tr><td colspan="1"><hr noshade></td></tr><tr align="center"><td colspan="1"><i>cx</i> |- <i>a</i>; <i>m</i> =~<sub>weak</sub> <i>p</i></td></tr></table></td></tr></table>
<table cellspacing="20"><tr valign="middle"><td>(weak match 2)</td><td><table cellpadding="0" cellspacing="0"><tr align="center" valign="baseline"><td><i>cx</i> |- <i>a</i>; ( ) =~ <i>p</i></td></tr><tr><td colspan="1"><hr noshade></td></tr><tr align="center"><td colspan="1"><i>cx</i> |- <i>a</i>; <i>ws</i> =~<sub>weak</sub> <i>p</i></td></tr></table></td></tr></table>
<table cellspacing="20"><tr valign="middle"><td>(weak match 3)</td><td><table cellpadding="0" cellspacing="0"><tr align="center" valign="baseline"><td><i>cx</i> |- <i>a</i>; <code>""</code> =~ <i>p</i></td></tr><tr><td colspan="1"><hr noshade></td></tr><tr align="center"><td colspan="1"><i>cx</i> |- <i>a</i>; ( ) =~<sub>weak</sub> <i>p</i></td></tr></table></td></tr></table>
<p>We use the following additional notation:</p><div class="variablelist"><dl><dt><a name="IDASI1R"></a><span class="term">attribute( <i>n</i>, <i>s</i> )</span></dt><dd><a name="IDA3I1R"></a>
constructs an attribute with name <i>n</i>
and value <i>s</i>
</dd><dt><a name="IDAGJ1R"></a><span class="term">element( <i>n</i>, <i>cx</i>, <i>a</i>, <i>m</i> )</span></dt><dd><a name="IDAXJ1R"></a>
constructs an element with name <i>n</i>,
context <i>cx</i>,
attributes <i>a</i>
and mixed sequence <i>m</i> as children
</dd><dt><a name="IDAGK1R"></a><span class="term">okAsChildren(<i>m</i>)</span></dt><dd><a name="IDAOK1R"></a>
asserts that the mixed sequence <i>m</i> can occur as
the children of an element: it does not contain any member that is an
empty string, nor does it contain two consecutive members that are
both strings</dd><dt><a name="IDAUK1R"></a><span class="term">deref(<i>ln</i>) = <code><element> </code><i>nc</i> <i>p</i><code> </element></code></span></dt><dd><a name="IDACL1R"></a>
asserts that the grammar contains
<code><define</code><code> name="</code><i>ln</i><code>"</code><code>></code> <code><element</code><code>></code> <i>nc</i> <i>p</i> <code></element></code> <code></define></code>
</dd></dl></div><p>The semantics of the <tt>attribute</tt> pattern are as follows:</p>
<table cellspacing="20"><tr valign="middle"><td>(attribute)</td><td><table cellpadding="0" cellspacing="0"><tr align="center" valign="baseline"><td><i>cx</i> |- { }; <i>s</i> =~<sub>weak</sub> <i>p</i></td><td> <i>n</i> in <i>nc</i></td></tr><tr><td colspan="2"><hr noshade></td></tr><tr align="center"><td colspan="2"><i>cx</i> |- attribute( <i>n</i>, <i>s</i> ); ( ) =~ <code><attribute</code><code>></code> <i>nc</i> <i>p</i> <code></attribute></code></td></tr></table></td></tr></table>
<p>The semantics of the <tt>element</tt> pattern are as follows:</p>
<table cellspacing="20"><tr valign="middle"><td>(element)</td><td><table cellpadding="0" cellspacing="0"><tr align="center" valign="baseline"><td><i>cx</i><sub>1</sub> |- <i>a</i>; <i>m</i> =~<sub>weak</sub> <i>p</i></td><td> <i>n</i> in <i>nc</i></td><td> okAsChildren(<i>m</i>)</td><td> deref(<i>ln</i>) = <code><element> </code><i>nc</i> <i>p</i><code> </element></code></td></tr><tr><td colspan="4"><hr noshade></td></tr><tr align="center"><td colspan="4"><i>cx</i><sub>2</sub> |- { }; <i>ws</i><sub>1</sub>, element( <i>n</i>, <i>cx</i><sub>1</sub>, <i>a</i>, <i>m</i> ), <i>ws</i><sub>2</sub> =~ <code><ref</code><code> name="</code><i>ln</i><code>"</code><code>/></code></td></tr></table></td></tr></table>
</div><div class="section"><a name="data-pattern"></a><div class="titlepage"><div><h4 class="title"><a name="data-pattern"></a>6.2.8. <tt>data</tt> and <tt>value</tt> pattern</h4></div></div><p>RELAX NG relies on datatype libraries to perform datatyping.
A datatype library is identified by a URI. A datatype within a
datatype library is identified by an NCName. A datatype library
provides two services.</p><div class="itemizedlist"><ul><li><a name="IDAZR1R"></a>It can determine whether a string is a legal
representation of a datatype. This service accepts a list of zero or
more parameters. For example, a string datatype might have a parameter
specifying the length of a string. The datatype library determines
what parameters are applicable for each datatype.</li><li><a name="IDA2R1R"></a>It can determine whether two strings represent the
same value of a datatype. This service does not have any
parameters.</li></ul></div><p>Both services may make use of the context of a string. For
example, a datatype representing a QName would use the namespace
map.</p><p>We use the following additional notation:</p><div class="variablelist"><dl><dt><a name="IDAFS1R"></a><span class="term">datatypeAllows(<i>u</i>, <i>ln</i>, <i>params</i>, <i>s</i>, <i>cx</i>)</span></dt><dd><a name="IDAZS1R"></a>
asserts that in the datatype library identified by URI <i>u</i>, the string <i>s</i> interpreted with
context <i>cx</i> is a legal
value of datatype <i>ln</i> with parameters <i>params</i></dd><dt><a name="IDAKT1R"></a><span class="term">datatypeEqual(<i>u</i>, <i>ln</i>, <i>s</i><sub>1</sub>, <i>cx</i><sub>1</sub>, <i>s</i><sub>2</sub>, <i>cx</i><sub>2</sub>)</span></dt><dd><a name="IDAFU1R"></a>
asserts that in the datatype library identified by URI <i>u</i>, string <i>s</i><sub>1</sub> interpreted with
context <i>cx</i><sub>1</sub> represents the same value of
the datatype <i>ln</i> as the string <i>s</i><sub>2</sub> interpreted in the context of <i>cx</i><sub>2</sub>
</dd><dt><a name="IDA4U1R"></a><span class="term"><i>params</i></span></dt><dd><a name="IDACV1R"></a>ranges over sequences of parameters</dd><dt><a name="IDAFV1R"></a><span class="term">[<i>cx</i>]</span></dt><dd><a name="IDALV1R"></a>
within the start-tag of a pattern refers to the context
of the pattern element
</dd><dt><a name="IDAOV1R"></a><span class="term">
context( <i>u</i>, <i>cx</i> )
</span></dt><dd><a name="IDA1V1R"></a>constructs a context which is the same as <i>cx</i>
except that the default namespace is <i>u</i>; if <i>u</i> is the empty string, then there is no default namespace
in the constructed context</dd></dl></div><p>The datatypeEqual function must be reflexive, transitive
and symmetric, that is, the following inference rules must hold:</p>
<table cellspacing="20"><tr valign="middle"><td>(datatypeEqual reflexive)</td><td><table cellpadding="0" cellspacing="0"><tr align="center" valign="baseline"><td>datatypeAllows(<i>u</i>, <i>ln</i>, <i>params</i>, <i>s</i>, <i>cx</i>)</td></tr><tr><td colspan="1"><hr noshade></td></tr><tr align="center"><td colspan="1">datatypeEqual(<i>u</i>, <i>ln</i>, <i>s</i>, <i>cx</i>, <i>s</i>, <i>cx</i>)</td></tr></table></td></tr></table>
<table cellspacing="20"><tr valign="middle"><td>(datatypeEqual transitive)</td><td><table cellpadding="0" cellspacing="0"><tr align="center" valign="baseline"><td>datatypeEqual(<i>u</i>, <i>ln</i>, <i>s</i><sub>1</sub>, <i>cx</i><sub>1</sub>, <i>s</i><sub>2</sub>, <i>cx</i><sub>2</sub>)</td><td> datatypeEqual(<i>u</i>, <i>ln</i>, <i>s</i><sub>2</sub>, <i>cx</i><sub>3</sub>, <i>s</i><sub>3</sub>, <i>cx</i><sub>3</sub>)</td></tr><tr><td colspan="2"><hr noshade></td></tr><tr align="center"><td colspan="2">datatypeEqual(<i>u</i>, <i>ln</i>, <i>s</i><sub>1</sub>, <i>cx</i><sub>1</sub>, <i>s</i><sub>3</sub>, <i>cx</i><sub>3</sub>)</td></tr></table></td></tr></table>
<table cellspacing="20"><tr valign="middle"><td>(datatypeEqual symmetric)</td><td><table cellpadding="0" cellspacing="0"><tr align="center" valign="baseline"><td>datatypeEqual(<i>u</i>, <i>ln</i>, <i>s</i><sub>1</sub>, <i>cx</i><sub>1</sub>, <i>s</i><sub>2</sub>, <i>cx</i><sub>2</sub>)</td></tr><tr><td colspan="1"><hr noshade></td></tr><tr align="center"><td colspan="1">datatypeEqual(<i>u</i>, <i>ln</i>, <i>s</i><sub>2</sub>, <i>cx</i><sub>2</sub>, <i>s</i><sub>1</sub>, <i>cx</i><sub>1</sub>)</td></tr></table></td></tr></table>
<p>The semantics of the <tt>data</tt> and
<tt>value</tt> patterns are as follows:</p>
<table cellspacing="20"><tr valign="middle"><td>(value)</td><td><table cellpadding="0" cellspacing="0"><tr align="center" valign="baseline"><td>datatypeEqual(<i>u</i><sub>1</sub>, <i>ln</i>, <i>s</i><sub>1</sub>, <i>cx</i><sub>1</sub>, <i>s</i><sub>2</sub>, context( <i>u</i><sub>2</sub>, <i>cx</i><sub>2</sub> ))</td></tr><tr><td colspan="1"><hr noshade></td></tr><tr align="center"><td colspan="1"><i>cx</i><sub>1</sub> |- { }; <i>s</i><sub>1</sub> =~ <code><value</code><code> datatypeLibrary="</code><i>u</i><sub>1</sub><code>"</code><code> type="</code><i>ln</i><code>"</code><code> ns="</code><i>u</i><sub>2</sub><code>"</code><code> </code>[<i>cx</i><sub>2</sub>]<code>></code> <i>s</i><sub>2</sub> <code></value></code></td></tr></table></td></tr></table>
<table cellspacing="20"><tr valign="middle"><td>(data 1)</td><td><table cellpadding="0" cellspacing="0"><tr align="center" valign="baseline"><td>datatypeAllows(<i>u</i>, <i>ln</i>, <i>params</i>, <i>s</i>, <i>cx</i>)</td></tr><tr><td colspan="1"><hr noshade></td></tr><tr align="center"><td colspan="1"><i>cx</i> |- { }; <i>s</i> =~ <code><data</code><code> datatypeLibrary="</code><i>u</i><code>"</code><code> type="</code><i>ln</i><code>"</code><code>></code> <i>params</i> <code></data></code></td></tr></table></td></tr></table>
<table cellspacing="20"><tr valign="middle"><td>(data 2)</td><td><table cellpadding="0" cellspacing="0"><tr align="center" valign="baseline"><td>datatypeAllows(<i>u</i>, <i>ln</i>, <i>params</i>, <i>s</i>, <i>cx</i>)</td><td> not(<i>cx</i> |- <i>a</i>; <i>s</i> =~ <i>p</i>)</td></tr><tr><td colspan="2"><hr noshade></td></tr><tr align="center"><td colspan="2"><i>cx</i> |- { }; <i>s</i> =~ <code><data</code><code> datatypeLibrary="</code><i>u</i><code>"</code><code> type="</code><i>ln</i><code>"</code><code>></code> <i>params</i> <code><except</code><code>></code> <i>p</i> <code></except></code> <code></data></code></td></tr></table></td></tr></table>
</div><div class="section"><a name="built-in-datatype"></a><div class="titlepage"><div><h4 class="title"><a name="built-in-datatype"></a>6.2.9. Built-in datatype library</h4></div></div><p>The empty URI identifies a special built-in datatype library.
This provides two datatypes, <tt>string</tt> and
<tt>token</tt>. No parameters are allowed for either of
these datatypes.</p><div class="variablelist"><dl><dt><a name="IDAWEAS"></a><span class="term">
<i>s</i><sub>1</sub> = <i>s</i><sub>2</sub></span></dt><dd><a name="IDAEFAS"></a>asserts that <i>s</i><sub>1</sub>
and <i>s</i><sub>2</sub> are identical</dd><dt><a name="IDAQFAS"></a><span class="term">
normalizeWhiteSpace( <i>s</i> )
</span></dt><dd><a name="IDA0FAS"></a>returns the string <i>s</i>,
with leading and trailing whitespace characters removed,
and with each other maximal sequence of whitespace characters
replaced by a single space character </dd></dl></div><p>The semantics of the two built-in datatypes are as
follows:</p>
<table cellspacing="20"><tr valign="middle"><td>(string allows)</td><td><table cellpadding="0" cellspacing="0"><tr align="center"><td colspan="0">datatypeAllows(<code>""</code>, <code>"string"</code>, ( ), <i>s</i>, <i>cx</i>)</td></tr></table></td></tr></table>
<table cellspacing="20"><tr valign="middle"><td>(string equal)</td><td><table cellpadding="0" cellspacing="0"><tr align="center"><td colspan="0">datatypeEqual(<code>""</code>, <code>"string"</code>, <i>s</i>, <i>cx</i><sub>1</sub>, <i>s</i>, <i>cx</i><sub>2</sub>)</td></tr></table></td></tr></table>
<table cellspacing="20"><tr valign="middle"><td>(token allows)</td><td><table cellpadding="0" cellspacing="0"><tr align="center"><td colspan="0">datatypeAllows(<code>""</code>, <code>"token"</code>, ( ), <i>s</i>, <i>cx</i>)</td></tr></table></td></tr></table>
<table cellspacing="20"><tr valign="middle"><td>(token equal)</td><td><table cellpadding="0" cellspacing="0"><tr align="center" valign="baseline"><td>normalizeWhiteSpace( <i>s</i><sub>1</sub> ) = normalizeWhiteSpace( <i>s</i><sub>2</sub> )</td></tr><tr><td colspan="1"><hr noshade></td></tr><tr align="center"><td colspan="1">datatypeEqual(<code>""</code>, <code>"token"</code>, <i>s</i><sub>1</sub>, <i>cx</i><sub>1</sub>, <i>s</i><sub>2</sub>, <i>cx</i><sub>2</sub>)</td></tr></table></td></tr></table>
</div><div class="section"><a name="IDACKAS"></a><div class="titlepage"><div><h4 class="title"><a name="IDACKAS"></a>6.2.10. <tt>list</tt> pattern</h4></div></div><p>We use the following additional notation:</p><div class="variablelist"><dl><dt><a name="IDAKKAS"></a><span class="term">split( <i>s</i> )</span></dt><dd><a name="IDASKAS"></a>
returns a sequence of strings one for each whitespace delimited token
of <i>s</i>; each string in the returned sequence will
be non-empty and will not contain any
whitespace</dd></dl></div><p>The semantics of the <tt>list</tt> pattern are as follows:</p>
<table cellspacing="20"><tr valign="middle"><td>(list)</td><td><table cellpadding="0" cellspacing="0"><tr align="center" valign="baseline"><td><i>cx</i> |- { }; split( <i>s</i> ) =~ <i>p</i></td></tr><tr><td colspan="1"><hr noshade></td></tr><tr align="center"><td colspan="1"><i>cx</i> |- { }; <i>s</i> =~ <code><list</code><code>></code> <i>p</i> <code></list></code></td></tr></table></td></tr></table>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title"><a name="IDALMAS"></a>Note</h3><p>It is crucial in the above inference rule that the
sequence that is matched against a pattern can contain consecutive
strings.</p></div></div></div><div class="section"><a name="validity"></a><div class="titlepage"><div><h3 class="title"><a name="validity"></a>6.3. Validity</h3></div></div><p>Now we can define when an element is valid with respect to a
schema. We use the following additional notation:</p><div class="variablelist"><dl><dt><a name="IDAYMAS"></a><span class="term"><i>e</i></span></dt><dd><a name="IDA2MAS"></a>ranges over elements</dd><dt><a name="IDA5MAS"></a><span class="term">valid(<i>e</i>)</span></dt><dd><a name="IDAHNAS"></a>
asserts that the element <i>e</i> is valid with
respect to the grammar</dd><dt><a name="IDANNAS"></a><span class="term">start() = <i>p</i></span></dt><dd><a name="IDAVNAS"></a>
asserts that the grammar contains
<code><start</code><code>></code> <i>p</i> <code></start></code></dd></dl></div><p>An element is valid if together with an empty set of attributes
it matches the <tt>start</tt> pattern of the grammar.</p>
<table cellspacing="20"><tr valign="middle"><td>(valid)</td><td><table cellpadding="0" cellspacing="0"><tr align="center" valign="baseline"><td>start() = <i>p</i></td><td> <i>cx</i> |- { }; <i>e</i> =~ <i>p</i></td></tr><tr><td colspan="2"><hr noshade></td></tr><tr align="center"><td colspan="2">valid(<i>e</i>)</td></tr></table></td></tr></table>
</div><div class="section"><a name="IDAHPAS"></a><div class="titlepage"><div><h3 class="title"><a name="IDAHPAS"></a>6.4. Example</h3></div></div><p>Let <i>e</i><sub>0</sub> be</p><div class="formula" style="margin-left: 0.5in; margin-right: 0.5in;">
element( name( <code>""</code>, <code>"foo"</code> ), <i>cx</i><sub>0</sub>, { }, <i>m</i> )
</div><p>where <i>m</i> is</p><div class="formula" style="margin-left: 0.5in; margin-right: 0.5in;">
<i>e</i><sub>1</sub>, <i>e</i><sub>2</sub>
</div><p>and <i>e</i><sub>1</sub> is</p><div class="formula" style="margin-left: 0.5in; margin-right: 0.5in;">
element( name( <code>"http://www.example.com/n1"</code>, <code>"bar1"</code> ), <i>cx</i><sub>1</sub>, { }, ( ) )
</div><p>and <i>e</i><sub>2</sub> is</p><div class="formula" style="margin-left: 0.5in; margin-right: 0.5in;">
element( name( <code>"http://www.example.com/n2"</code>, <code>"bar2"</code> ), <i>cx</i><sub>2</sub>, { }, ( ) )
</div><p>Assuming appropriate definitions of <i>cx</i><sub>0</sub>, <i>cx</i><sub>1</sub> and <i>cx</i><sub>2</sub>, this represents the document in <a href="#data-model-example" title="2.1. Example">Section 2.1</a>.</p><p>We now show how <i>e</i><sub>0</sub> can be shown to
be valid with respect to the schema in <a href="#simple-syntax-example" title="5.1. Example">Section 5.1</a>. The schema is equivalent to the
following propositions:</p><div class="formula" style="margin-left: 0.5in; margin-right: 0.5in;">
start() = <code><ref</code><code> name="</code><code>foo</code><code>"</code><code>/></code>
</div><div class="formula" style="margin-left: 0.5in; margin-right: 0.5in;">
deref(<code>"foo.element"</code>) = <code><element> </code><code><name</code><code> ns="</code><code>"</code><code>></code> <code>"foo"</code> <code></name></code> <code><group</code><code>></code> <code><ref</code><code> name="</code><code>bar1</code><code>"</code><code>/></code> <code><ref</code><code> name="</code><code>bar2</code><code>"</code><code>/></code> <code></group></code><code> </element></code>
</div><div class="formula" style="margin-left: 0.5in; margin-right: 0.5in;">
deref(<code>"bar1.element"</code>) = <code><element> </code><code><name</code><code> ns="</code><code>http://www.example.com/n1</code><code>"</code><code>></code> <code>"bar1"</code> <code></name></code> <code><empty</code><code>/></code><code> </element></code>
</div><div class="formula" style="margin-left: 0.5in; margin-right: 0.5in;">
deref(<code>"bar2.element"</code>) = <code><element> </code><code><name</code><code> ns="</code><code>http://www.example.com/n2</code><code>"</code><code>></code> <code>"bar2"</code> <code></name></code> <code><empty</code><code>/></code><code> </element></code>
</div><p>Let name class <i>nc</i><sub>1</sub> be</p><div class="formula" style="margin-left: 0.5in; margin-right: 0.5in;">
<code><name</code><code> ns="</code><code>http://www.example.com/n1</code><code>"</code><code>></code> <code>"bar1"</code> <code></name></code>
</div><p>and let <i>nc</i><sub>2</sub> be</p><div class="formula" style="margin-left: 0.5in; margin-right: 0.5in;">
<code><name</code><code> ns="</code><code>http://www.example.com/n2</code><code>"</code><code>></code> <code>"bar2"</code> <code></name></code>
</div><p>Then, by the inference rule (name) in <a href="#name-classes" title="6.1. Name classes">Section 6.1</a>, we have</p><div class="formula" style="margin-left: 0.5in; margin-right: 0.5in;">
name( <code>"http://www.example.com/n1"</code>, <code>"bar1"</code> ) in <i>nc</i><sub>1</sub>
</div><p>and</p><div class="formula" style="margin-left: 0.5in; margin-right: 0.5in;">
name( <code>"http://www.example.com/n2"</code>, <code>"bar2"</code> ) in <i>nc</i><sub>2</sub>
</div><p>By the inference rule (empty) in <a href="#empty-pattern" title="6.2.3. empty pattern">Section 6.2.3</a>,
we have</p><div class="formula" style="margin-left: 0.5in; margin-right: 0.5in;">
<i>cx</i><sub>1</sub> |- { }; ( ) =~ <code><empty</code><code>/></code>
</div><p>and</p><div class="formula" style="margin-left: 0.5in; margin-right: 0.5in;">
<i>cx</i><sub>2</sub> |- { }; ( ) =~ <code><empty</code><code>/></code>
</div><p>Thus by the inference rule (element) in <a href="#element-pattern" title="6.2.7. element and attribute pattern">Section 6.2.7</a>, we have</p><div class="formula" style="margin-left: 0.5in; margin-right: 0.5in;">
<i>cx</i><sub>0</sub> |- { }; <i>e</i><sub>1</sub> =~ <code><ref</code><code> name="</code><code>bar1</code><code>"</code><code>/></code>
</div><p>Note that we have chosen <i>cx</i><sub>0</sub>, since any context is allowed.</p><p>Likewise, we have</p><div class="formula" style="margin-left: 0.5in; margin-right: 0.5in;">
<i>cx</i><sub>0</sub> |- { }; <i>e</i><sub>2</sub> =~ <code><ref</code><code> name="</code><code>bar2</code><code>"</code><code>/></code>
</div><p>By the inference rule (group) in <a href="#choice-pattern" title="6.2.1. choice pattern">Section 6.2.1</a>, we have</p><div class="formula" style="margin-left: 0.5in; margin-right: 0.5in;">
<i>cx</i><sub>0</sub> |- { }; <i>e</i><sub>1</sub>, <i>e</i><sub>2</sub> =~ <code><group</code><code>></code> <code><ref</code><code> name="</code><code>bar1</code><code>"</code><code>/></code> <code><ref</code><code> name="</code><code>bar2</code><code>"</code><code>/></code> <code></group></code>
</div><p>By the inference rule (element) in <a href="#element-pattern" title="6.2.7. element and attribute pattern">Section 6.2.7</a>, we have</p><div class="formula" style="margin-left: 0.5in; margin-right: 0.5in;">
<i>cx</i><sub>3</sub> |- { }; element( name( <code>""</code>, <code>"foo"</code> ), <i>cx</i><sub>0</sub>, { }, <i>m</i> ) =~ <code><ref</code><code> name="</code><code>foo</code><code>"</code><code>/></code>
</div><p>Here <i>cx</i><sub>3</sub> is an arbitrary
context.</p><p>Thus we can apply the inference rule (valid) in <a href="#validity" title="6.3. Validity">Section 6.3</a> and obtain</p><div class="formula" style="margin-left: 0.5in; margin-right: 0.5in;">
valid(<i>e</i><sub>0</sub>)
</div></div></div><div class="section"><a name="restriction"></a><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="restriction"></a>7. Restrictions</h2></div></div><p>The following constraints are all checked after the grammar has
been transformed to the simple form described in <a href="#simple-syntax" title="5. Simple syntax">Section 5</a>. The purpose of these restrictions is to
catch user errors and to facilitate implementation.</p><div class="section"><a name="contextual-restriction"></a><div class="titlepage"><div><h3 class="title"><a name="contextual-restriction"></a>7.1. Contextual restrictions</h3></div></div><p>In this section we describe restrictions on where elements are
allowed in the schema based on the names of the ancestor elements. We
use the concept of a <i>prohibited path</i> to
describe these restrictions. A path is a sequence of NCNames separated
by <tt>/</tt> or <tt>//</tt>.</p><div class="itemizedlist"><ul><li><a name="IDA3JBS"></a>An element matches a path
<i><tt>x</tt></i>, where <i><tt>x</tt></i> is an
NCName, if and only if the local name of the element is
<i><tt>x</tt></i></li><li><a name="IDAFKBS"></a>An element matches a path
<i><tt>x</tt></i><tt>/</tt><i><tt>p</tt></i>,
where <i><tt>x</tt></i> is an NCName and
<i><tt>p</tt></i> is a path, if and only if the local name
of the element is <i><tt>x</tt></i> and the element has a
child that matches <i><tt>p</tt></i></li><li><a name="IDATKBS"></a>An element matches a path
<i><tt>x</tt></i><tt>//</tt><i><tt>p</tt></i>,
where <i><tt>x</tt></i> is an NCName and
<i><tt>p</tt></i> is a path, if and only if the local name
of the element is <i><tt>x</tt></i> and the element has a
descendant that matches <i><tt>p</tt></i></li></ul></div><p>For example, the element</p><pre class="programlisting"><foo>
<bar>
<baz/>
</bar>
</foo></pre><p>matches the paths <tt>foo</tt>,
<tt>foo/bar</tt>, <tt>foo//bar</tt>,
<tt>foo//baz</tt>, <tt>foo/bar/baz</tt>,
<tt>foo/bar//baz</tt> and <tt>foo//bar/baz</tt>,
but not <tt>foo/baz</tt> or
<tt>foobar</tt>.</p><p>A correct RELAX NG schema must be such that, after
transformation to the simple form, it does not contain any element
that matches a prohibited path.</p><div class="section"><a name="IDA3LBS"></a><div class="titlepage"><div><h4 class="title"><a name="IDA3LBS"></a>7.1.1. <tt>attribute</tt> pattern</h4></div></div><p>The following paths are prohibited:</p><div class="itemizedlist"><ul><li><a name="IDAFMBS"></a><tt>attribute//ref</tt></li><li><a name="IDAJMBS"></a><tt>attribute//attribute</tt></li></ul></div></div><div class="section"><a name="IDAPMBS"></a><div class="titlepage"><div><h4 class="title"><a name="IDAPMBS"></a>7.1.2. <tt>oneOrMore</tt> pattern</h4></div></div><p>The following paths are prohibited:</p><div class="itemizedlist"><ul><li><a name="IDAXMBS"></a><tt>oneOrMore//group//attribute</tt></li><li><a name="IDA1MBS"></a><tt>oneOrMore//interleave//attribute</tt></li></ul></div></div><div class="section"><a name="list-restrictions"></a><div class="titlepage"><div><h4 class="title"><a name="list-restrictions"></a>7.1.3. <tt>list</tt> pattern</h4></div></div><p>The following paths are prohibited:</p><div class="itemizedlist"><ul><li><a name="IDALNBS"></a><tt>list//list</tt></li><li><a name="IDAPNBS"></a><tt>list//ref</tt></li><li><a name="IDATNBS"></a><tt>list//attribute</tt></li><li><a name="IDAXNBS"></a><tt>list//text</tt></li><li><a name="IDA1NBS"></a><tt>list//interleave</tt></li></ul></div></div><div class="section"><a name="context-data-except"></a><div class="titlepage"><div><h4 class="title"><a name="context-data-except"></a>7.1.4. <tt>except</tt> in <tt>data</tt> pattern</h4></div></div><p>The following paths are prohibited:</p><div class="itemizedlist"><ul><li><a name="IDANOBS"></a><tt>data/except//attribute</tt></li><li><a name="IDAROBS"></a><tt>data/except//ref</tt></li><li><a name="IDAVOBS"></a><tt>data/except//text</tt></li><li><a name="IDAZOBS"></a><tt>data/except//list</tt></li><li><a name="IDA3OBS"></a><tt>data/except//group</tt></li><li><a name="IDABPBS"></a><tt>data/except//interleave</tt></li><li><a name="IDAFPBS"></a><tt>data/except//oneOrMore</tt></li><li><a name="IDAJPBS"></a><tt>data/except//empty</tt></li></ul></div><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title"><a name="IDAOPBS"></a>Note</h3><p>This implies that an <tt>except</tt> element
with a <tt>data</tt> parent can contain only
<tt>data</tt>, <tt>value</tt> and
<tt>choice</tt> elements.</p></div></div><div class="section"><a name="context-start"></a><div class="titlepage"><div><h4 class="title"><a name="context-start"></a>7.1.5. <tt>start</tt> element</h4></div></div><p>The following paths are prohibited:</p><div class="itemizedlist"><ul><li><a name="IDAJQBS"></a><tt>start//attribute</tt></li><li><a name="IDANQBS"></a><tt>start//data</tt></li><li><a name="IDARQBS"></a><tt>start//value</tt></li><li><a name="IDAVQBS"></a><tt>start//text</tt></li><li><a name="IDAZQBS"></a><tt>start//list</tt></li><li><a name="IDA3QBS"></a><tt>start//group</tt></li><li><a name="IDABRBS"></a><tt>start//interleave</tt></li><li><a name="IDAFRBS"></a><tt>start//oneOrMore</tt></li><li><a name="IDAJRBS"></a><tt>start//empty</tt></li></ul></div></div></div><div class="section"><a name="string-sequences"></a><div class="titlepage"><div><h3 class="title"><a name="string-sequences"></a>7.2. String sequences</h3></div></div><p>RELAX NG does not allow a pattern such as:</p><pre class="programlisting"><element name="foo">
<group>
<data type="int"/>
<element name="bar">
<empty/>
</element>
</group>
</element></pre><p>Nor does it allow a pattern such as:</p><pre class="programlisting"><element name="foo">
<group>
<data type="int"/>
<text/>
</group>
</element></pre><p>More generally, if the pattern for the content of an element or
attribute contains</p><div class="itemizedlist"><ul><li><a name="IDACSBS"></a>a pattern that can match a child
(that is, an <tt>element</tt>, <tt>data</tt>,
<tt>value</tt>, <tt>list</tt> or
<tt>text</tt> pattern), and</li><li><a name="IDAPSBS"></a>a pattern that matches a single string (that is, a
<tt>data</tt>, <tt>value</tt> or
<tt>list</tt> pattern),</li></ul></div><p>then the two patterns must be alternatives to each other.</p><p>This rule does not apply to patterns occurring within a
<tt>list</tt> pattern.</p><p>To formalize this, we use the concept of a content-type. A
pattern that is allowable as the content of an element has one of
three content-types: empty, complex and simple. We use the following
notation.</p><div class="variablelist"><dl><dt><a name="IDACTBS"></a><span class="term">empty( )</span></dt><dd><a name="IDAHTBS"></a>returns the empty content-type</dd><dt><a name="IDALTBS"></a><span class="term">complex( )</span></dt><dd><a name="IDAQTBS"></a>returns the complex content-type</dd><dt><a name="IDAUTBS"></a><span class="term">simple( )</span></dt><dd><a name="IDAZTBS"></a>returns the simple content-type</dd><dt><a name="IDA3TBS"></a><span class="term"><i>ct</i></span></dt><dd><a name="IDACUBS"></a>ranges over content-types</dd><dt><a name="IDAGUBS"></a><span class="term">
groupable(<i>ct</i><sub>1</sub>, <i>ct</i><sub>2</sub>)
</span></dt><dd><a name="IDAVUBS"></a>asserts that the content-types <i>ct</i><sub>1</sub> and <i>ct</i><sub>2</sub>
are groupable</dd></dl></div><p>The empty content-type is groupable with anything. In addition,
the complex content-type is groupable with the complex content-type. The
following rules formalize this.</p>
<table cellspacing="20"><tr valign="middle"><td>(group empty 1)</td><td><table cellpadding="0" cellspacing="0"><tr align="center"><td colspan="0">groupable(empty( ), <i>ct</i>)</td></tr></table></td></tr></table>
<table cellspacing="20"><tr valign="middle"><td>(group empty 2)</td><td><table cellpadding="0" cellspacing="0"><tr align="center"><td colspan="0">groupable(<i>ct</i>, empty( ))</td></tr></table></td></tr></table>
<table cellspacing="20"><tr valign="middle"><td>(group complex)</td><td><table cellpadding="0" cellspacing="0"><tr align="center"><td colspan="0">groupable(complex( ), complex( ))</td></tr></table></td></tr></table>
<p>Some patterns have a content-type. We use the following
additional notation.</p><div class="variablelist"><dl><dt><a name="IDATWBS"></a><span class="term">
<i>p</i> <b>:</b><sub>c</sub> <i>ct</i>
</span></dt><dd><a name="IDAAXBS"></a>asserts that pattern <i>p</i> has
content-type <i>ct</i></dd><dt><a name="IDAJXBS"></a><span class="term">
max( <i>ct</i><sub>1</sub>, <i>ct</i><sub>2</sub> )
</span></dt><dd><a name="IDAYXBS"></a>returns the maximum of <i>ct</i><sub>1</sub> and <i>ct</i><sub>2</sub> where the
content-types in increasing order are empty( ),
complex( ), simple( )</dd></dl></div><p>The following rules define when a pattern has a content-type and,
if so, what it is.</p>
<table cellspacing="20"><tr valign="middle"><td>(value)</td><td><table cellpadding="0" cellspacing="0"><tr align="center"><td colspan="0"><code><value</code><code> datatypeLibrary="</code><i>u</i><sub>1</sub><code>"</code><code> type="</code><i>ln</i><code>"</code><code> ns="</code><i>u</i><sub>2</sub><code>"</code><code>></code> <i>s</i> <code></value></code> <b>:</b><sub>c</sub> simple( )</td></tr></table></td></tr></table>
<table cellspacing="20"><tr valign="middle"><td>(data 1)</td><td><table cellpadding="0" cellspacing="0"><tr align="center"><td colspan="0"><code><data</code><code> datatypeLibrary="</code><i>u</i><code>"</code><code> type="</code><i>ln</i><code>"</code><code>></code> <i>params</i> <code></data></code> <b>:</b><sub>c</sub> simple( )</td></tr></table></td></tr></table>
<table cellspacing="20"><tr valign="middle"><td>(data 2)</td><td><table cellpadding="0" cellspacing="0"><tr align="center" valign="baseline"><td><i>p</i> <b>:</b><sub>c</sub> <i>ct</i></td></tr><tr><td colspan="1"><hr noshade></td></tr><tr align="center"><td colspan="1"><code><data</code><code> datatypeLibrary="</code><i>u</i><code>"</code><code> type="</code><i>ln</i><code>"</code><code>></code> <i>params</i> <code><except</code><code>></code> <i>p</i> <code></except></code> <code></data></code> <b>:</b><sub>c</sub> simple( )</td></tr></table></td></tr></table>
<table cellspacing="20"><tr valign="middle"><td>(list)</td><td><table cellpadding="0" cellspacing="0"><tr align="center"><td colspan="0"><code><list</code><code>></code> <i>p</i> <code></list></code> <b>:</b><sub>c</sub> simple( )</td></tr></table></td></tr></table>
<table cellspacing="20"><tr valign="middle"><td>(text)</td><td><table cellpadding="0" cellspacing="0"><tr align="center"><td colspan="0"><code><text</code><code>/></code> <b>:</b><sub>c</sub> complex( )</td></tr></table></td></tr></table>
<table cellspacing="20"><tr valign="middle"><td>(ref)</td><td><table cellpadding="0" cellspacing="0"><tr align="center"><td colspan="0"><code><ref</code><code> name="</code><i>ln</i><code>"</code><code>/></code> <b>:</b><sub>c</sub> complex( )</td></tr></table></td></tr></table>
<table cellspacing="20"><tr valign="middle"><td>(empty)</td><td><table cellpadding="0" cellspacing="0"><tr align="center"><td colspan="0"><code><empty</code><code>/></code> <b>:</b><sub>c</sub> empty( )</td></tr></table></td></tr></table>
<table cellspacing="20"><tr valign="middle"><td>(attribute)</td><td><table cellpadding="0" cellspacing="0"><tr align="center" valign="baseline"><td><i>p</i> <b>:</b><sub>c</sub> <i>ct</i></td></tr><tr><td colspan="1"><hr noshade></td></tr><tr align="center"><td colspan="1"><code><attribute</code><code>></code> <i>nc</i> <i>p</i> <code></attribute></code> <b>:</b><sub>c</sub> empty( )</td></tr></table></td></tr></table>
<table cellspacing="20"><tr valign="middle"><td>(group)</td><td><table cellpadding="0" cellspacing="0"><tr align="center" valign="baseline"><td><i>p</i><sub>1</sub> <b>:</b><sub>c</sub> <i>ct</i><sub>1</sub></td><td> <i>p</i><sub>2</sub> <b>:</b><sub>c</sub> <i>ct</i><sub>2</sub></td><td> groupable(<i>ct</i><sub>1</sub>, <i>ct</i><sub>2</sub>)</td></tr><tr><td colspan="3"><hr noshade></td></tr><tr align="center"><td colspan="3"><code><group</code><code>></code> <i>p</i><sub>1</sub> <i>p</i><sub>2</sub> <code></group></code> <b>:</b><sub>c</sub> max( <i>ct</i><sub>1</sub>, <i>ct</i><sub>2</sub> )</td></tr></table></td></tr></table>
<table cellspacing="20"><tr valign="middle"><td>(interleave)</td><td><table cellpadding="0" cellspacing="0"><tr align="center" valign="baseline"><td><i>p</i><sub>1</sub> <b>:</b><sub>c</sub> <i>ct</i><sub>1</sub></td><td> <i>p</i><sub>2</sub> <b>:</b><sub>c</sub> <i>ct</i><sub>2</sub></td><td> groupable(<i>ct</i><sub>1</sub>, <i>ct</i><sub>2</sub>)</td></tr><tr><td colspan="3"><hr noshade></td></tr><tr align="center"><td colspan="3"><code><interleave</code><code>></code> <i>p</i><sub>1</sub> <i>p</i><sub>2</sub> <code></interleave></code> <b>:</b><sub>c</sub> max( <i>ct</i><sub>1</sub>, <i>ct</i><sub>2</sub> )</td></tr></table></td></tr></table>
<table cellspacing="20"><tr valign="middle"><td>(oneOrMore)</td><td><table cellpadding="0" cellspacing="0"><tr align="center" valign="baseline"><td><i>p</i> <b>:</b><sub>c</sub> <i>ct</i></td><td> groupable(<i>ct</i>, <i>ct</i>)</td></tr><tr><td colspan="2"><hr noshade></td></tr><tr align="center"><td colspan="2"><code><oneOrMore</code><code>></code> <i>p</i> <code></oneOrMore></code> <b>:</b><sub>c</sub> <i>ct</i></td></tr></table></td></tr></table>
<table cellspacing="20"><tr valign="middle"><td>(choice)</td><td><table cellpadding="0" cellspacing="0"><tr align="center" valign="baseline"><td><i>p</i><sub>1</sub> <b>:</b><sub>c</sub> <i>ct</i><sub>1</sub></td><td> <i>p</i><sub>2</sub> <b>:</b><sub>c</sub> <i>ct</i><sub>2</sub></td></tr><tr><td colspan="2"><hr noshade></td></tr><tr align="center"><td colspan="2"><code><choice</code><code>></code> <i>p</i><sub>1</sub> <i>p</i><sub>2</sub> <code></choice></code> <b>:</b><sub>c</sub> max( <i>ct</i><sub>1</sub>, <i>ct</i><sub>2</sub> )</td></tr></table></td></tr></table>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title"><a name="IDA0GCS"></a>Note</h3><p>The antecedent in the (data 2) rule above is in fact
redundant because of the prohibited paths in <a href="#context-data-except" title="7.1.4. except in data pattern">Section 7.1.4</a>.</p></div><p>Now we can describe the restriction. We use the following
notation.</p><div class="variablelist"><dl><dt><a name="IDADHCS"></a><span class="term">
incorrectSchema()
</span></dt><dd><a name="IDAJHCS"></a>asserts that the schema is incorrect</dd></dl></div><p>All patterns occurring as the content of an element pattern must
have a content-type.</p>
<table cellspacing="20"><tr valign="middle"><td>(element)</td><td><table cellpadding="0" cellspacing="0"><tr align="center" valign="baseline"><td>deref(<i>ln</i>) = <code><element> </code><i>nc</i> <i>p</i><code> </element></code></td><td> not(<i>p</i> <b>:</b><sub>c</sub> <i>ct</i>)</td></tr><tr><td colspan="2"><hr noshade></td></tr><tr align="center"><td colspan="2">incorrectSchema()</td></tr></table></td></tr></table>
</div><div class="section"><a name="attribute-restrictions"></a><div class="titlepage"><div><h3 class="title"><a name="attribute-restrictions"></a>7.3. Restrictions on attributes</h3></div></div><p>Duplicate attributes are not allowed. More precisely, for a
pattern <tt><group> <i><tt>p1</tt></i>
<i><tt>p2</tt></i> </group></tt> or
<tt><interleave> <i><tt>p1</tt></i>
<i><tt>p2</tt></i> </interleave></tt>, there must
not be a name that belongs to both the name class of an
<tt>attribute</tt> pattern occurring in
<i><tt>p1</tt></i> and the name class of an
<tt>attribute</tt> pattern occurring in
<i><tt>p2</tt></i>. A pattern <i><tt>p1</tt></i>
is defined to <i>occur in</i> a pattern
<i><tt>p2</tt></i> if</p><div class="itemizedlist"><ul><li><a name="IDAYJCS"></a><i><tt>p1</tt></i> is
<i><tt>p2</tt></i>, or</li><li><a name="IDA5JCS"></a><i><tt>p2</tt></i> is a
<tt>choice</tt>, <tt>interleave</tt>,
<tt>group</tt> or <tt>oneOrMore</tt> element and
<i><tt>p1</tt></i> occurs in one or more children of
<i><tt>p2</tt></i>.</li></ul></div><p>Attributes using infinite name classes must be repeated. More
precisely, an <tt>attribute</tt> element that has an
<tt>anyName</tt> or <tt>nsName</tt> descendant
element must have a <tt>oneOrMore</tt> ancestor
element.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title"><a name="IDA1KCS"></a>Note</h3><p>This restriction is necessary for closure under
negation.</p></div></div><div class="section"><a name="interleave-restrictions"></a><div class="titlepage"><div><h3 class="title"><a name="interleave-restrictions"></a>7.4. Restrictions on <tt>interleave</tt></h3></div></div><p>For a pattern <tt><interleave>
<i><tt>p1</tt></i> <i><tt>p2</tt></i>
</interleave></tt>,</p><div class="itemizedlist"><ul><li><a name="IDAOLCS"></a>there must not be a name that belongs to both the name
class of an <tt>element</tt> pattern referenced by a
<tt>ref</tt> pattern occurring in
<i><tt>p1</tt></i> and the name class of an
<tt>element</tt> pattern referenced by a
<tt>ref</tt> pattern occurring in
<i><tt>p2</tt></i>, and</li><li><a name="IDA3LCS"></a>a <tt>text</tt> pattern must not occur in
both <i><tt>p1</tt></i> and
<i><tt>p2</tt></i>.</li></ul></div><p><a href="#attribute-restrictions" title="7.3. Restrictions on attributes">Section 7.3</a> defines when one
pattern is considered to occur in another pattern.</p></div></div><div class="section"><a name="conformance"></a><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="conformance"></a>8. Conformance</h2></div></div><p>A conforming RELAX NG validator must be able to determine for
any XML document whether it is a correct RELAX NG schema. A
conforming RELAX NG validator must be able to determine for any XML
document and for any correct RELAX NG schema whether the document is
valid with respect to the schema.</p><p>However, the requirements in the preceding paragraph do not
apply if the schema uses a datatype library that the validator does
not support. A conforming RELAX NG validator is only required to
support the built-in datatype library described in <a href="#built-in-datatype" title="6.2.9. Built-in datatype library">Section 6.2.9</a>. A validator that claims conformance to
RELAX NG should document which datatype libraries it supports. The
requirements in the preceding paragraph also do not apply if the
schema includes <tt>externalRef</tt> or
<tt>include</tt> elements and the validator is unable to
retrieve the resource identified by the URI or is unable to construct
an element from the retrieved resource. A validator that claims
conformance to RELAX NG should document its capabilities for handling
URI references.</p></div><div class="appendix"><h2 class="title" style="clear: both"><a name="IDA5MCS"></a>A. RELAX NG schema for RELAX NG</h2><pre><grammar datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"
ns="http://relaxng.org/ns/structure/1.0"
xmlns="http://relaxng.org/ns/structure/1.0">
<start>