~ubuntu-branches/ubuntu/hardy/pxp/hardy

« back to all changes in this revision

Viewing changes to doc/manual/html/x107.html

  • Committer: Bazaar Package Importer
  • Author(s): Stefano Zacchiroli
  • Date: 2005-03-29 11:06:39 UTC
  • mfrom: (2.1.2 hoary)
  • Revision ID: james.westby@ubuntu.com-20050329110639-5p39hz1d4aq3r2ec
Tags: 1.1.95-6
* Rebuilt against ocaml 3.08.3
* No longer built with wlex support (since wlex is no longer supported
  upstream and corresponding package has been removed from the debian
  archive)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<HTML
2
 
><HEAD
3
 
><TITLE
4
 
>Highlights of XML</TITLE
5
 
><META
6
 
NAME="GENERATOR"
7
 
CONTENT="Modular DocBook HTML Stylesheet Version 1.46"><LINK
8
 
REL="HOME"
9
 
TITLE="The PXP user's guide"
10
 
HREF="index.html"><LINK
11
 
REL="UP"
12
 
TITLE="What is XML?"
13
 
HREF="c36.html"><LINK
14
 
REL="PREVIOUS"
15
 
TITLE="What is XML?"
16
 
HREF="c36.html"><LINK
17
 
REL="NEXT"
18
 
TITLE="A complete example: The readme DTD"
19
 
HREF="x468.html"><LINK
20
 
REL="STYLESHEET"
21
 
TYPE="text/css"
22
 
HREF="markup.css"></HEAD
23
 
><BODY
24
 
CLASS="SECT1"
25
 
BGCOLOR="#FFFFFF"
26
 
TEXT="#000000"
27
 
LINK="#0000FF"
28
 
VLINK="#840084"
29
 
ALINK="#0000FF"
30
 
><DIV
31
 
CLASS="NAVHEADER"
32
 
><TABLE
33
 
WIDTH="100%"
34
 
BORDER="0"
35
 
CELLPADDING="0"
36
 
CELLSPACING="0"
37
 
><TR
38
 
><TH
39
 
COLSPAN="3"
40
 
ALIGN="center"
41
 
>The PXP user's guide</TH
42
 
></TR
43
 
><TR
44
 
><TD
45
 
WIDTH="10%"
46
 
ALIGN="left"
47
 
VALIGN="bottom"
48
 
><A
49
 
HREF="c36.html"
50
 
>Prev</A
51
 
></TD
52
 
><TD
53
 
WIDTH="80%"
54
 
ALIGN="center"
55
 
VALIGN="bottom"
56
 
>Chapter 1. What is XML?</TD
57
 
><TD
58
 
WIDTH="10%"
59
 
ALIGN="right"
60
 
VALIGN="bottom"
61
 
><A
62
 
HREF="x468.html"
63
 
>Next</A
64
 
></TD
65
 
></TR
66
 
></TABLE
67
 
><HR
68
 
ALIGN="LEFT"
69
 
WIDTH="100%"></DIV
70
 
><DIV
71
 
CLASS="SECT1"
72
 
><H1
73
 
CLASS="SECT1"
74
 
><A
75
 
NAME="AEN107"
76
 
>1.2. Highlights of XML</A
77
 
></H1
78
 
><P
79
 
>This section explains many of the features of XML, but not all, and some
80
 
features not in detail. For a complete description, see the <A
81
 
HREF="http://www.w3.org/TR/1998/REC-xml-19980210.html"
82
 
TARGET="_top"
83
 
>XML
84
 
specification</A
85
 
>.</P
86
 
><DIV
87
 
CLASS="SECT2"
88
 
><H2
89
 
CLASS="SECT2"
90
 
><A
91
 
NAME="AEN111"
92
 
>1.2.1. The DTD and the instance</A
93
 
></H2
94
 
><P
95
 
>The DTD contains various declarations; in general you can only use a feature if
96
 
you have previously declared it. The document instance file may contain the
97
 
full DTD, but it is also possible to split the DTD into an internal and an
98
 
external subset. A document must begin as follows if the full DTD is included:
99
 
 
100
 
<PRE
101
 
CLASS="PROGRAMLISTING"
102
 
>&lt;?xml version="1.0" encoding="<TT
103
 
CLASS="REPLACEABLE"
104
 
><I
105
 
>Your encoding</I
106
 
></TT
107
 
>"?&gt;
108
 
&lt;!DOCTYPE <TT
109
 
CLASS="REPLACEABLE"
110
 
><I
111
 
>root</I
112
 
></TT
113
 
> [
114
 
  <TT
115
 
CLASS="REPLACEABLE"
116
 
><I
117
 
>Declarations</I
118
 
></TT
119
 
>
120
 
]&gt;</PRE
121
 
>
122
 
 
123
 
These declarations are called the <I
124
 
CLASS="EMPHASIS"
125
 
>internal subset</I
126
 
>. Note
127
 
that the usage of entities and conditional sections is restricted within the
128
 
internal subset.</P
129
 
><P
130
 
>If the declarations are located in a different file, you can refer to this file
131
 
as follows:
132
 
 
133
 
<PRE
134
 
CLASS="PROGRAMLISTING"
135
 
>&lt;?xml version="1.0" encoding="<TT
136
 
CLASS="REPLACEABLE"
137
 
><I
138
 
>Your encoding</I
139
 
></TT
140
 
>"?&gt;
141
 
&lt;!DOCTYPE <TT
142
 
CLASS="REPLACEABLE"
143
 
><I
144
 
>root</I
145
 
></TT
146
 
> SYSTEM "<TT
147
 
CLASS="REPLACEABLE"
148
 
><I
149
 
>file name</I
150
 
></TT
151
 
>"&gt;</PRE
152
 
>
153
 
 
154
 
The declarations in the file are called the <I
155
 
CLASS="EMPHASIS"
156
 
>external
157
 
subset</I
158
 
>. The file name is called the <I
159
 
CLASS="EMPHASIS"
160
 
>system
161
 
identifier</I
162
 
>. 
163
 
It is also possible to refer to the file by a so-called
164
 
<I
165
 
CLASS="EMPHASIS"
166
 
>public identifier</I
167
 
>, but most XML applications won't use
168
 
this feature.</P
169
 
><P
170
 
>You can also specify both internal and external subsets. In this case, the
171
 
declarations of both subsets are mixed, and if there are conflicts, the
172
 
declaration of the internal subset overrides those of the external subset with
173
 
the same name. This looks as follows:
174
 
 
175
 
<PRE
176
 
CLASS="PROGRAMLISTING"
177
 
>&lt;?xml version="1.0" encoding="<TT
178
 
CLASS="REPLACEABLE"
179
 
><I
180
 
>Your encoding</I
181
 
></TT
182
 
>"?&gt;
183
 
&lt;!DOCTYPE <TT
184
 
CLASS="REPLACEABLE"
185
 
><I
186
 
>root</I
187
 
></TT
188
 
>  SYSTEM "<TT
189
 
CLASS="REPLACEABLE"
190
 
><I
191
 
>file name</I
192
 
></TT
193
 
>" [
194
 
  <TT
195
 
CLASS="REPLACEABLE"
196
 
><I
197
 
>Declarations</I
198
 
></TT
199
 
>
200
 
]&gt;</PRE
201
 
></P
202
 
><P
203
 
>The XML declaration (the string beginning with <TT
204
 
CLASS="LITERAL"
205
 
>&lt;?xml</TT
206
 
> and
207
 
ending at <TT
208
 
CLASS="LITERAL"
209
 
>?&gt;</TT
210
 
>) should specify the encoding of the
211
 
file. Common values are UTF-8, and the ISO-8859 series of character sets. Note
212
 
that every file parsed by the XML processor can begin with an XML declaration
213
 
and that every file may have its own encoding.</P
214
 
><P
215
 
>The name of the root element must be mentioned directly after the
216
 
<TT
217
 
CLASS="LITERAL"
218
 
>DOCTYPE</TT
219
 
> string. This means that a full document instance
220
 
looks like
221
 
 
222
 
<PRE
223
 
CLASS="PROGRAMLISTING"
224
 
>&lt;?xml version="1.0" encoding="<TT
225
 
CLASS="REPLACEABLE"
226
 
><I
227
 
>Your encoding</I
228
 
></TT
229
 
>"?&gt;
230
 
&lt;!DOCTYPE <TT
231
 
CLASS="REPLACEABLE"
232
 
><I
233
 
>root</I
234
 
></TT
235
 
>  SYSTEM "<TT
236
 
CLASS="REPLACEABLE"
237
 
><I
238
 
>file name</I
239
 
></TT
240
 
>" [
241
 
  <TT
242
 
CLASS="REPLACEABLE"
243
 
><I
244
 
>Declarations</I
245
 
></TT
246
 
>
247
 
]&gt;
248
 
 
249
 
&lt;<TT
250
 
CLASS="REPLACEABLE"
251
 
><I
252
 
>root</I
253
 
></TT
254
 
>&gt;
255
 
  <TT
256
 
CLASS="REPLACEABLE"
257
 
><I
258
 
>inner contents</I
259
 
></TT
260
 
>
261
 
&lt;/<TT
262
 
CLASS="REPLACEABLE"
263
 
><I
264
 
>root</I
265
 
></TT
266
 
>&gt;</PRE
267
 
></P
268
 
></DIV
269
 
><DIV
270
 
CLASS="SECT2"
271
 
><H2
272
 
CLASS="SECT2"
273
 
><A
274
 
NAME="AEN146"
275
 
>1.2.2. Reserved characters</A
276
 
></H2
277
 
><P
278
 
>Some characters are generally reserved to indicate markup such that they cannot
279
 
be used for character data. These characters are &lt;, &gt;, and
280
 
&amp;. Furthermore, single and double quotes are sometimes reserved. If you
281
 
want to include such a character as character, write it as follows:
282
 
 
283
 
<P
284
 
></P
285
 
><UL
286
 
COMPACT="COMPACT"
287
 
><LI
288
 
STYLE="list-style-type: disc"
289
 
><P
290
 
><TT
291
 
CLASS="LITERAL"
292
 
>&amp;lt;</TT
293
 
> instead of &lt;</P
294
 
></LI
295
 
><LI
296
 
STYLE="list-style-type: disc"
297
 
><P
298
 
><TT
299
 
CLASS="LITERAL"
300
 
>&amp;gt;</TT
301
 
> instead of &gt;</P
302
 
></LI
303
 
><LI
304
 
STYLE="list-style-type: disc"
305
 
><P
306
 
><TT
307
 
CLASS="LITERAL"
308
 
>&amp;amp;</TT
309
 
> instead of &amp;</P
310
 
></LI
311
 
><LI
312
 
STYLE="list-style-type: disc"
313
 
><P
314
 
><TT
315
 
CLASS="LITERAL"
316
 
>&amp;apos;</TT
317
 
> instead of '</P
318
 
></LI
319
 
><LI
320
 
STYLE="list-style-type: disc"
321
 
><P
322
 
><TT
323
 
CLASS="LITERAL"
324
 
>&amp;quot;</TT
325
 
> instead of "</P
326
 
></LI
327
 
></UL
328
 
>
329
 
 
330
 
All other characters are free in the document instance. It is possible to
331
 
include a character by its position in the Unicode alphabet: 
332
 
 
333
 
<PRE
334
 
CLASS="PROGRAMLISTING"
335
 
>&amp;#<TT
336
 
CLASS="REPLACEABLE"
337
 
><I
338
 
>n</I
339
 
></TT
340
 
>;</PRE
341
 
>
342
 
 
343
 
where <TT
344
 
CLASS="REPLACEABLE"
345
 
><I
346
 
>n</I
347
 
></TT
348
 
> is the decimal number of the
349
 
character. Alternatively, you can specify the character by its hexadecimal
350
 
number: 
351
 
 
352
 
<PRE
353
 
CLASS="PROGRAMLISTING"
354
 
>&amp;#x<TT
355
 
CLASS="REPLACEABLE"
356
 
><I
357
 
>n</I
358
 
></TT
359
 
>;</PRE
360
 
>
361
 
 
362
 
In the scope of declarations, the character % is no longer free. To include it
363
 
as character, you must use the notations <TT
364
 
CLASS="LITERAL"
365
 
>&amp;#37;</TT
366
 
> or
367
 
<TT
368
 
CLASS="LITERAL"
369
 
>&amp;#x25;</TT
370
 
>.</P
371
 
><P
372
 
>Note that besides &amp;lt;, &amp;gt;, &amp;amp;,
373
 
&amp;apos;, and &amp;quot; there are no predefines character entities. This is
374
 
different from HTML which defines a list of characters that can be referenced
375
 
by name (e.g. &amp;auml; for �); however, if you prefer named characters, you
376
 
can declare such entities yourself (see below).</P
377
 
></DIV
378
 
><DIV
379
 
CLASS="SECT2"
380
 
><H2
381
 
CLASS="SECT2"
382
 
><A
383
 
NAME="AEN173"
384
 
>1.2.3. Elements and ELEMENT declarations</A
385
 
></H2
386
 
><P
387
 
>Elements structure the document instance in a hierarchical way. There is a
388
 
top-level element, the <I
389
 
CLASS="EMPHASIS"
390
 
>root element</I
391
 
>, which contains a
392
 
sequence of inner elements and character sections. The inner elements are
393
 
structured in the same way. Every element has an <I
394
 
CLASS="EMPHASIS"
395
 
>element
396
 
type</I
397
 
>. The beginning of the element is indicated by a <I
398
 
CLASS="EMPHASIS"
399
 
>start
400
 
tag</I
401
 
>, written
402
 
 
403
 
<PRE
404
 
CLASS="PROGRAMLISTING"
405
 
>&lt;<TT
406
 
CLASS="REPLACEABLE"
407
 
><I
408
 
>element-type</I
409
 
></TT
410
 
>&gt;</PRE
411
 
>
412
 
 
413
 
and the element continues until the corresponding <I
414
 
CLASS="EMPHASIS"
415
 
>end tag</I
416
 
>
417
 
is reached:
418
 
 
419
 
<PRE
420
 
CLASS="PROGRAMLISTING"
421
 
>&lt;/<TT
422
 
CLASS="REPLACEABLE"
423
 
><I
424
 
>element-type</I
425
 
></TT
426
 
>&gt;</PRE
427
 
>
428
 
 
429
 
In XML, it is not allowed to omit start or end tags, even if the DTD would
430
 
permit this. Note that there are no special rules how to interpret spaces or
431
 
newlines near start or end tags; all spaces and newlines count.</P
432
 
><P
433
 
>Every element type must be declared before it can be used. The declaration
434
 
consists of two parts: the ELEMENT declaration describes the content model,
435
 
i.e. which inner elements are allowed; the ATTLIST declaration describes the
436
 
attributes of the element.</P
437
 
><P
438
 
>An element can simply allow everything as content. This is written:
439
 
 
440
 
<PRE
441
 
CLASS="PROGRAMLISTING"
442
 
>&lt;!ELEMENT <TT
443
 
CLASS="REPLACEABLE"
444
 
><I
445
 
>name</I
446
 
></TT
447
 
> ANY&gt;</PRE
448
 
>
449
 
 
450
 
On the opposite, an element can be forced to be empty; declared by:
451
 
 
452
 
<PRE
453
 
CLASS="PROGRAMLISTING"
454
 
>&lt;!ELEMENT <TT
455
 
CLASS="REPLACEABLE"
456
 
><I
457
 
>name</I
458
 
></TT
459
 
> EMPTY&gt;</PRE
460
 
>
461
 
 
462
 
Note that there is an abbreviated notation for empty element instances:
463
 
<TT
464
 
CLASS="LITERAL"
465
 
>&lt;<TT
466
 
CLASS="REPLACEABLE"
467
 
><I
468
 
>name</I
469
 
></TT
470
 
>/&gt;</TT
471
 
>. </P
472
 
><P
473
 
>There are two more sophisticated forms of declarations: so-called
474
 
<I
475
 
CLASS="EMPHASIS"
476
 
>mixed declarations</I
477
 
>, and <I
478
 
CLASS="EMPHASIS"
479
 
>regular
480
 
expressions</I
481
 
>. An element with mixed content contains character data
482
 
interspersed with inner elements, and the set of allowed inner elements can be
483
 
specified. In contrast to this, a regular expression declaration does not allow
484
 
character data, but the inner elements can be described by the more powerful
485
 
means of regular expressions.</P
486
 
><P
487
 
>A declaration for mixed content looks as follows:
488
 
 
489
 
<PRE
490
 
CLASS="PROGRAMLISTING"
491
 
>&lt;!ELEMENT <TT
492
 
CLASS="REPLACEABLE"
493
 
><I
494
 
>name</I
495
 
></TT
496
 
> (#PCDATA | <TT
497
 
CLASS="REPLACEABLE"
498
 
><I
499
 
>element<SUB
500
 
>1</SUB
501
 
></I
502
 
></TT
503
 
> | ... | <TT
504
 
CLASS="REPLACEABLE"
505
 
><I
506
 
>element<SUB
507
 
>n</SUB
508
 
></I
509
 
></TT
510
 
> )*&gt;</PRE
511
 
>
512
 
 
513
 
or if you do not want to allow any inner element, simply
514
 
 
515
 
<PRE
516
 
CLASS="PROGRAMLISTING"
517
 
>&lt;!ELEMENT <TT
518
 
CLASS="REPLACEABLE"
519
 
><I
520
 
>name</I
521
 
></TT
522
 
> (#PCDATA)&gt;</PRE
523
 
></P
524
 
><BLOCKQUOTE
525
 
CLASS="BLOCKQUOTE"
526
 
><P
527
 
><B
528
 
>Example</B
529
 
></P
530
 
><P
531
 
>If element type <TT
532
 
CLASS="LITERAL"
533
 
>q</TT
534
 
> is declared as
535
 
 
536
 
<PRE
537
 
CLASS="PROGRAMLISTING"
538
 
>&#60;!ELEMENT q (#PCDATA | r | s)*&#62;</PRE
539
 
>
540
 
 
541
 
this is a legal instance:
542
 
 
543
 
<PRE
544
 
CLASS="PROGRAMLISTING"
545
 
>&#60;q&#62;This is character data&#60;r&#62;&#60;/r&#62;with &#60;s&#62;&#60;/s&#62;inner elements&#60;/q&#62;</PRE
546
 
>
547
 
 
548
 
But this is illegal because <TT
549
 
CLASS="LITERAL"
550
 
>t</TT
551
 
> has not been enumerated in the
552
 
declaration:
553
 
 
554
 
<PRE
555
 
CLASS="PROGRAMLISTING"
556
 
>&#60;q&#62;This is character data&#60;r&#62;&#60;/r&#62;with &#60;t&#62;&#60;/t&#62;inner elements&#60;/q&#62;</PRE
557
 
></P
558
 
></BLOCKQUOTE
559
 
><P
560
 
>The other form uses a regular expression to describe the possible contents:
561
 
 
562
 
<PRE
563
 
CLASS="PROGRAMLISTING"
564
 
>&lt;!ELEMENT <TT
565
 
CLASS="REPLACEABLE"
566
 
><I
567
 
>name</I
568
 
></TT
569
 
> <TT
570
 
CLASS="REPLACEABLE"
571
 
><I
572
 
>regexp</I
573
 
></TT
574
 
>&gt;</PRE
575
 
>
576
 
 
577
 
The following well-known regexp operators are allowed:
578
 
 
579
 
<P
580
 
></P
581
 
><UL
582
 
COMPACT="COMPACT"
583
 
><LI
584
 
STYLE="list-style-type: disc"
585
 
><P
586
 
><TT
587
 
CLASS="LITERAL"
588
 
><TT
589
 
CLASS="REPLACEABLE"
590
 
><I
591
 
>element-name</I
592
 
></TT
593
 
></TT
594
 
></P
595
 
></LI
596
 
><LI
597
 
STYLE="list-style-type: disc"
598
 
><P
599
 
><TT
600
 
CLASS="LITERAL"
601
 
>(<TT
602
 
CLASS="REPLACEABLE"
603
 
><I
604
 
>subexpr<SUB
605
 
>1</SUB
606
 
></I
607
 
></TT
608
 
> ,</TT
609
 
> ... <TT
610
 
CLASS="LITERAL"
611
 
>, <TT
612
 
CLASS="REPLACEABLE"
613
 
><I
614
 
>subexpr<SUB
615
 
>n</SUB
616
 
></I
617
 
></TT
618
 
> )</TT
619
 
></P
620
 
></LI
621
 
><LI
622
 
STYLE="list-style-type: disc"
623
 
><P
624
 
><TT
625
 
CLASS="LITERAL"
626
 
>(<TT
627
 
CLASS="REPLACEABLE"
628
 
><I
629
 
>subexpr<SUB
630
 
>1</SUB
631
 
></I
632
 
></TT
633
 
> |</TT
634
 
> ... <TT
635
 
CLASS="LITERAL"
636
 
>| <TT
637
 
CLASS="REPLACEABLE"
638
 
><I
639
 
>subexpr<SUB
640
 
>n</SUB
641
 
></I
642
 
></TT
643
 
> )</TT
644
 
></P
645
 
></LI
646
 
><LI
647
 
STYLE="list-style-type: disc"
648
 
><P
649
 
><TT
650
 
CLASS="LITERAL"
651
 
><TT
652
 
CLASS="REPLACEABLE"
653
 
><I
654
 
>subexpr</I
655
 
></TT
656
 
>*</TT
657
 
></P
658
 
></LI
659
 
><LI
660
 
STYLE="list-style-type: disc"
661
 
><P
662
 
><TT
663
 
CLASS="LITERAL"
664
 
><TT
665
 
CLASS="REPLACEABLE"
666
 
><I
667
 
>subexpr</I
668
 
></TT
669
 
>+</TT
670
 
></P
671
 
></LI
672
 
><LI
673
 
STYLE="list-style-type: disc"
674
 
><P
675
 
><TT
676
 
CLASS="LITERAL"
677
 
><TT
678
 
CLASS="REPLACEABLE"
679
 
><I
680
 
>subexpr</I
681
 
></TT
682
 
>?</TT
683
 
></P
684
 
></LI
685
 
></UL
686
 
>
687
 
 
688
 
The <TT
689
 
CLASS="LITERAL"
690
 
>,</TT
691
 
> operator indicates a sequence of sub-models, the
692
 
<TT
693
 
CLASS="LITERAL"
694
 
>|</TT
695
 
> operator describes alternative sub-models. The
696
 
<TT
697
 
CLASS="LITERAL"
698
 
>*</TT
699
 
> indicates zero or more repetitions, and
700
 
<TT
701
 
CLASS="LITERAL"
702
 
>+</TT
703
 
> one or more repetitions. Finally, <TT
704
 
CLASS="LITERAL"
705
 
>?</TT
706
 
> can
707
 
be used for optional sub-models. As atoms the regexp can contain names of
708
 
elements; note that it is not allowed to include <TT
709
 
CLASS="LITERAL"
710
 
>#PCDATA</TT
711
 
>.</P
712
 
><P
713
 
>The exact syntax of the regular expressions is rather strange. This can be
714
 
explained best by a list of constraints:
715
 
 
716
 
<P
717
 
></P
718
 
><UL
719
 
COMPACT="COMPACT"
720
 
><LI
721
 
STYLE="list-style-type: disc"
722
 
><P
723
 
>The outermost expression must not be
724
 
<TT
725
 
CLASS="LITERAL"
726
 
><TT
727
 
CLASS="REPLACEABLE"
728
 
><I
729
 
>element-name</I
730
 
></TT
731
 
></TT
732
 
>. </P
733
 
><P
734
 
><I
735
 
CLASS="EMPHASIS"
736
 
>Illegal:</I
737
 
738
 
<TT
739
 
CLASS="LITERAL"
740
 
>&#60;!ELEMENT x y&#62;</TT
741
 
>; this must be written as
742
 
<TT
743
 
CLASS="LITERAL"
744
 
>&#60;!ELEMENT x (y)&#62;</TT
745
 
>.</P
746
 
></LI
747
 
><LI
748
 
STYLE="list-style-type: disc"
749
 
><P
750
 
>For the unary operators <TT
751
 
CLASS="LITERAL"
752
 
><TT
753
 
CLASS="REPLACEABLE"
754
 
><I
755
 
>subexpr</I
756
 
></TT
757
 
>*</TT
758
 
>,
759
 
<TT
760
 
CLASS="LITERAL"
761
 
><TT
762
 
CLASS="REPLACEABLE"
763
 
><I
764
 
>subexpr</I
765
 
></TT
766
 
>+</TT
767
 
>, and
768
 
<TT
769
 
CLASS="LITERAL"
770
 
><TT
771
 
CLASS="REPLACEABLE"
772
 
><I
773
 
>subexpr</I
774
 
></TT
775
 
>?</TT
776
 
>, the
777
 
<TT
778
 
CLASS="LITERAL"
779
 
><TT
780
 
CLASS="REPLACEABLE"
781
 
><I
782
 
>subexpr</I
783
 
></TT
784
 
></TT
785
 
> must not be again an
786
 
unary operator.</P
787
 
><P
788
 
><I
789
 
CLASS="EMPHASIS"
790
 
>Illegal:</I
791
 
792
 
<TT
793
 
CLASS="LITERAL"
794
 
>&#60;!ELEMENT x y**&#62;</TT
795
 
>; this must be written as
796
 
<TT
797
 
CLASS="LITERAL"
798
 
>&#60;!ELEMENT x (y*)*&#62;</TT
799
 
>.</P
800
 
></LI
801
 
><LI
802
 
STYLE="list-style-type: disc"
803
 
><P
804
 
>Between <TT
805
 
CLASS="LITERAL"
806
 
>)</TT
807
 
> and one of the unary operatory
808
 
<TT
809
 
CLASS="LITERAL"
810
 
>*</TT
811
 
>, <TT
812
 
CLASS="LITERAL"
813
 
>+</TT
814
 
>, or <TT
815
 
CLASS="LITERAL"
816
 
>?</TT
817
 
>, there must
818
 
not be whitespace.</P
819
 
><P
820
 
><I
821
 
CLASS="EMPHASIS"
822
 
>Illegal:</I
823
 
824
 
<TT
825
 
CLASS="LITERAL"
826
 
>&#60;!ELEMENT x (y|z) *&#62;</TT
827
 
>; this must be written as
828
 
<TT
829
 
CLASS="LITERAL"
830
 
>&#60;!ELEMENT x (y|z)*&#62;</TT
831
 
>.</P
832
 
></LI
833
 
><LI
834
 
STYLE="list-style-type: disc"
835
 
><P
836
 
>There is the additional constraint that the
837
 
right parenthsis must be contained in the same entity as the left parenthesis;
838
 
see the section about parsed entities below.</P
839
 
></LI
840
 
></UL
841
 
>&#13;</P
842
 
><P
843
 
>Note that there is another restriction on regular expressions which must be
844
 
deterministic. This means that the parser must be able to see by looking at the
845
 
next token which alternative is actually used, or whether the repetition
846
 
stops. The reason for this is simply compatability with SGML (there is no
847
 
intrinsic reason for this rule; XML can live without this restriction).</P
848
 
><BLOCKQUOTE
849
 
CLASS="BLOCKQUOTE"
850
 
><P
851
 
><B
852
 
>Example</B
853
 
></P
854
 
><P
855
 
>The elements are declared as follows:
856
 
 
857
 
<PRE
858
 
CLASS="PROGRAMLISTING"
859
 
>&#60;!ELEMENT q (r?, (s | t)+)&#62;
860
 
&#60;!ELEMENT r (#PCDATA)&#62;
861
 
&#60;!ELEMENT s EMPTY&#62;
862
 
&#60;!ELEMENT t (q | r)&#62;</PRE
863
 
>
864
 
 
865
 
This is a legal instance:
866
 
 
867
 
<PRE
868
 
CLASS="PROGRAMLISTING"
869
 
>&#60;q&#62;&#60;r&#62;Some characters&#60;/r&#62;&#60;s/&#62;&#60;/q&#62;</PRE
870
 
>
871
 
 
872
 
(Note: <TT
873
 
CLASS="LITERAL"
874
 
>&lt;s/&gt;</TT
875
 
> is an abbreviation for
876
 
<TT
877
 
CLASS="LITERAL"
878
 
>&lt;s&gt;&lt;/s&gt;</TT
879
 
>.)
880
 
 
881
 
It would be illegal to leave <TT
882
 
CLASS="LITERAL"
883
 
>&#60;s/&#62;</TT
884
 
> out because at
885
 
least one instance of <TT
886
 
CLASS="LITERAL"
887
 
>s</TT
888
 
> or <TT
889
 
CLASS="LITERAL"
890
 
>t</TT
891
 
> must be
892
 
present. It would be illegal, too, if characters existed outside the
893
 
<TT
894
 
CLASS="LITERAL"
895
 
>r</TT
896
 
> element; the only exception is white space. -- This is
897
 
legal, too:
898
 
 
899
 
<PRE
900
 
CLASS="PROGRAMLISTING"
901
 
>&#60;q&#62;&#60;s/&#62;&#60;t&#62;&#60;q&#62;&#60;s/&#62;&#60;/q&#62;&#60;/t&#62;&#60;/q&#62;</PRE
902
 
></P
903
 
></BLOCKQUOTE
904
 
></DIV
905
 
><DIV
906
 
CLASS="SECT2"
907
 
><H2
908
 
CLASS="SECT2"
909
 
><A
910
 
NAME="AEN304"
911
 
>1.2.4. Attribute lists and ATTLIST declarations</A
912
 
></H2
913
 
><P
914
 
>Elements may have attributes. These are put into the start tag of an element as
915
 
follows:
916
 
 
917
 
<PRE
918
 
CLASS="PROGRAMLISTING"
919
 
>&lt;<TT
920
 
CLASS="REPLACEABLE"
921
 
><I
922
 
>element-name</I
923
 
></TT
924
 
> <TT
925
 
CLASS="REPLACEABLE"
926
 
><I
927
 
>attribute<SUB
928
 
>1</SUB
929
 
></I
930
 
></TT
931
 
>="<TT
932
 
CLASS="REPLACEABLE"
933
 
><I
934
 
>value<SUB
935
 
>1</SUB
936
 
></I
937
 
></TT
938
 
>" ... <TT
939
 
CLASS="REPLACEABLE"
940
 
><I
941
 
>attribute<SUB
942
 
>n</SUB
943
 
></I
944
 
></TT
945
 
>="<TT
946
 
CLASS="REPLACEABLE"
947
 
><I
948
 
>value<SUB
949
 
>n</SUB
950
 
></I
951
 
></TT
952
 
>"&gt;</PRE
953
 
>
954
 
 
955
 
Instead of
956
 
<TT
957
 
CLASS="LITERAL"
958
 
>"<TT
959
 
CLASS="REPLACEABLE"
960
 
><I
961
 
>value<SUB
962
 
>k</SUB
963
 
></I
964
 
></TT
965
 
>"</TT
966
 
>
967
 
it is also possible to use single quotes as in
968
 
<TT
969
 
CLASS="LITERAL"
970
 
>'<TT
971
 
CLASS="REPLACEABLE"
972
 
><I
973
 
>value<SUB
974
 
>k</SUB
975
 
></I
976
 
></TT
977
 
>'</TT
978
 
>.
979
 
Note that you cannot use double quotes literally within the value of the
980
 
attribute if double quotes are the delimiters; the same applies to single
981
 
quotes. You can generally not use &lt; and &amp; as characters in attribute
982
 
values. It is possible to include the paraphrases &amp;lt;, &amp;gt;,
983
 
&amp;amp;, &amp;apos;, and &amp;quot; (and any other reference to a general
984
 
entity as long as the entity is not defined by an external file) as well as
985
 
&amp;#<TT
986
 
CLASS="REPLACEABLE"
987
 
><I
988
 
>n</I
989
 
></TT
990
 
>;.</P
991
 
><P
992
 
>Before you can use an attribute you must declare it. An ATTLIST declaration
993
 
looks as follows:
994
 
 
995
 
<PRE
996
 
CLASS="PROGRAMLISTING"
997
 
>&lt;!ATTLIST <TT
998
 
CLASS="REPLACEABLE"
999
 
><I
1000
 
>element-name</I
1001
 
></TT
1002
 
1003
 
          <TT
1004
 
CLASS="REPLACEABLE"
1005
 
><I
1006
 
>attribute-name</I
1007
 
></TT
1008
 
> <TT
1009
 
CLASS="REPLACEABLE"
1010
 
><I
1011
 
>attribute-type</I
1012
 
></TT
1013
 
> <TT
1014
 
CLASS="REPLACEABLE"
1015
 
><I
1016
 
>attribute-default</I
1017
 
></TT
1018
 
>
1019
 
          ...
1020
 
          <TT
1021
 
CLASS="REPLACEABLE"
1022
 
><I
1023
 
>attribute-name</I
1024
 
></TT
1025
 
> <TT
1026
 
CLASS="REPLACEABLE"
1027
 
><I
1028
 
>attribute-type</I
1029
 
></TT
1030
 
> <TT
1031
 
CLASS="REPLACEABLE"
1032
 
><I
1033
 
>attribute-default</I
1034
 
></TT
1035
 
>
1036
 
&gt;</PRE
1037
 
>
1038
 
 
1039
 
There are a lot of types, but most important are:
1040
 
 
1041
 
<P
1042
 
></P
1043
 
><UL
1044
 
COMPACT="COMPACT"
1045
 
><LI
1046
 
STYLE="list-style-type: disc"
1047
 
><P
1048
 
><TT
1049
 
CLASS="LITERAL"
1050
 
>CDATA</TT
1051
 
>: Every string is allowed as attribute value.</P
1052
 
></LI
1053
 
><LI
1054
 
STYLE="list-style-type: disc"
1055
 
><P
1056
 
><TT
1057
 
CLASS="LITERAL"
1058
 
>NMTOKEN</TT
1059
 
>: Every nametoken is allowed as attribute
1060
 
value. Nametokens consist (mainly) of letters, digits, ., :, -, _ in arbitrary
1061
 
order.</P
1062
 
></LI
1063
 
><LI
1064
 
STYLE="list-style-type: disc"
1065
 
><P
1066
 
><TT
1067
 
CLASS="LITERAL"
1068
 
>NMTOKENS</TT
1069
 
>: A space-separated list of nametokens is allowed as
1070
 
attribute value.</P
1071
 
></LI
1072
 
></UL
1073
 
>
1074
 
 
1075
 
The most interesting default declarations are:
1076
 
 
1077
 
<P
1078
 
></P
1079
 
><UL
1080
 
COMPACT="COMPACT"
1081
 
><LI
1082
 
STYLE="list-style-type: disc"
1083
 
><P
1084
 
><TT
1085
 
CLASS="LITERAL"
1086
 
>#REQUIRED</TT
1087
 
>: The attribute must be specified.</P
1088
 
></LI
1089
 
><LI
1090
 
STYLE="list-style-type: disc"
1091
 
><P
1092
 
><TT
1093
 
CLASS="LITERAL"
1094
 
>#IMPLIED</TT
1095
 
>: The attribute can be specified but also can be
1096
 
left out. The application can find out whether the attribute was present or
1097
 
not. </P
1098
 
></LI
1099
 
><LI
1100
 
STYLE="list-style-type: disc"
1101
 
><P
1102
 
><TT
1103
 
CLASS="LITERAL"
1104
 
>"<TT
1105
 
CLASS="REPLACEABLE"
1106
 
><I
1107
 
>value</I
1108
 
></TT
1109
 
>"</TT
1110
 
> or
1111
 
<TT
1112
 
CLASS="LITERAL"
1113
 
>'<TT
1114
 
CLASS="REPLACEABLE"
1115
 
><I
1116
 
>value</I
1117
 
></TT
1118
 
>'</TT
1119
 
>: This particular value is
1120
 
used as default if the attribute is omitted in the element.</P
1121
 
></LI
1122
 
></UL
1123
 
></P
1124
 
><BLOCKQUOTE
1125
 
CLASS="BLOCKQUOTE"
1126
 
><P
1127
 
><B
1128
 
>Example</B
1129
 
></P
1130
 
><P
1131
 
>This is a valid attribute declaration for element type <TT
1132
 
CLASS="LITERAL"
1133
 
>r</TT
1134
 
>:
1135
 
 
1136
 
<PRE
1137
 
CLASS="PROGRAMLISTING"
1138
 
>&#60;!ATTLIST r 
1139
 
          x CDATA    #REQUIRED
1140
 
          y NMTOKEN  #IMPLIED
1141
 
          z NMTOKENS "one two three"&#62;</PRE
1142
 
>
1143
 
 
1144
 
This means that <TT
1145
 
CLASS="LITERAL"
1146
 
>x</TT
1147
 
> is a required attribute that cannot be
1148
 
left out, while <TT
1149
 
CLASS="LITERAL"
1150
 
>y</TT
1151
 
> and <TT
1152
 
CLASS="LITERAL"
1153
 
>z</TT
1154
 
> are optional. The
1155
 
XML parser indicates the application whether <TT
1156
 
CLASS="LITERAL"
1157
 
>y</TT
1158
 
> is present or
1159
 
not, but if <TT
1160
 
CLASS="LITERAL"
1161
 
>z</TT
1162
 
> is missing the default value
1163
 
"one two three" is returned automatically. </P
1164
 
><P
1165
 
>This is a valid example of these attributes:
1166
 
 
1167
 
<PRE
1168
 
CLASS="PROGRAMLISTING"
1169
 
>&#60;r x="He said: &#38;quot;I don't like quotes!&#38;quot;" y='1'&#62;</PRE
1170
 
></P
1171
 
></BLOCKQUOTE
1172
 
></DIV
1173
 
><DIV
1174
 
CLASS="SECT2"
1175
 
><H2
1176
 
CLASS="SECT2"
1177
 
><A
1178
 
NAME="AEN368"
1179
 
>1.2.5. Parsed entities</A
1180
 
></H2
1181
 
><P
1182
 
>Elements describe the logical structure of the document, while
1183
 
<I
1184
 
CLASS="EMPHASIS"
1185
 
>entities</I
1186
 
> determine the physical structure. Entities are
1187
 
the pieces of text the parser operates on, mostly files and macros. Entities
1188
 
may be <I
1189
 
CLASS="EMPHASIS"
1190
 
>parsed</I
1191
 
> in which case the parser reads the text and
1192
 
interprets it as XML markup, or <I
1193
 
CLASS="EMPHASIS"
1194
 
>unparsed</I
1195
 
> which simply
1196
 
means that the data of the entity has a foreign format (e.g. a GIF icon).</P
1197
 
><P
1198
 
>If the parsed entity is going to be used as part of the DTD, it
1199
 
is called a <I
1200
 
CLASS="EMPHASIS"
1201
 
>parameter entity</I
1202
 
>. You can declare a parameter
1203
 
entity with a fixed text as content by:
1204
 
 
1205
 
<PRE
1206
 
CLASS="PROGRAMLISTING"
1207
 
>&lt;!ENTITY % <TT
1208
 
CLASS="REPLACEABLE"
1209
 
><I
1210
 
>name</I
1211
 
></TT
1212
 
> "<TT
1213
 
CLASS="REPLACEABLE"
1214
 
><I
1215
 
>value</I
1216
 
></TT
1217
 
>"&gt;</PRE
1218
 
>
1219
 
 
1220
 
Within the DTD, you can <I
1221
 
CLASS="EMPHASIS"
1222
 
>refer to</I
1223
 
> this entity, i.e. read
1224
 
the text of the entity, by:
1225
 
 
1226
 
<PRE
1227
 
CLASS="PROGRAMLISTING"
1228
 
>%<TT
1229
 
CLASS="REPLACEABLE"
1230
 
><I
1231
 
>name</I
1232
 
></TT
1233
 
>;</PRE
1234
 
>
1235
 
 
1236
 
Such entities behave like macros, i.e. when they are referred to, the
1237
 
macro text is inserted and read instead of the original text.
1238
 
 
1239
 
<BLOCKQUOTE
1240
 
CLASS="BLOCKQUOTE"
1241
 
><P
1242
 
><B
1243
 
>Example</B
1244
 
></P
1245
 
><P
1246
 
>For example, you can declare two elements with the same content model by:
1247
 
 
1248
 
<PRE
1249
 
CLASS="PROGRAMLISTING"
1250
 
>&#60;!ENTITY % model "a | b | c"&#62;
1251
 
&#60;!ELEMENT x (%model;)&#62;
1252
 
&#60;!ELEMENT y (%model;)&#62;</PRE
1253
 
>&#13;</P
1254
 
></BLOCKQUOTE
1255
 
>
1256
 
 
1257
 
If the contents of the entity are given as string constant, the entity is
1258
 
called an <I
1259
 
CLASS="EMPHASIS"
1260
 
>internal</I
1261
 
> entity. It is also possible to name a
1262
 
file to be used as content (an <I
1263
 
CLASS="EMPHASIS"
1264
 
>external</I
1265
 
> entity):
1266
 
 
1267
 
<PRE
1268
 
CLASS="PROGRAMLISTING"
1269
 
>&lt;!ENTITY % <TT
1270
 
CLASS="REPLACEABLE"
1271
 
><I
1272
 
>name</I
1273
 
></TT
1274
 
> SYSTEM "<TT
1275
 
CLASS="REPLACEABLE"
1276
 
><I
1277
 
>file name</I
1278
 
></TT
1279
 
>"&gt;</PRE
1280
 
>
1281
 
 
1282
 
There are some restrictions for parameter entities:
1283
 
 
1284
 
<P
1285
 
></P
1286
 
><UL
1287
 
COMPACT="COMPACT"
1288
 
><LI
1289
 
STYLE="list-style-type: disc"
1290
 
><P
1291
 
>If the internal parameter entity contains the first token of a declaration
1292
 
(i.e. <TT
1293
 
CLASS="LITERAL"
1294
 
>&lt;!</TT
1295
 
>), it must also contain the last token of the
1296
 
declaration, i.e. the <TT
1297
 
CLASS="LITERAL"
1298
 
>&gt;</TT
1299
 
>. This means that the entity
1300
 
either contains a whole number of complete declarations, or some text from the
1301
 
middle of one declaration.</P
1302
 
><P
1303
 
><I
1304
 
CLASS="EMPHASIS"
1305
 
>Illegal:</I
1306
 
>
1307
 
<PRE
1308
 
CLASS="PROGRAMLISTING"
1309
 
>&#60;!ENTITY % e "(a | b | c)&#62;"&#62;
1310
 
&#60;!ELEMENT x %e;</PRE
1311
 
> Because <TT
1312
 
CLASS="LITERAL"
1313
 
>&lt;!</TT
1314
 
> is contained in the main
1315
 
entity, and the corresponding <TT
1316
 
CLASS="LITERAL"
1317
 
>&gt;</TT
1318
 
> is contained in the
1319
 
entity <TT
1320
 
CLASS="LITERAL"
1321
 
>e</TT
1322
 
>.</P
1323
 
></LI
1324
 
><LI
1325
 
STYLE="list-style-type: disc"
1326
 
><P
1327
 
>If the internal parameter entity contains a left paranthesis, it must also
1328
 
contain the corresponding right paranthesis.</P
1329
 
><P
1330
 
><I
1331
 
CLASS="EMPHASIS"
1332
 
>Illegal:</I
1333
 
>
1334
 
<PRE
1335
 
CLASS="PROGRAMLISTING"
1336
 
>&#60;!ENTITY % e "(a | b | c"&#62;
1337
 
&#60;!ELEMENT x %e;)&#62;</PRE
1338
 
> Because <TT
1339
 
CLASS="LITERAL"
1340
 
>(</TT
1341
 
> is contained in the entity 
1342
 
<TT
1343
 
CLASS="LITERAL"
1344
 
>e</TT
1345
 
>, and the corresponding <TT
1346
 
CLASS="LITERAL"
1347
 
>)</TT
1348
 
> is
1349
 
contained in the main entity.</P
1350
 
></LI
1351
 
><LI
1352
 
STYLE="list-style-type: disc"
1353
 
><P
1354
 
>When reading text from an entity, the parser automatically inserts one space
1355
 
character before the entity text and one space character after the entity
1356
 
text. However, this rule is not applied within the definition of another
1357
 
entity.</P
1358
 
><P
1359
 
><I
1360
 
CLASS="EMPHASIS"
1361
 
>Legal:</I
1362
 
>
1363
 
<PRE
1364
 
CLASS="PROGRAMLISTING"
1365
 
1366
 
&#60;!ENTITY % suffix "gif"&#62; 
1367
 
&#60;!ENTITY iconfile 'icon.%suffix;'&#62;</PRE
1368
 
> Because <TT
1369
 
CLASS="LITERAL"
1370
 
>%suffix;</TT
1371
 
> is referenced within
1372
 
the definition text for <TT
1373
 
CLASS="LITERAL"
1374
 
>iconfile</TT
1375
 
>, no additional spaces are
1376
 
added.</P
1377
 
><P
1378
 
><I
1379
 
CLASS="EMPHASIS"
1380
 
>Illegal:</I
1381
 
>
1382
 
<PRE
1383
 
CLASS="PROGRAMLISTING"
1384
 
>&#60;!ENTITY % suffix "test"&#62;
1385
 
&#60;!ELEMENT x.%suffix; ANY&#62;</PRE
1386
 
>
1387
 
Because <TT
1388
 
CLASS="LITERAL"
1389
 
>%suffix;</TT
1390
 
> is referenced outside the definition
1391
 
text of another entity, the parser replaces <TT
1392
 
CLASS="LITERAL"
1393
 
>%suffix;</TT
1394
 
> by
1395
 
<TT
1396
 
CLASS="LITERAL"
1397
 
><TT
1398
 
CLASS="REPLACEABLE"
1399
 
><I
1400
 
>space</I
1401
 
></TT
1402
 
>test<TT
1403
 
CLASS="REPLACEABLE"
1404
 
><I
1405
 
>space</I
1406
 
></TT
1407
 
></TT
1408
 
>. </P
1409
 
><P
1410
 
><I
1411
 
CLASS="EMPHASIS"
1412
 
>Illegal:</I
1413
 
>
1414
 
<PRE
1415
 
CLASS="PROGRAMLISTING"
1416
 
>&#60;!ENTITY % e "(a | b | c)"&#62;
1417
 
&#60;!ELEMENT x %e;*&#62;</PRE
1418
 
> Because there is a whitespace between <TT
1419
 
CLASS="LITERAL"
1420
 
>)</TT
1421
 
>
1422
 
and <TT
1423
 
CLASS="LITERAL"
1424
 
>*</TT
1425
 
>, which is illegal.</P
1426
 
></LI
1427
 
><LI
1428
 
STYLE="list-style-type: disc"
1429
 
><P
1430
 
>An external parameter entity must always consist of a whole number of complete
1431
 
declarations.</P
1432
 
></LI
1433
 
><LI
1434
 
STYLE="list-style-type: disc"
1435
 
><P
1436
 
>In the internal subset of the DTD, a reference to a parameter entity (internal
1437
 
or external) is only allowed at positions where a new declaration can start.</P
1438
 
></LI
1439
 
></UL
1440
 
></P
1441
 
><P
1442
 
>If the parsed entity is going to be used in the document instance, it is called
1443
 
a <I
1444
 
CLASS="EMPHASIS"
1445
 
>general entity</I
1446
 
>. Such entities can be used as
1447
 
abbreviations for frequent phrases, or to include external files. Internal
1448
 
general entities are declared as follows:
1449
 
 
1450
 
<PRE
1451
 
CLASS="PROGRAMLISTING"
1452
 
>&lt;!ENTITY <TT
1453
 
CLASS="REPLACEABLE"
1454
 
><I
1455
 
>name</I
1456
 
></TT
1457
 
> "<TT
1458
 
CLASS="REPLACEABLE"
1459
 
><I
1460
 
>value</I
1461
 
></TT
1462
 
>"&gt;</PRE
1463
 
>
1464
 
 
1465
 
External general entities are declared this way:
1466
 
 
1467
 
<PRE
1468
 
CLASS="PROGRAMLISTING"
1469
 
>&lt;!ENTITY <TT
1470
 
CLASS="REPLACEABLE"
1471
 
><I
1472
 
>name</I
1473
 
></TT
1474
 
> SYSTEM "<TT
1475
 
CLASS="REPLACEABLE"
1476
 
><I
1477
 
>file name</I
1478
 
></TT
1479
 
>"&gt;</PRE
1480
 
>
1481
 
 
1482
 
References to general entities are written as:
1483
 
 
1484
 
<PRE
1485
 
CLASS="PROGRAMLISTING"
1486
 
>&#38;<TT
1487
 
CLASS="REPLACEABLE"
1488
 
><I
1489
 
>name</I
1490
 
></TT
1491
 
>;</PRE
1492
 
>
1493
 
 
1494
 
The main difference between parameter and general entities is that the former
1495
 
are only recognized in the DTD and that the latter are only recognized in the
1496
 
document instance. As the DTD is parsed before the document, the parameter
1497
 
entities are expanded first; for example it is possible to use the content of a
1498
 
parameter entity as the name of a general entity:
1499
 
<TT
1500
 
CLASS="LITERAL"
1501
 
>&amp;#38;%name;;</TT
1502
 
><A
1503
 
NAME="AEN445"
1504
 
HREF="#FTN.AEN445"
1505
 
>[1]</A
1506
 
>.</P
1507
 
><P
1508
 
>General entities must respect the element hierarchy. This means that there must
1509
 
be an end tag for every start tag in the entity value, and that end tags
1510
 
without corresponding start tags are not allowed.</P
1511
 
><BLOCKQUOTE
1512
 
CLASS="BLOCKQUOTE"
1513
 
><P
1514
 
><B
1515
 
>Example</B
1516
 
></P
1517
 
><P
1518
 
>If the author of a document changes sometimes, it is worthwhile to set up a
1519
 
general entity containing the names of the authors. If the author changes, you
1520
 
need only to change the definition of the entity, and do not need to check all
1521
 
occurrences of authors' names:
1522
 
 
1523
 
<PRE
1524
 
CLASS="PROGRAMLISTING"
1525
 
>&#60;!ENTITY authors "Gerd Stolpmann"&#62;</PRE
1526
 
>
1527
 
 
1528
 
In the document text, you can now refer to the author names by writing
1529
 
<TT
1530
 
CLASS="LITERAL"
1531
 
>&amp;authors;</TT
1532
 
>.</P
1533
 
><P
1534
 
><I
1535
 
CLASS="EMPHASIS"
1536
 
>Illegal:</I
1537
 
>
1538
 
The following two entities are illegal because the elements in the definition
1539
 
do not nest properly:
1540
 
 
1541
 
<PRE
1542
 
CLASS="PROGRAMLISTING"
1543
 
>&#60;!ENTITY lengthy-tag "&#60;section textcolor='white' background='graphic'&#62;"&#62;
1544
 
&#60;!ENTITY nonsense    "&#60;a&#62;&#60;/b&#62;"&#62;</PRE
1545
 
></P
1546
 
></BLOCKQUOTE
1547
 
><P
1548
 
>Earlier in this introduction we explained that there are substitutes for
1549
 
reserved characters: &amp;lt;, &amp;gt;, &amp;amp;, &amp;apos;, and
1550
 
&amp;quot;. These are simply predefined general entities; note that they are
1551
 
the only predefined entities. It is allowed to define these entities again
1552
 
as long as the meaning is unchanged.</P
1553
 
></DIV
1554
 
><DIV
1555
 
CLASS="SECT2"
1556
 
><H2
1557
 
CLASS="SECT2"
1558
 
><A
1559
 
NAME="AEN463"
1560
 
>1.2.6. Notations and unparsed entities</A
1561
 
></H2
1562
 
><P
1563
 
>Unparsed entities have a foreign format and can thus not be read by the XML
1564
 
parser. Unparsed entities are always external. The format of an unparsed entity
1565
 
must have been declared, such a format is called a
1566
 
<I
1567
 
CLASS="EMPHASIS"
1568
 
>notation</I
1569
 
>. The entity can then be declared by referring to
1570
 
this notation. As unparsed entities do not contain XML text, it is not possible
1571
 
to include them directly into the document; you can only declare attributes
1572
 
such that names of unparsed entities are acceptable values.</P
1573
 
><P
1574
 
>As you can see, unparsed entities are too complicated in order to have any
1575
 
purpose. It is almost always better to simply pass the name of the data file as
1576
 
normal attribute value, and let the application recognize and process the
1577
 
foreign format. </P
1578
 
></DIV
1579
 
></DIV
1580
 
><H3
1581
 
CLASS="FOOTNOTES"
1582
 
>Notes</H3
1583
 
><TABLE
1584
 
BORDER="0"
1585
 
CLASS="FOOTNOTES"
1586
 
WIDTH="100%"
1587
 
><TR
1588
 
><TD
1589
 
ALIGN="LEFT"
1590
 
VALIGN="TOP"
1591
 
WIDTH="5%"
1592
 
><A
1593
 
NAME="FTN.AEN445"
1594
 
HREF="x107.html#AEN445"
1595
 
>[1]</A
1596
 
></TD
1597
 
><TD
1598
 
ALIGN="LEFT"
1599
 
VALIGN="TOP"
1600
 
WIDTH="95%"
1601
 
><P
1602
 
>This construct is only
1603
 
allowed within the definition of another entity; otherwise extra spaces would
1604
 
be added (as explained above). Such indirection is not recommended.</P
1605
 
><P
1606
 
>Complete example:
1607
 
<PRE
1608
 
CLASS="PROGRAMLISTING"
1609
 
>&#60;!ENTITY % variant "a"&#62;      &#60;!-- or "b" --&#62;
1610
 
&#60;!ENTITY text-a "This is text A."&#62;
1611
 
&#60;!ENTITY text-b "This is text B."&#62;
1612
 
&#60;!ENTITY text "&#38;#38;text-%variant;;"&#62;</PRE
1613
 
>
1614
 
You can now write <TT
1615
 
CLASS="LITERAL"
1616
 
>&amp;text;</TT
1617
 
> in the document instance, and
1618
 
depending on the value of <TT
1619
 
CLASS="LITERAL"
1620
 
>variant</TT
1621
 
> either
1622
 
<TT
1623
 
CLASS="LITERAL"
1624
 
>text-a</TT
1625
 
> or <TT
1626
 
CLASS="LITERAL"
1627
 
>text-b</TT
1628
 
> is inserted.</P
1629
 
></TD
1630
 
></TR
1631
 
></TABLE
1632
 
><DIV
1633
 
CLASS="NAVFOOTER"
1634
 
><HR
1635
 
ALIGN="LEFT"
1636
 
WIDTH="100%"><TABLE
1637
 
WIDTH="100%"
1638
 
BORDER="0"
1639
 
CELLPADDING="0"
1640
 
CELLSPACING="0"
1641
 
><TR
1642
 
><TD
1643
 
WIDTH="33%"
1644
 
ALIGN="left"
1645
 
VALIGN="top"
1646
 
><A
1647
 
HREF="c36.html"
1648
 
>Prev</A
1649
 
></TD
1650
 
><TD
1651
 
WIDTH="34%"
1652
 
ALIGN="center"
1653
 
VALIGN="top"
1654
 
><A
1655
 
HREF="index.html"
1656
 
>Home</A
1657
 
></TD
1658
 
><TD
1659
 
WIDTH="33%"
1660
 
ALIGN="right"
1661
 
VALIGN="top"
1662
 
><A
1663
 
HREF="x468.html"
1664
 
>Next</A
1665
 
></TD
1666
 
></TR
1667
 
><TR
1668
 
><TD
1669
 
WIDTH="33%"
1670
 
ALIGN="left"
1671
 
VALIGN="top"
1672
 
>What is XML?</TD
1673
 
><TD
1674
 
WIDTH="34%"
1675
 
ALIGN="center"
1676
 
VALIGN="top"
1677
 
><A
1678
 
HREF="c36.html"
1679
 
>Up</A
1680
 
></TD
1681
 
><TD
1682
 
WIDTH="33%"
1683
 
ALIGN="right"
1684
 
VALIGN="top"
1685
 
>A complete example: The <I
1686
 
CLASS="EMPHASIS"
1687
 
>readme</I
1688
 
> DTD</TD
1689
 
></TR
1690
 
></TABLE
1691
 
></DIV
1692
 
></BODY
1693
 
></HTML
1694
 
>
 
 
b'\\ No newline at end of file'