lutaml-model 0.8.192 → 0.8.193
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/dependent-tests.yml +12 -0
- data/README.adoc +9 -0
- data/docs/_guides/xml-guide-0.8.0.adoc +1547 -0
- data/docs/_guides/xml_mappings/05_common_patterns.adoc +365 -1
- data/docs/missing_xml_features.adoc +35 -0
- data/docs/xml_1.0.adoc +1989 -0
- data/docs/xml_base.adoc +718 -0
- data/docs/xml_data_types.adoc +263 -0
- data/docs/xml_namespace.adoc +129 -0
- data/docs/xml_schema.adoc +500 -0
- data/docs/xml_xlink.adoc +539 -0
- data/lib/lutaml/model/attribute.rb +55 -0
- data/lib/lutaml/model/version.rb +1 -1
- data/spec/lutaml/model/namespace_autoload_spec.rb +86 -0
- metadata +10 -1
data/docs/xml_1.0.adoc
ADDED
|
@@ -0,0 +1,1989 @@
|
|
|
1
|
+
= XML 1.0 — Complete Specification (Fifth Edition)
|
|
2
|
+
|
|
3
|
+
This document outlines the complete specification of XML 1.0 (Fifth Edition) based on the W3C Recommendation dated November 26, 2008. It provides comprehensive coverage of XML document structure, elements, attributes, entities, notations, character encoding, and all relevant components for implementing XML 1.0 compliant processors.
|
|
4
|
+
|
|
5
|
+
== Overview
|
|
6
|
+
|
|
7
|
+
XML (Extensible Markup Language) is a subset of SGML that is designed for ease of implementation and interoperability with both SGML and HTML. XML describes a class of data objects called XML documents and partially describes the behavior of computer programs which process them.
|
|
8
|
+
|
|
9
|
+
=== Design Goals
|
|
10
|
+
|
|
11
|
+
XML was designed with the following goals:
|
|
12
|
+
|
|
13
|
+
1. XML shall be straightforwardly usable over the Internet
|
|
14
|
+
2. XML shall support a wide variety of applications
|
|
15
|
+
3. XML shall be compatible with SGML
|
|
16
|
+
4. It shall be easy to write programs which process XML documents
|
|
17
|
+
5. The number of optional features in XML is to be kept to the absolute minimum, ideally zero
|
|
18
|
+
6. XML documents should be human-legible and reasonably clear
|
|
19
|
+
7. The XML design should be prepared quickly
|
|
20
|
+
8. The design of XML shall be formal and concise
|
|
21
|
+
9. XML documents shall be easy to create
|
|
22
|
+
10. Terseness in XML markup is of minimal importance
|
|
23
|
+
|
|
24
|
+
== 1. Document Structure and Well-Formedness
|
|
25
|
+
|
|
26
|
+
An XML document consists of:
|
|
27
|
+
|
|
28
|
+
- **Prolog**: Optional; includes XML declaration, document type declaration, comments, and processing instructions
|
|
29
|
+
- **Document Element**: A single root element that contains all other elements
|
|
30
|
+
- **Miscellaneous**: Comments, processing instructions, and whitespace that may appear after the document element
|
|
31
|
+
|
|
32
|
+
=== Well-Formed XML Documents
|
|
33
|
+
|
|
34
|
+
A textual object is a well-formed XML document if:
|
|
35
|
+
|
|
36
|
+
1. Taken as a whole, it matches the document production
|
|
37
|
+
2. It meets all the well-formedness constraints given in this specification
|
|
38
|
+
3. Each of the parsed entities which is referenced directly or indirectly within the document is well-formed
|
|
39
|
+
|
|
40
|
+
==== Document Production
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
document ::= prolog element Misc*
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Where:
|
|
47
|
+
- There is exactly one element, called the root or document element
|
|
48
|
+
- Elements must be properly nested within each other
|
|
49
|
+
- For each non-root element C, there is one other element P such that C is in the content of P
|
|
50
|
+
|
|
51
|
+
=== Basic Document Examples
|
|
52
|
+
|
|
53
|
+
.Minimal Well-Formed Document
|
|
54
|
+
```xml
|
|
55
|
+
<greeting>Hello, world!</greeting>
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
.Complete Document with XML Declaration
|
|
59
|
+
```xml
|
|
60
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
61
|
+
<greeting>Hello, world!</greeting>
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
.Document with DOCTYPE Declaration
|
|
65
|
+
```xml
|
|
66
|
+
<?xml version="1.0"?>
|
|
67
|
+
<!DOCTYPE greeting SYSTEM "hello.dtd">
|
|
68
|
+
<greeting>Hello, world!</greeting>
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
== 2. Characters and Character Encoding
|
|
72
|
+
|
|
73
|
+
=== Character Range
|
|
74
|
+
|
|
75
|
+
XML documents are composed of characters from the Unicode/ISO 10646 character set. Legal characters include:
|
|
76
|
+
|
|
77
|
+
- Tab (#x9)
|
|
78
|
+
- Line feed (#xA)
|
|
79
|
+
- Carriage return (#xD)
|
|
80
|
+
- Characters in range #x20-#xD7FF
|
|
81
|
+
- Characters in range #xE000-#xFFFD
|
|
82
|
+
- Characters in range #x10000-#x10FFFF
|
|
83
|
+
|
|
84
|
+
```
|
|
85
|
+
Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
=== Character Encoding
|
|
89
|
+
|
|
90
|
+
All XML processors must accept UTF-8 and UTF-16 encodings. Other encodings may be supported but must be declared using an encoding declaration.
|
|
91
|
+
|
|
92
|
+
==== UTF-8 Example
|
|
93
|
+
```xml
|
|
94
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
95
|
+
<document>Content in UTF-8</document>
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
==== UTF-16 Example
|
|
99
|
+
```xml
|
|
100
|
+
<?xml version="1.0" encoding="UTF-16"?>
|
|
101
|
+
<document>Content in UTF-16</document>
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
==== Other Encoding Example
|
|
105
|
+
```xml
|
|
106
|
+
<?xml version="1.0" encoding="ISO-8859-1"?>
|
|
107
|
+
<document>Content in Latin-1</document>
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
=== Character References
|
|
111
|
+
|
|
112
|
+
Character references allow inclusion of specific Unicode characters:
|
|
113
|
+
|
|
114
|
+
- Decimal: `&#decimal;`
|
|
115
|
+
- Hexadecimal: `&#xhex;`
|
|
116
|
+
|
|
117
|
+
.Character Reference Examples
|
|
118
|
+
```xml
|
|
119
|
+
<text>Copyright © 2023</text>
|
|
120
|
+
<text>Copyright © 2023</text>
|
|
121
|
+
<text>Less than: < Greater than: ></text>
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
== 3. Prolog Components
|
|
125
|
+
|
|
126
|
+
The prolog contains optional components that appear before the document element.
|
|
127
|
+
|
|
128
|
+
=== XML Declaration
|
|
129
|
+
|
|
130
|
+
The XML declaration specifies the XML version and optionally the encoding and standalone status.
|
|
131
|
+
|
|
132
|
+
```
|
|
133
|
+
XMLDecl ::= '<?xml' VersionInfo EncodingDecl? SDDecl? S? '?>'
|
|
134
|
+
VersionInfo ::= S 'version' Eq ("'" VersionNum "'" | '"' VersionNum '"')
|
|
135
|
+
VersionNum ::= '1.' [0-9]+
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
.XML Declaration Examples
|
|
139
|
+
```xml
|
|
140
|
+
<?xml version="1.0"?>
|
|
141
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
142
|
+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
143
|
+
<?xml version="1.0" standalone="no"?>
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
=== Encoding Declaration
|
|
147
|
+
|
|
148
|
+
The encoding declaration specifies the character encoding used in the document.
|
|
149
|
+
|
|
150
|
+
```
|
|
151
|
+
EncodingDecl ::= S 'encoding' Eq ('"' EncName '"' | "'" EncName "'" )
|
|
152
|
+
EncName ::= [A-Za-z] ([A-Za-z0-9._] | '-')*
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
.Encoding Declaration Examples
|
|
156
|
+
```xml
|
|
157
|
+
<?xml encoding='UTF-8'?>
|
|
158
|
+
<?xml encoding='ISO-8859-1'?>
|
|
159
|
+
<?xml encoding='EUC-JP'?>
|
|
160
|
+
<?xml encoding='Shift_JIS'?>
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
=== Standalone Document Declaration
|
|
164
|
+
|
|
165
|
+
The standalone declaration indicates whether the document relies on external markup declarations.
|
|
166
|
+
|
|
167
|
+
```
|
|
168
|
+
SDDecl ::= S 'standalone' Eq (("'" ('yes' | 'no') "'") | ('"' ('yes' | 'no') '"'))
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
.Standalone Declaration Examples
|
|
172
|
+
```xml
|
|
173
|
+
<?xml version="1.0" standalone="yes"?>
|
|
174
|
+
<?xml version="1.0" standalone="no"?>
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
=== Document Type Declaration
|
|
178
|
+
|
|
179
|
+
The document type declaration contains or points to markup declarations (DTD).
|
|
180
|
+
|
|
181
|
+
```
|
|
182
|
+
doctypedecl ::= '<!DOCTYPE' S Name (S ExternalID)? S? ('[' intSubset ']' S?)? '>'
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
.DOCTYPE Examples
|
|
186
|
+
```xml
|
|
187
|
+
<!DOCTYPE greeting SYSTEM "hello.dtd">
|
|
188
|
+
<!DOCTYPE greeting PUBLIC "-//W3C//DTD XHTML 1.0//EN"
|
|
189
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
|
190
|
+
<!DOCTYPE greeting [
|
|
191
|
+
<!ELEMENT greeting (#PCDATA)>
|
|
192
|
+
]>
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
== 4. Elements and Tags
|
|
196
|
+
|
|
197
|
+
Elements are the fundamental building blocks of XML documents. Each element has a type identified by name and may have a set of attribute specifications.
|
|
198
|
+
|
|
199
|
+
=== Element Structure
|
|
200
|
+
|
|
201
|
+
```
|
|
202
|
+
element ::= EmptyElemTag | STag content ETag
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
=== Start Tags
|
|
206
|
+
|
|
207
|
+
Start tags mark the beginning of non-empty elements.
|
|
208
|
+
|
|
209
|
+
```
|
|
210
|
+
STag ::= '<' Name (S Attribute)* S? '>'
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
.Start Tag Examples
|
|
214
|
+
```xml
|
|
215
|
+
<book>
|
|
216
|
+
<person id="123">
|
|
217
|
+
<section title="Introduction" level="1">
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
=== End Tags
|
|
221
|
+
|
|
222
|
+
End tags mark the end of elements that began with start tags.
|
|
223
|
+
|
|
224
|
+
```
|
|
225
|
+
ETag ::= '</' Name S? '>'
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
.End Tag Examples
|
|
229
|
+
```xml
|
|
230
|
+
</book>
|
|
231
|
+
</person>
|
|
232
|
+
</section>
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
=== Empty Element Tags
|
|
236
|
+
|
|
237
|
+
Empty element tags represent elements with no content.
|
|
238
|
+
|
|
239
|
+
```
|
|
240
|
+
EmptyElemTag ::= '<' Name (S Attribute)* S? '/>'
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
.Empty Element Examples
|
|
244
|
+
```xml
|
|
245
|
+
<br/>
|
|
246
|
+
<img src="logo.png" alt="Company Logo"/>
|
|
247
|
+
<meta charset="UTF-8"/>
|
|
248
|
+
<input type="text" name="username"/>
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
=== Element Content
|
|
252
|
+
|
|
253
|
+
Element content is the text between start and end tags.
|
|
254
|
+
|
|
255
|
+
```
|
|
256
|
+
content ::= CharData? ((element | Reference | CDSect | PI | Comment) CharData?)*
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
.Element Content Examples
|
|
260
|
+
```xml
|
|
261
|
+
<title>XML 1.0 Specification</title>
|
|
262
|
+
<paragraph>This is <emphasis>important</emphasis> text.</paragraph>
|
|
263
|
+
<mixed>Text with <em>embedded</em> elements and &entity; references.</mixed>
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
=== Well-Formedness Constraints
|
|
267
|
+
|
|
268
|
+
- Element Type Match: The name in an element's end tag must match the element type in the start tag
|
|
269
|
+
- Proper Nesting: Elements must be properly nested within each other
|
|
270
|
+
- Unique Attribute Specification: An attribute name must not appear more than once in the same start tag
|
|
271
|
+
|
|
272
|
+
.Well-Formed Nesting Example
|
|
273
|
+
```xml
|
|
274
|
+
<document>
|
|
275
|
+
<section>
|
|
276
|
+
<title>Chapter 1</title>
|
|
277
|
+
<paragraph>Content here.</paragraph>
|
|
278
|
+
</section>
|
|
279
|
+
</document>
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
.Ill-Formed Nesting Example (Wrong)
|
|
283
|
+
```xml
|
|
284
|
+
<document>
|
|
285
|
+
<section>
|
|
286
|
+
<title>Chapter 1
|
|
287
|
+
<paragraph>Content here.</title>
|
|
288
|
+
</section>
|
|
289
|
+
</paragraph>
|
|
290
|
+
</document>
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
== 5. Attributes
|
|
294
|
+
|
|
295
|
+
Attributes are name-value pairs associated with elements, appearing in start tags and empty element tags.
|
|
296
|
+
|
|
297
|
+
=== Attribute Syntax
|
|
298
|
+
|
|
299
|
+
```
|
|
300
|
+
Attribute ::= Name Eq AttValue
|
|
301
|
+
Eq ::= S? '=' S?
|
|
302
|
+
AttValue ::= '"' ([^<&"] | Reference)* '"' | "'" ([^<&'] | Reference)* "'"
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
.Attribute Examples
|
|
306
|
+
```xml
|
|
307
|
+
<book title="XML Guide" author="John Doe" year="2023">
|
|
308
|
+
<img src="photo.jpg" width="300" height="200" alt="A beautiful sunset"/>
|
|
309
|
+
<input type="email" name="email" required="true"/>
|
|
310
|
+
<div class="container" id="main-content" style="margin: 10px;">
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
=== Attribute Types
|
|
314
|
+
|
|
315
|
+
==== String Type (CDATA)
|
|
316
|
+
The most basic attribute type that can contain any character data.
|
|
317
|
+
|
|
318
|
+
```xml
|
|
319
|
+
<person name="Jane Smith" address="123 Main St, Anytown, USA"/>
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
==== Tokenized Types
|
|
323
|
+
|
|
324
|
+
===== ID Type
|
|
325
|
+
Uniquely identifies an element within the document.
|
|
326
|
+
|
|
327
|
+
```xml
|
|
328
|
+
<section id="introduction">
|
|
329
|
+
<chapter id="chapter1">
|
|
330
|
+
<figure id="fig-1">
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
===== IDREF and IDREFS Types
|
|
334
|
+
Reference other elements by their ID values.
|
|
335
|
+
|
|
336
|
+
```xml
|
|
337
|
+
<footnote ref="note1"/>
|
|
338
|
+
<index refs="chap1 chap2 chap3"/>
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
===== ENTITY and ENTITIES Types
|
|
342
|
+
Reference unparsed entities.
|
|
343
|
+
|
|
344
|
+
```xml
|
|
345
|
+
<image entity="logo"/>
|
|
346
|
+
<sounds entities="beep click whistle"/>
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
===== NMTOKEN and NMTOKENS Types
|
|
350
|
+
Name tokens following XML naming rules.
|
|
351
|
+
|
|
352
|
+
```xml
|
|
353
|
+
<status value="active"/>
|
|
354
|
+
<keywords tokens="xml parsing validation"/>
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
==== Enumerated Types
|
|
358
|
+
|
|
359
|
+
===== Enumeration
|
|
360
|
+
Restricts values to a specific list.
|
|
361
|
+
|
|
362
|
+
```xml
|
|
363
|
+
<!ATTLIST status value (active|inactive|pending) "active">
|
|
364
|
+
<status value="active"/>
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
===== Notation Type
|
|
368
|
+
References a declared notation.
|
|
369
|
+
|
|
370
|
+
```xml
|
|
371
|
+
<!NOTATION gif SYSTEM "image/gif">
|
|
372
|
+
<!ATTLIST image format NOTATION (gif|jpeg|png) #IMPLIED>
|
|
373
|
+
<image format="gif"/>
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
=== Attribute Defaults
|
|
377
|
+
|
|
378
|
+
==== Required Attributes
|
|
379
|
+
```xml
|
|
380
|
+
<!ATTLIST person name CDATA #REQUIRED>
|
|
381
|
+
<person name="John"/>
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
==== Implied Attributes
|
|
385
|
+
```xml
|
|
386
|
+
<!ATTLIST book isbn CDATA #IMPLIED>
|
|
387
|
+
<book title="XML Guide"/>
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
==== Fixed Attributes
|
|
391
|
+
```xml
|
|
392
|
+
<!ATTLIST form method CDATA #FIXED "POST">
|
|
393
|
+
<form method="POST"/>
|
|
394
|
+
```
|
|
395
|
+
|
|
396
|
+
==== Default Values
|
|
397
|
+
```xml
|
|
398
|
+
<!ATTLIST list type (bullets|ordered|glossary) "ordered">
|
|
399
|
+
<list type="bullets"/>
|
|
400
|
+
<list/> <!-- defaults to "ordered" -->
|
|
401
|
+
```
|
|
402
|
+
|
|
403
|
+
=== Attribute Value Normalization
|
|
404
|
+
|
|
405
|
+
Before processing, attribute values are normalized:
|
|
406
|
+
|
|
407
|
+
1. Line breaks normalized to #xA
|
|
408
|
+
2. Character and entity references resolved
|
|
409
|
+
3. White space characters (#x20, #xD, #xA, #x9) converted to space (#x20)
|
|
410
|
+
4. For non-CDATA attributes: leading/trailing spaces removed, sequences of spaces collapsed to single space
|
|
411
|
+
|
|
412
|
+
.Normalization Example
|
|
413
|
+
```xml
|
|
414
|
+
<!-- Before normalization -->
|
|
415
|
+
<element attr=" value	with
whitespace "/>
|
|
416
|
+
|
|
417
|
+
<!-- After normalization (CDATA) -->
|
|
418
|
+
<element attr=" value with whitespace "/>
|
|
419
|
+
|
|
420
|
+
<!-- After normalization (NMTOKEN) -->
|
|
421
|
+
<element attr="value with whitespace"/>
|
|
422
|
+
```
|
|
423
|
+
|
|
424
|
+
== 6. Entities
|
|
425
|
+
|
|
426
|
+
Entities are storage units that can contain parsed or unparsed data. They provide a mechanism for text reuse and modularization.
|
|
427
|
+
|
|
428
|
+
=== Entity Types
|
|
429
|
+
|
|
430
|
+
==== General Entities
|
|
431
|
+
Used within document content to represent text or other data.
|
|
432
|
+
|
|
433
|
+
```
|
|
434
|
+
EntityRef ::= '&' Name ';'
|
|
435
|
+
```
|
|
436
|
+
|
|
437
|
+
==== Parameter Entities
|
|
438
|
+
Used within DTD to modularize markup declarations.
|
|
439
|
+
|
|
440
|
+
```
|
|
441
|
+
PEReference ::= '%' Name ';'
|
|
442
|
+
```
|
|
443
|
+
|
|
444
|
+
=== Entity Declarations
|
|
445
|
+
|
|
446
|
+
==== Internal Entity Declaration
|
|
447
|
+
```
|
|
448
|
+
GEDecl ::= '<!ENTITY' S Name S EntityValue S? '>'
|
|
449
|
+
EntityValue ::= '"' ([^%&"] | PEReference | Reference)* '"'
|
|
450
|
+
| "'" ([^%&'] | PEReference | Reference)* "'"
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
.Internal Entity Examples
|
|
454
|
+
```xml
|
|
455
|
+
<!ENTITY company "Acme Corporation">
|
|
456
|
+
<!ENTITY copyright "Copyright © 2023 &company;">
|
|
457
|
+
<!ENTITY email "support@acme.com">
|
|
458
|
+
|
|
459
|
+
<footer>©right; Contact: &email;</footer>
|
|
460
|
+
```
|
|
461
|
+
|
|
462
|
+
==== External Entity Declaration
|
|
463
|
+
```
|
|
464
|
+
ExternalID ::= 'SYSTEM' S SystemLiteral
|
|
465
|
+
| 'PUBLIC' S PubidLiteral S SystemLiteral
|
|
466
|
+
```
|
|
467
|
+
|
|
468
|
+
.External Entity Examples
|
|
469
|
+
```xml
|
|
470
|
+
<!ENTITY legal SYSTEM "legal.xml">
|
|
471
|
+
<!ENTITY boilerplate PUBLIC "-//ACME//TEXT Boilerplate//EN"
|
|
472
|
+
"http://www.acme.com/boilerplate.xml">
|
|
473
|
+
<!ENTITY logo SYSTEM "logo.gif" NDATA gif>
|
|
474
|
+
```
|
|
475
|
+
|
|
476
|
+
==== Parameter Entity Declaration
|
|
477
|
+
```
|
|
478
|
+
PEDecl ::= '<!ENTITY' S '%' S Name S PEDef S? '>'
|
|
479
|
+
PEDef ::= EntityValue | ExternalID
|
|
480
|
+
```
|
|
481
|
+
|
|
482
|
+
.Parameter Entity Examples
|
|
483
|
+
```xml
|
|
484
|
+
<!ENTITY % common-attrs "id ID #IMPLIED
|
|
485
|
+
class CDATA #IMPLIED">
|
|
486
|
+
<!ENTITY % text-elements "em | strong | code | br">
|
|
487
|
+
|
|
488
|
+
<!ATTLIST p %common-attrs;>
|
|
489
|
+
<!ELEMENT p (#PCDATA | %text-elements;)*>
|
|
490
|
+
```
|
|
491
|
+
|
|
492
|
+
=== Predefined Entities
|
|
493
|
+
|
|
494
|
+
XML defines five predefined general entities that must be recognized by all processors:
|
|
495
|
+
|
|
496
|
+
```xml
|
|
497
|
+
<!ENTITY lt "&#60;">
|
|
498
|
+
<!ENTITY gt ">">
|
|
499
|
+
<!ENTITY amp "&#38;">
|
|
500
|
+
<!ENTITY apos "'">
|
|
501
|
+
<!ENTITY quot """>
|
|
502
|
+
```
|
|
503
|
+
|
|
504
|
+
.Predefined Entity Usage
|
|
505
|
+
```xml
|
|
506
|
+
<code>if (x < y && y > z) return "true";</code>
|
|
507
|
+
<message>Don't forget to escape & characters!</message>
|
|
508
|
+
```
|
|
509
|
+
|
|
510
|
+
=== Entity Processing
|
|
511
|
+
|
|
512
|
+
==== Character References
|
|
513
|
+
Processed immediately when encountered.
|
|
514
|
+
|
|
515
|
+
```xml
|
|
516
|
+
<text>Degree symbol: ° or °</text>
|
|
517
|
+
```
|
|
518
|
+
|
|
519
|
+
==== Entity References
|
|
520
|
+
Processing depends on context:
|
|
521
|
+
|
|
522
|
+
- **In Content**: Included and processed
|
|
523
|
+
- **In Attribute Values**: Included but quotes treated as normal data
|
|
524
|
+
- **In Entity Values**: General entities bypassed, parameter entities processed
|
|
525
|
+
- **In DTD**: Parameter entities processed
|
|
526
|
+
|
|
527
|
+
.Entity Processing Examples
|
|
528
|
+
```xml
|
|
529
|
+
<!ENTITY example "This is "quoted" text">
|
|
530
|
+
<element attr="&example;"> <!-- Result: This is "quoted" text -->
|
|
531
|
+
&example; <!-- Result: This is "quoted" text -->
|
|
532
|
+
```
|
|
533
|
+
|
|
534
|
+
=== Unparsed Entities
|
|
535
|
+
|
|
536
|
+
Unparsed entities contain non-XML data and require a notation declaration.
|
|
537
|
+
|
|
538
|
+
```xml
|
|
539
|
+
<!NOTATION gif SYSTEM "image/gif">
|
|
540
|
+
<!ENTITY photo SYSTEM "photo.gif" NDATA gif>
|
|
541
|
+
<!ATTLIST img src ENTITY #REQUIRED>
|
|
542
|
+
|
|
543
|
+
<img src="photo"/>
|
|
544
|
+
```
|
|
545
|
+
|
|
546
|
+
=== Well-Formedness Constraints
|
|
547
|
+
|
|
548
|
+
- **Entity Declared**: Referenced entities must be declared
|
|
549
|
+
- **Parsed Entity**: Entity references must not contain unparsed entity names
|
|
550
|
+
- **No Recursion**: Entities must not contain recursive references
|
|
551
|
+
- **No External Entity References**: Attribute values cannot reference external entities
|
|
552
|
+
- **No < in Attribute Values**: Entity replacement text in attributes cannot contain '<'
|
|
553
|
+
|
|
554
|
+
.Valid Entity Usage
|
|
555
|
+
```xml
|
|
556
|
+
<!ENTITY greeting "Hello">
|
|
557
|
+
<!ENTITY target "World">
|
|
558
|
+
<!ENTITY message "&greeting;, ⌖!">
|
|
559
|
+
|
|
560
|
+
<text>&message;</text> <!-- Result: Hello, World! -->
|
|
561
|
+
```
|
|
562
|
+
|
|
563
|
+
== 7. Character Data and Markup
|
|
564
|
+
|
|
565
|
+
=== Character Data
|
|
566
|
+
|
|
567
|
+
Character data is all text that is not markup. It must not contain the literal characters '<' and '&' except when used as markup delimiters.
|
|
568
|
+
|
|
569
|
+
```
|
|
570
|
+
CharData ::= [^<&]* - ([^<&]* ']]>' [^<&]*)
|
|
571
|
+
```
|
|
572
|
+
|
|
573
|
+
.Character Data Examples
|
|
574
|
+
```xml
|
|
575
|
+
<text>This is simple character data.</text>
|
|
576
|
+
<paragraph>Character data can contain spaces, numbers 123, and punctuation!</paragraph>
|
|
577
|
+
```
|
|
578
|
+
|
|
579
|
+
=== Escaping Special Characters
|
|
580
|
+
|
|
581
|
+
Special characters must be escaped in character data:
|
|
582
|
+
|
|
583
|
+
- `<` must be escaped as `<`
|
|
584
|
+
- `&` must be escaped as `&`
|
|
585
|
+
- `>` should be escaped as `>` when part of `]]>`
|
|
586
|
+
|
|
587
|
+
.Escaped Character Examples
|
|
588
|
+
```xml
|
|
589
|
+
<code>if (x < y && y > z) { return true; }</code>
|
|
590
|
+
<text>The <xml> tag starts an element.</text>
|
|
591
|
+
<expression>3 < 5 && 5 > 1</expression>
|
|
592
|
+
```
|
|
593
|
+
|
|
594
|
+
=== Mixed Content
|
|
595
|
+
|
|
596
|
+
Elements can contain both character data and child elements (mixed content).
|
|
597
|
+
|
|
598
|
+
.Mixed Content Examples
|
|
599
|
+
```xml
|
|
600
|
+
<paragraph>This is <emphasis>important</emphasis> text with mixed content.</paragraph>
|
|
601
|
+
<recipe>
|
|
602
|
+
Bake at <temperature>350°F</temperature> for <time>25 minutes</time>.
|
|
603
|
+
</recipe>
|
|
604
|
+
<alert>Warning: <strong>Do not</strong> exceed the maximum <value>100</value> limit.</alert>
|
|
605
|
+
```
|
|
606
|
+
|
|
607
|
+
== 8. CDATA Sections
|
|
608
|
+
|
|
609
|
+
CDATA sections allow inclusion of text containing characters that would otherwise be recognized as markup. Only the CDATA end delimiter `]]>` is recognized as markup within CDATA sections.
|
|
610
|
+
|
|
611
|
+
```
|
|
612
|
+
CDSect ::= CDStart CData CDEnd
|
|
613
|
+
CDStart ::= '<![CDATA['
|
|
614
|
+
CData ::= (Char* - (Char* ']]>' Char*))
|
|
615
|
+
CDEnd ::= ']]>'
|
|
616
|
+
```
|
|
617
|
+
|
|
618
|
+
.CDATA Section Examples
|
|
619
|
+
```xml
|
|
620
|
+
<code><![CDATA[
|
|
621
|
+
if (x < y && y > z) {
|
|
622
|
+
return "success";
|
|
623
|
+
}
|
|
624
|
+
]]></code>
|
|
625
|
+
|
|
626
|
+
<xml-example><![CDATA[
|
|
627
|
+
<greeting>Hello, world!</greeting>
|
|
628
|
+
]]></xml-example>
|
|
629
|
+
|
|
630
|
+
<script><![CDATA[
|
|
631
|
+
function validate() {
|
|
632
|
+
if (document.forms[0].email.value == "") {
|
|
633
|
+
alert("Email required!");
|
|
634
|
+
return false;
|
|
635
|
+
}
|
|
636
|
+
return true;
|
|
637
|
+
}
|
|
638
|
+
]]></script>
|
|
639
|
+
|
|
640
|
+
<sql-query><![CDATA[
|
|
641
|
+
SELECT * FROM users
|
|
642
|
+
WHERE age > 18 AND status = 'active'
|
|
643
|
+
ORDER BY name
|
|
644
|
+
]]></sql-query>
|
|
645
|
+
```
|
|
646
|
+
|
|
647
|
+
=== CDATA vs. Character Escaping
|
|
648
|
+
|
|
649
|
+
CDATA sections are useful when you have large blocks of text with many special characters:
|
|
650
|
+
|
|
651
|
+
.Without CDATA (requires escaping)
|
|
652
|
+
```xml
|
|
653
|
+
<code>if (x < y && y > z) { return "success"; }</code>
|
|
654
|
+
```
|
|
655
|
+
|
|
656
|
+
.With CDATA (no escaping needed)
|
|
657
|
+
```xml
|
|
658
|
+
<code><![CDATA[if (x < y && y > z) { return "success"; }]]></code>
|
|
659
|
+
```
|
|
660
|
+
|
|
661
|
+
=== CDATA Limitations
|
|
662
|
+
|
|
663
|
+
- CDATA sections cannot be nested
|
|
664
|
+
- The string `]]>` cannot appear within CDATA content
|
|
665
|
+
- CDATA sections can only contain character data, not markup
|
|
666
|
+
|
|
667
|
+
.Invalid CDATA Usage
|
|
668
|
+
```xml
|
|
669
|
+
<!-- WRONG: Nested CDATA -->
|
|
670
|
+
<![CDATA[
|
|
671
|
+
Some text <![CDATA[nested]]> more text
|
|
672
|
+
]]>
|
|
673
|
+
|
|
674
|
+
<!-- WRONG: Contains ]]> -->
|
|
675
|
+
<![CDATA[
|
|
676
|
+
Array access: arr[i]]>0
|
|
677
|
+
]]>
|
|
678
|
+
```
|
|
679
|
+
|
|
680
|
+
== 9. Processing Instructions
|
|
681
|
+
|
|
682
|
+
Processing instructions (PIs) allow documents to contain instructions for applications. They are not part of the document's character data but must be passed through to the application.
|
|
683
|
+
|
|
684
|
+
```
|
|
685
|
+
PI ::= '<?' PITarget (S (Char* - (Char* '?>' Char*)))? '?>'
|
|
686
|
+
PITarget ::= Name - (('X' | 'x') ('M' | 'm') ('L' | 'l'))
|
|
687
|
+
```
|
|
688
|
+
|
|
689
|
+
=== PI Target Names
|
|
690
|
+
|
|
691
|
+
The PI target identifies the application to which the instruction is directed. Target names beginning with "XML", "xml", and similar combinations are reserved.
|
|
692
|
+
|
|
693
|
+
.Processing Instruction Examples
|
|
694
|
+
```xml
|
|
695
|
+
<?xml-stylesheet type="text/xsl" href="style.xsl"?>
|
|
696
|
+
<?page-break?>
|
|
697
|
+
<?printer font="helvetica" size="12pt"?>
|
|
698
|
+
<?php echo "Hello World"; ?>
|
|
699
|
+
<?custom-app action="process" mode="batch"?>
|
|
700
|
+
```
|
|
701
|
+
|
|
702
|
+
=== Common Processing Instructions
|
|
703
|
+
|
|
704
|
+
==== XML Stylesheet Declaration
|
|
705
|
+
```xml
|
|
706
|
+
<?xml-stylesheet type="text/css" href="styles.css"?>
|
|
707
|
+
<?xml-stylesheet type="text/xsl" href="transform.xsl"?>
|
|
708
|
+
<?xml-stylesheet type="text/xsl" href="style.xsl" title="Default Style"?>
|
|
709
|
+
```
|
|
710
|
+
|
|
711
|
+
==== Application-Specific Instructions
|
|
712
|
+
```xml
|
|
713
|
+
<?cocoon-process type="xslt"?>
|
|
714
|
+
<?robot index="yes" follow="no"?>
|
|
715
|
+
<?include file="header.xml"?>
|
|
716
|
+
<?dbhtml table-width="100%"?>
|
|
717
|
+
```
|
|
718
|
+
|
|
719
|
+
=== PI Placement
|
|
720
|
+
|
|
721
|
+
Processing instructions can appear:
|
|
722
|
+
- In the prolog (before the document element)
|
|
723
|
+
- Within the document type declaration (where allowed)
|
|
724
|
+
- Between elements
|
|
725
|
+
- After the document element
|
|
726
|
+
|
|
727
|
+
.PI Placement Examples
|
|
728
|
+
```xml
|
|
729
|
+
<?xml version="1.0"?>
|
|
730
|
+
<?xml-stylesheet type="text/css" href="style.css"?>
|
|
731
|
+
<!DOCTYPE document [
|
|
732
|
+
<?custom-dtd-instruction?>
|
|
733
|
+
]>
|
|
734
|
+
<document>
|
|
735
|
+
<?page-break?>
|
|
736
|
+
<section>Content here</section>
|
|
737
|
+
<?print-options duplex="true"?>
|
|
738
|
+
</document>
|
|
739
|
+
<?end-processing?>
|
|
740
|
+
```
|
|
741
|
+
|
|
742
|
+
=== Well-Formedness Constraints
|
|
743
|
+
|
|
744
|
+
- Target names cannot begin with "xml" (case-insensitive)
|
|
745
|
+
- PI data cannot contain the string "?>"
|
|
746
|
+
- Parameter entity references are not recognized within PIs
|
|
747
|
+
|
|
748
|
+
.Valid Processing Instructions
|
|
749
|
+
```xml
|
|
750
|
+
<?stylesheet href="main.css"?>
|
|
751
|
+
<?custom data="value with spaces"?>
|
|
752
|
+
<?application-name version="2.0" config="production"?>
|
|
753
|
+
```
|
|
754
|
+
|
|
755
|
+
.Invalid Processing Instructions
|
|
756
|
+
```xml
|
|
757
|
+
<?xml-custom?> <!-- WRONG: starts with "xml" -->
|
|
758
|
+
<?valid data="?>"?> <!-- WRONG: contains "?>" -->
|
|
759
|
+
<?XML-processor?> <!-- WRONG: starts with "XML" -->
|
|
760
|
+
```
|
|
761
|
+
|
|
762
|
+
== 10. Comments
|
|
763
|
+
|
|
764
|
+
Comments provide a way to include notes and documentation within XML documents. They are not part of the document's character data and may optionally be made available to applications.
|
|
765
|
+
|
|
766
|
+
```
|
|
767
|
+
Comment ::= '<!--' ((Char - '-') | ('-' (Char - '-')))* '-->'
|
|
768
|
+
```
|
|
769
|
+
|
|
770
|
+
=== Comment Syntax Rules
|
|
771
|
+
|
|
772
|
+
- Comments begin with `<!--` and end with `-->`
|
|
773
|
+
- Comments cannot contain the string `--` (double hyphen)
|
|
774
|
+
- Comments cannot end with `--->` (three hyphens)
|
|
775
|
+
- Parameter entity references are not recognized within comments
|
|
776
|
+
|
|
777
|
+
.Valid Comment Examples
|
|
778
|
+
```xml
|
|
779
|
+
<!-- This is a simple comment -->
|
|
780
|
+
<!--
|
|
781
|
+
Multi-line comment
|
|
782
|
+
spanning several lines
|
|
783
|
+
-->
|
|
784
|
+
<!-- Author: John Doe, Date: 2023-12-01 -->
|
|
785
|
+
<!-- TODO: Add validation for email field -->
|
|
786
|
+
<!-- Version 1.0 - Initial release -->
|
|
787
|
+
```
|
|
788
|
+
|
|
789
|
+
=== Comment Placement
|
|
790
|
+
|
|
791
|
+
Comments can appear:
|
|
792
|
+
- In the prolog
|
|
793
|
+
- Within the document type declaration (where allowed by grammar)
|
|
794
|
+
- Between elements
|
|
795
|
+
- Within element content (between child elements)
|
|
796
|
+
- After the document element
|
|
797
|
+
|
|
798
|
+
.Comment Placement Examples
|
|
799
|
+
```xml
|
|
800
|
+
<?xml version="1.0"?>
|
|
801
|
+
<!-- Document-level comment -->
|
|
802
|
+
<!DOCTYPE document [
|
|
803
|
+
<!-- DTD comment -->
|
|
804
|
+
<!ELEMENT document (section+)>
|
|
805
|
+
]>
|
|
806
|
+
<document>
|
|
807
|
+
<!-- Section comments -->
|
|
808
|
+
<section>
|
|
809
|
+
<title>Introduction</title>
|
|
810
|
+
<!-- Content comment -->
|
|
811
|
+
<paragraph>Some text here.</paragraph>
|
|
812
|
+
</section>
|
|
813
|
+
<!-- Another section -->
|
|
814
|
+
<section>
|
|
815
|
+
<title>Conclusion</title>
|
|
816
|
+
<paragraph>Final thoughts.</paragraph>
|
|
817
|
+
</section>
|
|
818
|
+
</document>
|
|
819
|
+
<!-- End of document comment -->
|
|
820
|
+
```
|
|
821
|
+
|
|
822
|
+
=== Documentation Comments
|
|
823
|
+
|
|
824
|
+
Comments are often used for documentation purposes:
|
|
825
|
+
|
|
826
|
+
.Documentation Examples
|
|
827
|
+
```xml
|
|
828
|
+
<!--
|
|
829
|
+
Customer Information Schema
|
|
830
|
+
Version: 2.1
|
|
831
|
+
Last Modified: 2023-12-01
|
|
832
|
+
Author: Development Team
|
|
833
|
+
-->
|
|
834
|
+
<customers>
|
|
835
|
+
<!-- Each customer record contains basic information -->
|
|
836
|
+
<customer id="C001">
|
|
837
|
+
<!-- Primary contact information -->
|
|
838
|
+
<name>John Smith</name>
|
|
839
|
+
<email>john@example.com</email>
|
|
840
|
+
|
|
841
|
+
<!-- Optional billing address -->
|
|
842
|
+
<address type="billing">
|
|
843
|
+
<street>123 Main St</street>
|
|
844
|
+
<city>Anytown</city>
|
|
845
|
+
<zip>12345</zip>
|
|
846
|
+
</address>
|
|
847
|
+
</customer>
|
|
848
|
+
</customers>
|
|
849
|
+
```
|
|
850
|
+
|
|
851
|
+
=== Comment Processing
|
|
852
|
+
|
|
853
|
+
XML processors may, but need not, make comment text available to applications. Applications should not rely on comments being preserved during document processing, transformation, or transmission.
|
|
854
|
+
|
|
855
|
+
== 11. Notations
|
|
856
|
+
|
|
857
|
+
Notations identify the format of unparsed entities, elements with notation attributes, or the target application for processing instructions.
|
|
858
|
+
|
|
859
|
+
```
|
|
860
|
+
NotationDecl ::= '<!NOTATION' S Name S (ExternalID | PublicID) S? '>'
|
|
861
|
+
PublicID ::= 'PUBLIC' S PubidLiteral
|
|
862
|
+
```
|
|
863
|
+
|
|
864
|
+
=== Notation Declaration Examples
|
|
865
|
+
|
|
866
|
+
.System Notation
|
|
867
|
+
```xml
|
|
868
|
+
<!NOTATION gif SYSTEM "image/gif">
|
|
869
|
+
<!NOTATION jpeg SYSTEM "image/jpeg">
|
|
870
|
+
<!NOTATION pdf SYSTEM "application/pdf">
|
|
871
|
+
```
|
|
872
|
+
|
|
873
|
+
.Public Notation
|
|
874
|
+
```xml
|
|
875
|
+
<!NOTATION tex PUBLIC "+//ISBN 0-201-13790-1::Knuth//NOTATION The TeXbook//EN">
|
|
876
|
+
<!NOTATION cgm PUBLIC "ISO 8632:1987//NOTATION Computer Graphics Metafile//EN">
|
|
877
|
+
```
|
|
878
|
+
|
|
879
|
+
.Combined Public and System
|
|
880
|
+
```xml
|
|
881
|
+
<!NOTATION svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
|
|
882
|
+
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
|
883
|
+
```
|
|
884
|
+
|
|
885
|
+
=== Using Notations with Unparsed Entities
|
|
886
|
+
|
|
887
|
+
```xml
|
|
888
|
+
<!NOTATION gif SYSTEM "image/gif">
|
|
889
|
+
<!NOTATION jpeg SYSTEM "image/jpeg">
|
|
890
|
+
|
|
891
|
+
<!ENTITY logo SYSTEM "company-logo.gif" NDATA gif>
|
|
892
|
+
<!ENTITY photo SYSTEM "team-photo.jpg" NDATA jpeg>
|
|
893
|
+
|
|
894
|
+
<!ATTLIST image entity ENTITY #REQUIRED>
|
|
895
|
+
|
|
896
|
+
<image entity="logo"/>
|
|
897
|
+
<image entity="photo"/>
|
|
898
|
+
```
|
|
899
|
+
|
|
900
|
+
=== Notation Attributes
|
|
901
|
+
|
|
902
|
+
Elements can have attributes that specify which notation applies:
|
|
903
|
+
|
|
904
|
+
```xml
|
|
905
|
+
<!NOTATION gif SYSTEM "image/gif">
|
|
906
|
+
<!NOTATION jpeg SYSTEM "image/jpeg">
|
|
907
|
+
<!NOTATION png SYSTEM "image/png">
|
|
908
|
+
|
|
909
|
+
<!ATTLIST graphic format NOTATION (gif|jpeg|png) #REQUIRED>
|
|
910
|
+
|
|
911
|
+
<graphic format="gif">company-logo.gif</graphic>
|
|
912
|
+
<graphic format="jpeg">team-photo.jpg</graphic>
|
|
913
|
+
<graphic format="png">diagram.png</graphic>
|
|
914
|
+
```
|
|
915
|
+
|
|
916
|
+
=== Well-Formedness and Validity Constraints
|
|
917
|
+
|
|
918
|
+
- **Unique Notation Name**: A notation name must not be declared more than once
|
|
919
|
+
- **Notation Attributes**: Values must match declared notation names
|
|
920
|
+
- **One Notation Per Element Type**: An element type cannot have more than one NOTATION attribute
|
|
921
|
+
- **No Notation on Empty Element**: NOTATION attributes cannot be declared on EMPTY elements
|
|
922
|
+
|
|
923
|
+
.Complete Notation Example
|
|
924
|
+
```xml
|
|
925
|
+
<!DOCTYPE document [
|
|
926
|
+
<!NOTATION gif SYSTEM "image/gif">
|
|
927
|
+
<!NOTATION jpeg SYSTEM "image/jpeg">
|
|
928
|
+
<!NOTATION wav SYSTEM "audio/wav">
|
|
929
|
+
|
|
930
|
+
<!ENTITY logo SYSTEM "logo.gif" NDATA gif>
|
|
931
|
+
<!ENTITY intro SYSTEM "intro.wav" NDATA wav>
|
|
932
|
+
|
|
933
|
+
<!ELEMENT document (text | media)*>
|
|
934
|
+
<!ELEMENT text (#PCDATA)>
|
|
935
|
+
<!ELEMENT media EMPTY>
|
|
936
|
+
<!ATTLIST media
|
|
937
|
+
type (image|audio) #REQUIRED
|
|
938
|
+
src ENTITY #REQUIRED>
|
|
939
|
+
]>
|
|
940
|
+
|
|
941
|
+
<document>
|
|
942
|
+
<text>Welcome to our site!</text>
|
|
943
|
+
<media type="image" src="logo"/>
|
|
944
|
+
<media type="audio" src="intro"/>
|
|
945
|
+
</document>
|
|
946
|
+
```
|
|
947
|
+
|
|
948
|
+
== 12. Whitespace Handling
|
|
949
|
+
|
|
950
|
+
Whitespace in XML includes space (#x20), tab (#x9), carriage return (#xD), and line feed (#xA) characters. XML processors must handle whitespace appropriately based on context.
|
|
951
|
+
|
|
952
|
+
```
|
|
953
|
+
S ::= (#x20 | #x9 | #xD | #xA)+
|
|
954
|
+
```
|
|
955
|
+
|
|
956
|
+
=== End-of-Line Handling
|
|
957
|
+
|
|
958
|
+
XML processors must normalize line breaks in external parsed entities before parsing by translating:
|
|
959
|
+
- The two-character sequence #xD #xA to a single #xA
|
|
960
|
+
- Any #xD not followed by #xA to a single #xA
|
|
961
|
+
|
|
962
|
+
.Line Break Normalization
|
|
963
|
+
```xml
|
|
964
|
+
<!-- Before normalization (different platforms) -->
|
|
965
|
+
Line 1[CR][LF]
|
|
966
|
+
Line 2[CR]
|
|
967
|
+
Line 3[LF]
|
|
968
|
+
|
|
969
|
+
<!-- After normalization (all become LF) -->
|
|
970
|
+
Line 1[LF]
|
|
971
|
+
Line 2[LF]
|
|
972
|
+
Line 3[LF]
|
|
973
|
+
```
|
|
974
|
+
|
|
975
|
+
=== xml:space Attribute
|
|
976
|
+
|
|
977
|
+
The `xml:space` attribute signals how applications should handle whitespace in element content.
|
|
978
|
+
|
|
979
|
+
```xml
|
|
980
|
+
<!ATTLIST poem xml:space (default|preserve) 'preserve'>
|
|
981
|
+
<!ATTLIST pre xml:space (preserve) #FIXED 'preserve'>
|
|
982
|
+
```
|
|
983
|
+
|
|
984
|
+
==== xml:space="preserve"
|
|
985
|
+
Indicates that applications should preserve all whitespace.
|
|
986
|
+
|
|
987
|
+
.Preserving Whitespace
|
|
988
|
+
```xml
|
|
989
|
+
<poem xml:space="preserve">
|
|
990
|
+
Roses are red,
|
|
991
|
+
Violets are blue,
|
|
992
|
+
XML is structured,
|
|
993
|
+
And so are you.
|
|
994
|
+
</poem>
|
|
995
|
+
|
|
996
|
+
<code xml:space="preserve">
|
|
997
|
+
function hello() {
|
|
998
|
+
console.log("Hello, World!");
|
|
999
|
+
}
|
|
1000
|
+
</code>
|
|
1001
|
+
```
|
|
1002
|
+
|
|
1003
|
+
==== xml:space="default"
|
|
1004
|
+
Indicates that applications may apply default whitespace processing.
|
|
1005
|
+
|
|
1006
|
+
.Default Whitespace Processing
|
|
1007
|
+
```xml
|
|
1008
|
+
<paragraph xml:space="default">
|
|
1009
|
+
This text may have its
|
|
1010
|
+
whitespace normalized by
|
|
1011
|
+
the application.
|
|
1012
|
+
</paragraph>
|
|
1013
|
+
```
|
|
1014
|
+
|
|
1015
|
+
=== Whitespace in Element Content
|
|
1016
|
+
|
|
1017
|
+
In element content, whitespace between child elements is often not significant:
|
|
1018
|
+
|
|
1019
|
+
.Significant vs. Non-significant Whitespace
|
|
1020
|
+
```xml
|
|
1021
|
+
<!-- These are equivalent for processing -->
|
|
1022
|
+
<list><item>First</item><item>Second</item></list>
|
|
1023
|
+
|
|
1024
|
+
<list>
|
|
1025
|
+
<item>First</item>
|
|
1026
|
+
<item>Second</item>
|
|
1027
|
+
</list>
|
|
1028
|
+
|
|
1029
|
+
<list>
|
|
1030
|
+
<item>First</item>
|
|
1031
|
+
<item>Second</item>
|
|
1032
|
+
</list>
|
|
1033
|
+
```
|
|
1034
|
+
|
|
1035
|
+
=== Whitespace in Mixed Content
|
|
1036
|
+
|
|
1037
|
+
In mixed content, whitespace is part of the character data:
|
|
1038
|
+
|
|
1039
|
+
```xml
|
|
1040
|
+
<paragraph>This text has <emphasis>important</emphasis> content.</paragraph>
|
|
1041
|
+
<!-- The spaces around "important" are significant -->
|
|
1042
|
+
```
|
|
1043
|
+
|
|
1044
|
+
=== Attribute Value Whitespace
|
|
1045
|
+
|
|
1046
|
+
Leading and trailing whitespace in attribute values is normalized differently based on attribute type:
|
|
1047
|
+
|
|
1048
|
+
.CDATA Attributes (preserve internal whitespace)
|
|
1049
|
+
```xml
|
|
1050
|
+
<element attr=" value with spaces "/>
|
|
1051
|
+
<!-- Preserves: " value with spaces " -->
|
|
1052
|
+
```
|
|
1053
|
+
|
|
1054
|
+
.Tokenized Attributes (normalize whitespace)
|
|
1055
|
+
```xml
|
|
1056
|
+
<element tokens=" token1 token2 token3 "/>
|
|
1057
|
+
<!-- Becomes: "token1 token2 token3" -->
|
|
1058
|
+
```
|
|
1059
|
+
|
|
1060
|
+
=== Language Identification
|
|
1061
|
+
|
|
1062
|
+
The `xml:lang` attribute specifies the language of element content and attribute values.
|
|
1063
|
+
|
|
1064
|
+
```xml
|
|
1065
|
+
<!ATTLIST poem xml:lang CDATA #IMPLIED>
|
|
1066
|
+
<!ATTLIST gloss xml:lang CDATA 'en'>
|
|
1067
|
+
```
|
|
1068
|
+
|
|
1069
|
+
.Language Examples
|
|
1070
|
+
```xml
|
|
1071
|
+
<p xml:lang="en">The quick brown fox jumps over the lazy dog.</p>
|
|
1072
|
+
<p xml:lang="en-GB">What colour is it?</p>
|
|
1073
|
+
<p xml:lang="en-US">What color is it?</p>
|
|
1074
|
+
<p xml:lang="fr">Bonjour le monde!</p>
|
|
1075
|
+
<sp who="Faust" xml:lang="de">
|
|
1076
|
+
<l>Habe nun, ach! Philosophie,</l>
|
|
1077
|
+
<l>Juristerei, und Medizin</l>
|
|
1078
|
+
</sp>
|
|
1079
|
+
```
|
|
1080
|
+
|
|
1081
|
+
The `xml:lang` value applies to the element and all its children unless overridden. An empty value removes language information.
|
|
1082
|
+
|
|
1083
|
+
== 13. Document Type Definition (DTD)
|
|
1084
|
+
|
|
1085
|
+
The DTD provides a grammar for a class of documents, defining the structure and constraints for elements, attributes, entities, and notations.
|
|
1086
|
+
|
|
1087
|
+
=== DTD Structure
|
|
1088
|
+
|
|
1089
|
+
A DTD consists of:
|
|
1090
|
+
- Element type declarations
|
|
1091
|
+
- Attribute-list declarations
|
|
1092
|
+
- Entity declarations
|
|
1093
|
+
- Notation declarations
|
|
1094
|
+
|
|
1095
|
+
.Internal DTD Subset
|
|
1096
|
+
```xml
|
|
1097
|
+
<!DOCTYPE greeting [
|
|
1098
|
+
<!ELEMENT greeting (#PCDATA)>
|
|
1099
|
+
<!ATTLIST greeting lang CDATA "en">
|
|
1100
|
+
]>
|
|
1101
|
+
<greeting lang="fr">Bonjour!</greeting>
|
|
1102
|
+
```
|
|
1103
|
+
|
|
1104
|
+
.External DTD Subset
|
|
1105
|
+
```xml
|
|
1106
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
|
1107
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
|
1108
|
+
```
|
|
1109
|
+
|
|
1110
|
+
.Combined Internal and External
|
|
1111
|
+
```xml
|
|
1112
|
+
<!DOCTYPE book SYSTEM "book.dtd" [
|
|
1113
|
+
<!ENTITY copyright "Copyright 2023 Publisher">
|
|
1114
|
+
]>
|
|
1115
|
+
```
|
|
1116
|
+
|
|
1117
|
+
=== Element Type Declarations
|
|
1118
|
+
|
|
1119
|
+
Element declarations define the content model for elements.
|
|
1120
|
+
|
|
1121
|
+
```
|
|
1122
|
+
elementdecl ::= '<!ELEMENT' S Name S contentspec S? '>'
|
|
1123
|
+
contentspec ::= 'EMPTY' | 'ANY' | Mixed | children
|
|
1124
|
+
```
|
|
1125
|
+
|
|
1126
|
+
==== EMPTY Elements
|
|
1127
|
+
```xml
|
|
1128
|
+
<!ELEMENT br EMPTY>
|
|
1129
|
+
<!ELEMENT img EMPTY>
|
|
1130
|
+
<br/>
|
|
1131
|
+
<img src="photo.jpg" alt="Photo"/>
|
|
1132
|
+
```
|
|
1133
|
+
|
|
1134
|
+
==== ANY Content
|
|
1135
|
+
```xml
|
|
1136
|
+
<!ELEMENT container ANY>
|
|
1137
|
+
<container>
|
|
1138
|
+
<text>Any content</text>
|
|
1139
|
+
<number>123</number>
|
|
1140
|
+
</container>
|
|
1141
|
+
```
|
|
1142
|
+
|
|
1143
|
+
==== Element Content Models
|
|
1144
|
+
```xml
|
|
1145
|
+
<!ELEMENT book (title, author+, chapter*)>
|
|
1146
|
+
<!ELEMENT title (#PCDATA)>
|
|
1147
|
+
<!ELEMENT author (#PCDATA)>
|
|
1148
|
+
<!ELEMENT chapter (title, section+)>
|
|
1149
|
+
<!ELEMENT section (title, paragraph+)>
|
|
1150
|
+
<!ELEMENT paragraph (#PCDATA | emphasis)*>
|
|
1151
|
+
<!ELEMENT emphasis (#PCDATA)>
|
|
1152
|
+
```
|
|
1153
|
+
|
|
1154
|
+
===== Occurrence Indicators
|
|
1155
|
+
- `?` - Zero or one occurrence
|
|
1156
|
+
- `*` - Zero or more occurrences
|
|
1157
|
+
- `+` - One or more occurrences
|
|
1158
|
+
- No indicator - Exactly one occurrence
|
|
1159
|
+
|
|
1160
|
+
.Content Model Examples
|
|
1161
|
+
```xml
|
|
1162
|
+
<!ELEMENT article (title, author?, abstract, body, references*)>
|
|
1163
|
+
<!ELEMENT list (item+)>
|
|
1164
|
+
<!ELEMENT optional-section (content?)>
|
|
1165
|
+
<!ELEMENT repeating-section (content*)>
|
|
1166
|
+
```
|
|
1167
|
+
|
|
1168
|
+
===== Choice and Sequence
|
|
1169
|
+
```xml
|
|
1170
|
+
<!ELEMENT media (image | video | audio)>
|
|
1171
|
+
<!ELEMENT book (frontmatter, body, backmatter)>
|
|
1172
|
+
<!ELEMENT citation (author, (book-title | article-title), year)>
|
|
1173
|
+
```
|
|
1174
|
+
|
|
1175
|
+
==== Mixed Content
|
|
1176
|
+
```xml
|
|
1177
|
+
<!ELEMENT p (#PCDATA | em | strong | code)*>
|
|
1178
|
+
<!ELEMENT description (#PCDATA)>
|
|
1179
|
+
|
|
1180
|
+
<p>This is <em>emphasized</em> text with <strong>strong</strong> content.</p>
|
|
1181
|
+
```
|
|
1182
|
+
|
|
1183
|
+
=== Attribute-List Declarations
|
|
1184
|
+
|
|
1185
|
+
```
|
|
1186
|
+
AttlistDecl ::= '<!ATTLIST' S Name AttDef* S? '>'
|
|
1187
|
+
AttDef ::= S Name S AttType S DefaultDecl
|
|
1188
|
+
```
|
|
1189
|
+
|
|
1190
|
+
.Attribute Declarations
|
|
1191
|
+
```xml
|
|
1192
|
+
<!ATTLIST img
|
|
1193
|
+
src CDATA #REQUIRED
|
|
1194
|
+
alt CDATA #REQUIRED
|
|
1195
|
+
width CDATA #IMPLIED
|
|
1196
|
+
height CDATA #IMPLIED
|
|
1197
|
+
border CDATA "0">
|
|
1198
|
+
|
|
1199
|
+
<!ATTLIST input
|
|
1200
|
+
type (text|password|submit|reset) "text"
|
|
1201
|
+
name CDATA #REQUIRED
|
|
1202
|
+
value CDATA #IMPLIED
|
|
1203
|
+
size CDATA #IMPLIED>
|
|
1204
|
+
```
|
|
1205
|
+
|
|
1206
|
+
=== Entity Declarations in DTD
|
|
1207
|
+
|
|
1208
|
+
.Internal General Entities
|
|
1209
|
+
```xml
|
|
1210
|
+
<!ENTITY company "Acme Corporation">
|
|
1211
|
+
<!ENTITY email "info@acme.com">
|
|
1212
|
+
<!ENTITY phone "+1-555-0123">
|
|
1213
|
+
```
|
|
1214
|
+
|
|
1215
|
+
.External General Entities
|
|
1216
|
+
```xml
|
|
1217
|
+
<!ENTITY legal SYSTEM "legal-notice.xml">
|
|
1218
|
+
<!ENTITY terms SYSTEM "terms-of-service.xml">
|
|
1219
|
+
```
|
|
1220
|
+
|
|
1221
|
+
.Parameter Entities
|
|
1222
|
+
```xml
|
|
1223
|
+
<!ENTITY % text-elements "em | strong | code | br">
|
|
1224
|
+
<!ENTITY % common-attrs "id ID #IMPLIED
|
|
1225
|
+
class CDATA #IMPLIED">
|
|
1226
|
+
|
|
1227
|
+
<!ELEMENT p (#PCDATA | %text-elements;)*>
|
|
1228
|
+
<!ATTLIST p %common-attrs;>
|
|
1229
|
+
<!ATTLIST div %common-attrs;>
|
|
1230
|
+
```
|
|
1231
|
+
|
|
1232
|
+
=== Complete DTD Example
|
|
1233
|
+
|
|
1234
|
+
```xml
|
|
1235
|
+
<!DOCTYPE library [
|
|
1236
|
+
<!-- Element Declarations -->
|
|
1237
|
+
<!ELEMENT library (book+)>
|
|
1238
|
+
<!ELEMENT book (title, author+, isbn?, year, description?)>
|
|
1239
|
+
<!ELEMENT title (#PCDATA)>
|
|
1240
|
+
<!ELEMENT author (#PCDATA)>
|
|
1241
|
+
<!ELEMENT isbn (#PCDATA)>
|
|
1242
|
+
<!ELEMENT year (#PCDATA)>
|
|
1243
|
+
<!ELEMENT description (#PCDATA | em | strong)*>
|
|
1244
|
+
<!ELEMENT em (#PCDATA)>
|
|
1245
|
+
<!ELEMENT strong (#PCDATA)>
|
|
1246
|
+
|
|
1247
|
+
<!-- Attribute Declarations -->
|
|
1248
|
+
<!ATTLIST book
|
|
1249
|
+
id ID #REQUIRED
|
|
1250
|
+
category (fiction|non-fiction|technical) "non-fiction"
|
|
1251
|
+
language CDATA "en">
|
|
1252
|
+
<!ATTLIST author
|
|
1253
|
+
role (primary|secondary) "primary">
|
|
1254
|
+
|
|
1255
|
+
<!-- Entity Declarations -->
|
|
1256
|
+
<!ENTITY publisher "Academic Press">
|
|
1257
|
+
<!ENTITY contact "library@university.edu">
|
|
1258
|
+
]>
|
|
1259
|
+
|
|
1260
|
+
<library>
|
|
1261
|
+
<book id="xml-guide" category="technical">
|
|
1262
|
+
<title>XML Processing Guide</title>
|
|
1263
|
+
<author role="primary">John Smith</author>
|
|
1264
|
+
<author role="secondary">Jane Doe</author>
|
|
1265
|
+
<isbn>978-0-123456-78-9</isbn>
|
|
1266
|
+
<year>2023</year>
|
|
1267
|
+
<description>
|
|
1268
|
+
A <em>comprehensive</em> guide to <strong>XML processing</strong>
|
|
1269
|
+
published by &publisher;. Contact: &contact;
|
|
1270
|
+
</description>
|
|
1271
|
+
</book>
|
|
1272
|
+
== 15. Validity Constraints
|
|
1273
|
+
|
|
1274
|
+
A valid XML document is well-formed and conforms to its DTD. Validity constraints are checked by validating XML processors.
|
|
1275
|
+
|
|
1276
|
+
=== Element Validity
|
|
1277
|
+
|
|
1278
|
+
==== Element Valid
|
|
1279
|
+
An element is valid if there is a matching element declaration and the content matches the declared content model.
|
|
1280
|
+
|
|
1281
|
+
.Valid Element Examples
|
|
1282
|
+
```xml
|
|
1283
|
+
<!ELEMENT book (title, author+, year)>
|
|
1284
|
+
<!ELEMENT title (#PCDATA)>
|
|
1285
|
+
<!ELEMENT author (#PCDATA)>
|
|
1286
|
+
<!ELEMENT year (#PCDATA)>
|
|
1287
|
+
|
|
1288
|
+
<book>
|
|
1289
|
+
<title>XML Guide</title>
|
|
1290
|
+
<author>John Smith</author>
|
|
1291
|
+
<author>Jane Doe</author>
|
|
1292
|
+
<year>2023</year>
|
|
1293
|
+
</book>
|
|
1294
|
+
```
|
|
1295
|
+
|
|
1296
|
+
==== Root Element Type
|
|
1297
|
+
The root element must match the name in the DOCTYPE declaration.
|
|
1298
|
+
|
|
1299
|
+
.Valid Root Element
|
|
1300
|
+
```xml
|
|
1301
|
+
<!DOCTYPE library [...]>
|
|
1302
|
+
<library>...</library>
|
|
1303
|
+
```
|
|
1304
|
+
|
|
1305
|
+
.Invalid Root Element
|
|
1306
|
+
```xml
|
|
1307
|
+
<!DOCTYPE library [...]>
|
|
1308
|
+
<catalog>...</catalog> <!-- WRONG: doesn't match DOCTYPE -->
|
|
1309
|
+
```
|
|
1310
|
+
|
|
1311
|
+
=== Attribute Validity
|
|
1312
|
+
|
|
1313
|
+
==== Attribute Value Type
|
|
1314
|
+
Attribute values must conform to their declared types.
|
|
1315
|
+
|
|
1316
|
+
.ID Attribute Validation
|
|
1317
|
+
```xml
|
|
1318
|
+
<!ATTLIST person id ID #REQUIRED>
|
|
1319
|
+
<person id="person-001"/> <!-- Valid -->
|
|
1320
|
+
<person id="123"/> <!-- Invalid: starts with digit -->
|
|
1321
|
+
```
|
|
1322
|
+
|
|
1323
|
+
.Enumerated Attribute Validation
|
|
1324
|
+
```xml
|
|
1325
|
+
<!ATTLIST status value (active|inactive|pending) "active">
|
|
1326
|
+
<status value="active"/> <!-- Valid -->
|
|
1327
|
+
<status value="unknown"/> <!-- Invalid: not in enumeration -->
|
|
1328
|
+
```
|
|
1329
|
+
|
|
1330
|
+
.IDREF Attribute Validation
|
|
1331
|
+
```xml
|
|
1332
|
+
<!ATTLIST ref target IDREF #REQUIRED>
|
|
1333
|
+
<section id="intro">...</section>
|
|
1334
|
+
<ref target="intro"/> <!-- Valid: references existing ID -->
|
|
1335
|
+
<ref target="missing"/> <!-- Invalid: no matching ID -->
|
|
1336
|
+
```
|
|
1337
|
+
|
|
1338
|
+
==== Required Attribute
|
|
1339
|
+
Elements must include all required attributes.
|
|
1340
|
+
|
|
1341
|
+
```xml
|
|
1342
|
+
<!ATTLIST img src CDATA #REQUIRED
|
|
1343
|
+
alt CDATA #REQUIRED>
|
|
1344
|
+
<img src="photo.jpg" alt="Photo"/> <!-- Valid -->
|
|
1345
|
+
<img src="photo.jpg"/> <!-- Invalid: missing required alt -->
|
|
1346
|
+
```
|
|
1347
|
+
|
|
1348
|
+
==== Fixed Attribute Default
|
|
1349
|
+
Fixed attributes must have the declared default value.
|
|
1350
|
+
|
|
1351
|
+
```xml
|
|
1352
|
+
<!ATTLIST form method CDATA #FIXED "POST">
|
|
1353
|
+
<form method="POST"/> <!-- Valid -->
|
|
1354
|
+
<form method="GET"/> <!-- Invalid: doesn't match fixed value -->
|
|
1355
|
+
```
|
|
1356
|
+
|
|
1357
|
+
=== Entity Validity
|
|
1358
|
+
|
|
1359
|
+
==== Entity Declared
|
|
1360
|
+
All referenced entities must be declared in validating processors.
|
|
1361
|
+
|
|
1362
|
+
.Valid Entity Declaration and Reference
|
|
1363
|
+
```xml
|
|
1364
|
+
<!ENTITY company "Acme Corporation">
|
|
1365
|
+
<text>&company;</text>
|
|
1366
|
+
```
|
|
1367
|
+
|
|
1368
|
+
==== Notation Declared
|
|
1369
|
+
Notation names in NOTATION attributes must be declared.
|
|
1370
|
+
|
|
1371
|
+
```xml
|
|
1372
|
+
<!NOTATION gif SYSTEM "image/gif">
|
|
1373
|
+
<!ATTLIST image format NOTATION (gif|jpeg) #IMPLIED>
|
|
1374
|
+
<image format="gif"/> <!-- Valid: gif notation declared -->
|
|
1375
|
+
<image format="png"/> <!-- Invalid: png notation not declared -->
|
|
1376
|
+
```
|
|
1377
|
+
|
|
1378
|
+
=== DTD Constraints
|
|
1379
|
+
|
|
1380
|
+
==== Unique Element Type Declaration
|
|
1381
|
+
Element types can only be declared once.
|
|
1382
|
+
|
|
1383
|
+
.Valid (Single Declaration)
|
|
1384
|
+
```xml
|
|
1385
|
+
<!ELEMENT person (name, age)>
|
|
1386
|
+
```
|
|
1387
|
+
|
|
1388
|
+
.Invalid (Duplicate Declaration)
|
|
1389
|
+
```xml
|
|
1390
|
+
<!ELEMENT person (name, age)>
|
|
1391
|
+
<!ELEMENT person (name, email)> <!-- WRONG: duplicate -->
|
|
1392
|
+
```
|
|
1393
|
+
|
|
1394
|
+
==== Unique Notation Name
|
|
1395
|
+
Notation names can only be declared once.
|
|
1396
|
+
|
|
1397
|
+
```xml
|
|
1398
|
+
<!NOTATION gif SYSTEM "image/gif">
|
|
1399
|
+
<!NOTATION gif SYSTEM "graphics/gif"> <!-- WRONG: duplicate -->
|
|
1400
|
+
```
|
|
1401
|
+
|
|
1402
|
+
==== No Duplicate Types
|
|
1403
|
+
Mixed content declarations cannot repeat element names.
|
|
1404
|
+
|
|
1405
|
+
.Valid Mixed Content
|
|
1406
|
+
```xml
|
|
1407
|
+
<!ELEMENT p (#PCDATA | em | strong)*>
|
|
1408
|
+
```
|
|
1409
|
+
|
|
1410
|
+
.Invalid Mixed Content
|
|
1411
|
+
```xml
|
|
1412
|
+
<!ELEMENT p (#PCDATA | em | strong | em)*> <!-- WRONG: em repeated -->
|
|
1413
|
+
```
|
|
1414
|
+
|
|
1415
|
+
=== Standalone Document Declaration
|
|
1416
|
+
|
|
1417
|
+
For standalone documents, external markup declarations cannot affect the document's information set.
|
|
1418
|
+
|
|
1419
|
+
```xml
|
|
1420
|
+
<?xml version="1.0" standalone="yes"?>
|
|
1421
|
+
```
|
|
1422
|
+
|
|
1423
|
+
Standalone="yes" is invalid if external DTD contains:
|
|
1424
|
+
- Attribute defaults for attributes used in the document
|
|
1425
|
+
- Entity declarations for entities referenced in the document
|
|
1426
|
+
- Attribute normalization that would change values
|
|
1427
|
+
- Element content declarations for elements containing whitespace
|
|
1428
|
+
|
|
1429
|
+
=== Complete Validity Example
|
|
1430
|
+
|
|
1431
|
+
.Valid Document with DTD
|
|
1432
|
+
```xml
|
|
1433
|
+
<?xml version="1.0"?>
|
|
1434
|
+
<!DOCTYPE library [
|
|
1435
|
+
<!ELEMENT library (book+)>
|
|
1436
|
+
<!ELEMENT book (title, author+, isbn?, year)>
|
|
1437
|
+
<!ELEMENT title (#PCDATA)>
|
|
1438
|
+
<!ELEMENT author (#PCDATA)>
|
|
1439
|
+
<!ELEMENT isbn (#PCDATA)>
|
|
1440
|
+
<!ELEMENT year (#PCDATA)>
|
|
1441
|
+
|
|
1442
|
+
<!ATTLIST book
|
|
1443
|
+
id ID #REQUIRED
|
|
1444
|
+
category (fiction|technical) "technical">
|
|
1445
|
+
<!ATTLIST author
|
|
1446
|
+
role (primary|secondary) "primary">
|
|
1447
|
+
|
|
1448
|
+
<!ENTITY publisher "Academic Press">
|
|
1449
|
+
]>
|
|
1450
|
+
|
|
1451
|
+
<library>
|
|
1452
|
+
<book id="book1" category="technical">
|
|
1453
|
+
<title>XML Processing Guide</title>
|
|
1454
|
+
<author role="primary">John Smith</author>
|
|
1455
|
+
<isbn>978-0-123456-78-9</isbn>
|
|
1456
|
+
<year>2023</year>
|
|
1457
|
+
</book>
|
|
1458
|
+
<book id="book2" category="fiction">
|
|
1459
|
+
<title>The Data Adventure</title>
|
|
1460
|
+
<author>Jane Doe</author>
|
|
1461
|
+
<year>2023</year>
|
|
1462
|
+
</book>
|
|
1463
|
+
</library>
|
|
1464
|
+
```
|
|
1465
|
+
|
|
1466
|
+
== 16. Namespaces (Informative)
|
|
1467
|
+
|
|
1468
|
+
Note: Namespaces are defined in a separate specification (Namespaces in XML) but are commonly used with XML 1.0.
|
|
1469
|
+
|
|
1470
|
+
Namespaces provide a method to avoid element name conflicts when combining XML documents from different vocabularies.
|
|
1471
|
+
|
|
1472
|
+
=== Namespace Declaration
|
|
1473
|
+
|
|
1474
|
+
.Default Namespace
|
|
1475
|
+
```xml
|
|
1476
|
+
<document xmlns="http://example.com/schema">
|
|
1477
|
+
<title>Default namespace content</title>
|
|
1478
|
+
</document>
|
|
1479
|
+
```
|
|
1480
|
+
|
|
1481
|
+
.Prefixed Namespace
|
|
1482
|
+
```xml
|
|
1483
|
+
<doc:document xmlns:doc="http://example.com/document"
|
|
1484
|
+
xmlns:meta="http://example.com/metadata">
|
|
1485
|
+
<doc:title>Document Title</doc:title>
|
|
1486
|
+
<meta:author>John Smith</meta:author>
|
|
1487
|
+
</doc:document>
|
|
1488
|
+
```
|
|
1489
|
+
|
|
1490
|
+
.Multiple Namespaces
|
|
1491
|
+
```xml
|
|
1492
|
+
<html xmlns="http://www.w3.org/1999/xhtml"
|
|
1493
|
+
xmlns:svg="http://www.w3.org/2000/svg">
|
|
1494
|
+
<head>
|
|
1495
|
+
<title>Mixed Content</title>
|
|
1496
|
+
</head>
|
|
1497
|
+
<body>
|
|
1498
|
+
<p>This document contains SVG:</p>
|
|
1499
|
+
<svg:svg width="100" height="100">
|
|
1500
|
+
<svg:circle cx="50" cy="50" r="40"/>
|
|
1501
|
+
</svg:svg>
|
|
1502
|
+
</body>
|
|
1503
|
+
</html>
|
|
1504
|
+
```
|
|
1505
|
+
|
|
1506
|
+
== 17. Character Encoding Detection
|
|
1507
|
+
|
|
1508
|
+
XML processors can detect character encoding through several methods:
|
|
1509
|
+
|
|
1510
|
+
=== Byte Order Mark (BOM) Detection
|
|
1511
|
+
|
|
1512
|
+
.UTF-8 with BOM
|
|
1513
|
+
```
|
|
1514
|
+
EF BB BF [XML content in UTF-8]
|
|
1515
|
+
```
|
|
1516
|
+
|
|
1517
|
+
.UTF-16 Big Endian with BOM
|
|
1518
|
+
```
|
|
1519
|
+
FE FF [XML content in UTF-16BE]
|
|
1520
|
+
```
|
|
1521
|
+
|
|
1522
|
+
.UTF-16 Little Endian with BOM
|
|
1523
|
+
```
|
|
1524
|
+
FF FE [XML content in UTF-16LE]
|
|
1525
|
+
```
|
|
1526
|
+
|
|
1527
|
+
=== Auto-detection without BOM
|
|
1528
|
+
|
|
1529
|
+
.UTF-8/ASCII Detection
|
|
1530
|
+
```
|
|
1531
|
+
3C 3F 78 6D <!-- "<?xm" in UTF-8/ASCII -->
|
|
1532
|
+
```
|
|
1533
|
+
|
|
1534
|
+
.UTF-16BE Detection
|
|
1535
|
+
```
|
|
1536
|
+
00 3C 00 3F <!-- "<?xm" in UTF-16BE -->
|
|
1537
|
+
```
|
|
1538
|
+
|
|
1539
|
+
.UTF-16LE Detection
|
|
1540
|
+
```
|
|
1541
|
+
3C 00 3F 00 <!-- "<?xm" in UTF-16LE -->
|
|
1542
|
+
```
|
|
1543
|
+
|
|
1544
|
+
== 18. Conformance
|
|
1545
|
+
|
|
1546
|
+
=== Validating Processors
|
|
1547
|
+
|
|
1548
|
+
Validating XML processors must:
|
|
1549
|
+
- Report violations of well-formedness constraints
|
|
1550
|
+
- Report violations of validity constraints (when validating)
|
|
1551
|
+
- Read and process the entire DTD and all external parsed entities
|
|
1552
|
+
- Provide complete document information to applications
|
|
1553
|
+
|
|
1554
|
+
=== Non-Validating Processors
|
|
1555
|
+
|
|
1556
|
+
Non-validating XML processors must:
|
|
1557
|
+
- Report well-formedness violations in the document entity and any parsed entities they read
|
|
1558
|
+
- Process all declarations in the internal DTD subset
|
|
1559
|
+
- Process parameter entities up to the first unread parameter entity reference
|
|
1560
|
+
- May but need not read external entities
|
|
1561
|
+
|
|
1562
|
+
.Processor Behavior Example
|
|
1563
|
+
```xml
|
|
1564
|
+
<?xml version="1.0"?>
|
|
1565
|
+
<!DOCTYPE doc SYSTEM "external.dtd" [
|
|
1566
|
+
<!ENTITY internal "Internal entity">
|
|
1567
|
+
<!ENTITY % param "<!ELEMENT extra (#PCDATA)>">
|
|
1568
|
+
%param;
|
|
1569
|
+
]>
|
|
1570
|
+
<doc>
|
|
1571
|
+
<content>&internal;</content>
|
|
1572
|
+
<extra>This element defined by parameter entity</extra>
|
|
1573
|
+
</doc>
|
|
1574
|
+
```
|
|
1575
|
+
|
|
1576
|
+
== 19. Error Handling
|
|
1577
|
+
|
|
1578
|
+
=== Fatal Errors
|
|
1579
|
+
|
|
1580
|
+
Fatal errors must be reported and prevent continued normal processing:
|
|
1581
|
+
- Well-formedness violations
|
|
1582
|
+
- Character encoding errors
|
|
1583
|
+
- Recursive entity references
|
|
1584
|
+
- Malformed markup
|
|
1585
|
+
|
|
1586
|
+
=== Non-Fatal Errors
|
|
1587
|
+
|
|
1588
|
+
Non-fatal errors may be reported but allow continued processing:
|
|
1589
|
+
- Validity constraint violations
|
|
1590
|
+
- Undeclared entities (in non-validating processors)
|
|
1591
|
+
- DTD parsing errors (in non-validating processors)
|
|
1592
|
+
|
|
1593
|
+
=== Error Recovery
|
|
1594
|
+
|
|
1595
|
+
.Well-Formedness Error (Fatal)
|
|
1596
|
+
```xml
|
|
1597
|
+
<element>
|
|
1598
|
+
<nested>Content</element> <!-- FATAL: Improper nesting -->
|
|
1599
|
+
</nested>
|
|
1600
|
+
```
|
|
1601
|
+
|
|
1602
|
+
.Validity Error (Non-Fatal for non-validating processors)
|
|
1603
|
+
```xml
|
|
1604
|
+
<!DOCTYPE doc [<!ELEMENT doc (title)>]>
|
|
1605
|
+
<doc>
|
|
1606
|
+
<paragraph>Content</paragraph> <!-- VALIDITY ERROR: unexpected element -->
|
|
1607
|
+
</doc>
|
|
1608
|
+
```
|
|
1609
|
+
|
|
1610
|
+
== 20. Best Practices and Recommendations
|
|
1611
|
+
|
|
1612
|
+
=== Document Structure
|
|
1613
|
+
|
|
1614
|
+
.Recommended Document Structure
|
|
1615
|
+
```xml
|
|
1616
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
1617
|
+
<!DOCTYPE document SYSTEM "document.dtd">
|
|
1618
|
+
<document>
|
|
1619
|
+
<!-- Clear, logical structure -->
|
|
1620
|
+
<metadata>
|
|
1621
|
+
<title>Document Title</title>
|
|
1622
|
+
<author>Author Name</author>
|
|
1623
|
+
<date>2023-12-01</date>
|
|
1624
|
+
</metadata>
|
|
1625
|
+
<content>
|
|
1626
|
+
<section id="introduction">
|
|
1627
|
+
<title>Introduction</title>
|
|
1628
|
+
<paragraph>Content here...</paragraph>
|
|
1629
|
+
</section>
|
|
1630
|
+
</content>
|
|
1631
|
+
</document>
|
|
1632
|
+
```
|
|
1633
|
+
|
|
1634
|
+
=== Naming Conventions
|
|
1635
|
+
|
|
1636
|
+
.Recommended Element and Attribute Names
|
|
1637
|
+
```xml
|
|
1638
|
+
<!-- Use descriptive, meaningful names -->
|
|
1639
|
+
<customer-record id="cust-001">
|
|
1640
|
+
<personal-info>
|
|
1641
|
+
<full-name>John Smith</full-name>
|
|
1642
|
+
<birth-date>1990-01-15</birth-date>
|
|
1643
|
+
</personal-info>
|
|
1644
|
+
<contact-info>
|
|
1645
|
+
<email-address>john@example.com</email-address>
|
|
1646
|
+
<phone-number type="mobile">555-0123</phone-number>
|
|
1647
|
+
</contact-info>
|
|
1648
|
+
</customer-record>
|
|
1649
|
+
```
|
|
1650
|
+
|
|
1651
|
+
=== Entity Usage
|
|
1652
|
+
|
|
1653
|
+
.Recommended Entity Patterns
|
|
1654
|
+
```xml
|
|
1655
|
+
<!DOCTYPE document [
|
|
1656
|
+
<!-- Use entities for repeated content -->
|
|
1657
|
+
<!ENTITY company "Acme Corporation">
|
|
1658
|
+
<!ENTITY copyright "Copyright © 2023 &company;">
|
|
1659
|
+
<!ENTITY contact-email "support@acme.com">
|
|
1660
|
+
|
|
1661
|
+
<!-- Use parameter entities for DTD modularity -->
|
|
1662
|
+
<!ENTITY % common-attrs "
|
|
1663
|
+
id ID #IMPLIED
|
|
1664
|
+
class CDATA #IMPLIED">
|
|
1665
|
+
]>
|
|
1666
|
+
```
|
|
1667
|
+
|
|
1668
|
+
=== Internationalization
|
|
1669
|
+
|
|
1670
|
+
.Proper Language and Encoding Handling
|
|
1671
|
+
```xml
|
|
1672
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
1673
|
+
<multilingual-document>
|
|
1674
|
+
<content xml:lang="en">
|
|
1675
|
+
<title>English Title</title>
|
|
1676
|
+
<text>English content here.</text>
|
|
1677
|
+
</content>
|
|
1678
|
+
<content xml:lang="es">
|
|
1679
|
+
<title>Título en Español</title>
|
|
1680
|
+
<text>Contenido en español aquí.</text>
|
|
1681
|
+
</content>
|
|
1682
|
+
<content xml:lang="zh-CN">
|
|
1683
|
+
<title>中文标题</title>
|
|
1684
|
+
<text>中文内容。</text>
|
|
1685
|
+
</content>
|
|
1686
|
+
</multilingual-document>
|
|
1687
|
+
```
|
|
1688
|
+
|
|
1689
|
+
== Conclusion
|
|
1690
|
+
|
|
1691
|
+
This document provides a comprehensive specification of XML 1.0 (Fifth Edition) based on the W3C Recommendation. It covers all aspects of XML document structure, syntax, processing requirements, and includes extensive examples to illustrate proper usage.
|
|
1692
|
+
|
|
1693
|
+
Key aspects covered include:
|
|
1694
|
+
- Document structure and well-formedness
|
|
1695
|
+
- Character encoding and references
|
|
1696
|
+
- Elements, attributes, and content models
|
|
1697
|
+
- Entities and entity processing
|
|
1698
|
+
- Processing instructions and comments
|
|
1699
|
+
- CDATA sections and character data
|
|
1700
|
+
- DTD components and declarations
|
|
1701
|
+
- Validity and conformance requirements
|
|
1702
|
+
- Error handling and processor behavior
|
|
1703
|
+
- Best practices and recommendations
|
|
1704
|
+
|
|
1705
|
+
For the most current information and errata, refer to the official W3C XML 1.0 specification at https://www.w3.org/TR/xml/.
|
|
1706
|
+
|
|
1707
|
+
== 14. Well-Formedness Constraints
|
|
1708
|
+
|
|
1709
|
+
A well-formed XML document must satisfy these constraints:
|
|
1710
|
+
|
|
1711
|
+
=== Document Structure Constraints
|
|
1712
|
+
|
|
1713
|
+
==== Single Root Element
|
|
1714
|
+
The document must have exactly one root element.
|
|
1715
|
+
|
|
1716
|
+
.Valid (Single Root)
|
|
1717
|
+
```xml
|
|
1718
|
+
<document>
|
|
1719
|
+
<section>Content</section>
|
|
1720
|
+
</document>
|
|
1721
|
+
```
|
|
1722
|
+
|
|
1723
|
+
.Invalid (Multiple Roots)
|
|
1724
|
+
```xml
|
|
1725
|
+
<section>First</section>
|
|
1726
|
+
<section>Second</section>
|
|
1727
|
+
```
|
|
1728
|
+
|
|
1729
|
+
==== Proper Element Nesting
|
|
1730
|
+
Elements must be properly nested - no overlapping.
|
|
1731
|
+
|
|
1732
|
+
.Valid Nesting
|
|
1733
|
+
```xml
|
|
1734
|
+
<outer>
|
|
1735
|
+
<inner>
|
|
1736
|
+
<content>Text</content>
|
|
1737
|
+
</inner>
|
|
1738
|
+
</outer>
|
|
1739
|
+
```
|
|
1740
|
+
|
|
1741
|
+
.Invalid Nesting
|
|
1742
|
+
```xml
|
|
1743
|
+
<outer>
|
|
1744
|
+
<inner>
|
|
1745
|
+
<content>Text</outer>
|
|
1746
|
+
</inner>
|
|
1747
|
+
</content>
|
|
1748
|
+
```
|
|
1749
|
+
|
|
1750
|
+
=== Element and Attribute Constraints
|
|
1751
|
+
|
|
1752
|
+
==== Element Type Match
|
|
1753
|
+
End tag names must match start tag names.
|
|
1754
|
+
|
|
1755
|
+
.Valid Matching
|
|
1756
|
+
```xml
|
|
1757
|
+
<section>Content</section>
|
|
1758
|
+
<title>Heading</title>
|
|
1759
|
+
```
|
|
1760
|
+
|
|
1761
|
+
.Invalid Matching
|
|
1762
|
+
```xml
|
|
1763
|
+
<section>Content</title>
|
|
1764
|
+
<Title>Content</title> <!-- Case sensitive -->
|
|
1765
|
+
```
|
|
1766
|
+
|
|
1767
|
+
==== Unique Attribute Specification
|
|
1768
|
+
No attribute name may appear more than once in the same tag.
|
|
1769
|
+
|
|
1770
|
+
.Valid Attributes
|
|
1771
|
+
```xml
|
|
1772
|
+
<img src="photo.jpg" alt="Photo" width="300"/>
|
|
1773
|
+
```
|
|
1774
|
+
|
|
1775
|
+
.Invalid Attributes
|
|
1776
|
+
```xml
|
|
1777
|
+
<img src="photo.jpg" src="backup.jpg" alt="Photo"/>
|
|
1778
|
+
```
|
|
1779
|
+
|
|
1780
|
+
==== Attribute Value Constraints
|
|
1781
|
+
- Attribute values must be quoted
|
|
1782
|
+
- Values cannot contain '<' character
|
|
1783
|
+
- Values cannot contain direct or indirect references to external entities
|
|
1784
|
+
|
|
1785
|
+
.Valid Attribute Values
|
|
1786
|
+
```xml
|
|
1787
|
+
<element attr="value with spaces"/>
|
|
1788
|
+
<element attr='single quoted value'/>
|
|
1789
|
+
<element attr="escaped < and & characters"/>
|
|
1790
|
+
```
|
|
1791
|
+
|
|
1792
|
+
.Invalid Attribute Values
|
|
1793
|
+
```xml
|
|
1794
|
+
<element attr=unquoted/>
|
|
1795
|
+
<element attr="value < with literal less-than"/>
|
|
1796
|
+
<element attr="&external-entity;"/>
|
|
1797
|
+
```
|
|
1798
|
+
|
|
1799
|
+
=== Entity Reference Constraints
|
|
1800
|
+
|
|
1801
|
+
==== Entity Declared
|
|
1802
|
+
Referenced entities must be declared (except predefined entities).
|
|
1803
|
+
|
|
1804
|
+
.Valid Entity Usage
|
|
1805
|
+
```xml
|
|
1806
|
+
<!ENTITY greeting "Hello">
|
|
1807
|
+
<text>&greeting; & <</text>
|
|
1808
|
+
```
|
|
1809
|
+
|
|
1810
|
+
==== Parsed Entity
|
|
1811
|
+
Entity references cannot refer to unparsed entities.
|
|
1812
|
+
|
|
1813
|
+
.Valid: General Entity Reference
|
|
1814
|
+
```xml
|
|
1815
|
+
<!ENTITY text "Hello World">
|
|
1816
|
+
<message>&text;</message>
|
|
1817
|
+
```
|
|
1818
|
+
|
|
1819
|
+
.Invalid: Unparsed Entity Reference
|
|
1820
|
+
```xml
|
|
1821
|
+
<!ENTITY image SYSTEM "photo.jpg" NDATA jpeg>
|
|
1822
|
+
<text>ℑ</text> <!-- WRONG: Cannot reference unparsed entity -->
|
|
1823
|
+
```
|
|
1824
|
+
|
|
1825
|
+
==== No Recursion
|
|
1826
|
+
Entities cannot contain recursive references.
|
|
1827
|
+
|
|
1828
|
+
.Invalid Recursive Entity
|
|
1829
|
+
```xml
|
|
1830
|
+
<!ENTITY recursive "Start &recursive; End"> <!-- WRONG -->
|
|
1831
|
+
```
|
|
1832
|
+
|
|
1833
|
+
==== Parameter Entities in DTD Only
|
|
1834
|
+
Parameter entity references can only appear in DTD.
|
|
1835
|
+
|
|
1836
|
+
.Valid Parameter Entity Usage
|
|
1837
|
+
```xml
|
|
1838
|
+
<!DOCTYPE doc [
|
|
1839
|
+
<!ENTITY % common "id ID #IMPLIED">
|
|
1840
|
+
<!ATTLIST element %common;>
|
|
1841
|
+
]>
|
|
1842
|
+
```
|
|
1843
|
+
|
|
1844
|
+
.Invalid Parameter Entity Usage
|
|
1845
|
+
```xml
|
|
1846
|
+
<document>
|
|
1847
|
+
%common; <!-- WRONG: Parameter entity in content -->
|
|
1848
|
+
</document>
|
|
1849
|
+
```
|
|
1850
|
+
|
|
1851
|
+
=== Character and Reference Constraints
|
|
1852
|
+
|
|
1853
|
+
==== Legal Character
|
|
1854
|
+
Character references must refer to legal XML characters.
|
|
1855
|
+
|
|
1856
|
+
.Valid Character References
|
|
1857
|
+
```xml
|
|
1858
|
+
<text>Copyright ©</text>
|
|
1859
|
+
<text>Registered ®</text>
|
|
1860
|
+
```
|
|
1861
|
+
|
|
1862
|
+
==== No External Entity References in Attributes
|
|
1863
|
+
Attribute values cannot contain references to external entities.
|
|
1864
|
+
|
|
1865
|
+
.Valid Internal Entity in Attribute
|
|
1866
|
+
```xml
|
|
1867
|
+
<!ENTITY version "1.0">
|
|
1868
|
+
<document version="&version;"/>
|
|
1869
|
+
```
|
|
1870
|
+
|
|
1871
|
+
.Invalid External Entity in Attribute
|
|
1872
|
+
```xml
|
|
1873
|
+
<!ENTITY config SYSTEM "config.xml">
|
|
1874
|
+
<document config="&config;"/> <!-- WRONG -->
|
|
1875
|
+
```
|
|
1876
|
+
|
|
1877
|
+
=== Complete Well-Formedness Example
|
|
1878
|
+
|
|
1879
|
+
.Well-Formed Document
|
|
1880
|
+
```xml
|
|
1881
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
1882
|
+
<!DOCTYPE document [
|
|
1883
|
+
<!ENTITY company "Acme Corp">
|
|
1884
|
+
<!ENTITY copyright "Copyright © 2023">
|
|
1885
|
+
]>
|
|
1886
|
+
<document>
|
|
1887
|
+
<header>
|
|
1888
|
+
<title>Sample Document</title>
|
|
1889
|
+
<info>©right; &company;</info>
|
|
1890
|
+
</header>
|
|
1891
|
+
<body>
|
|
1892
|
+
<section id="intro">
|
|
1893
|
+
<title>Introduction</title>
|
|
1894
|
+
<paragraph>This is properly nested content.</paragraph>
|
|
1895
|
+
</section>
|
|
1896
|
+
</body>
|
|
1897
|
+
</document>
|
|
1898
|
+
```
|
|
1899
|
+
|
|
1900
|
+
== Implementation Status in Codebase
|
|
1901
|
+
|
|
1902
|
+
This section summarizes the current implementation status of XML 1.0 features in the `lutaml-model` codebase as of September 12, 2025. This record helps track which features are fully implemented, partially implemented, or not yet supported.
|
|
1903
|
+
|
|
1904
|
+
[cols="2,2,6",options="header"]
|
|
1905
|
+
|===
|
|
1906
|
+
| Feature | Status | Notes
|
|
1907
|
+
|
|
1908
|
+
| Document Structure & Well-Formedness | Implemented | Parsing and validation of root element, element nesting, and basic well-formedness constraints are supported.
|
|
1909
|
+
| Character Encoding (UTF-8/UTF-16) | Implemented | UTF-8 and UTF-16 support is present. Other encodings may require manual configuration.
|
|
1910
|
+
| Elements & Tags | Implemented | Element creation, start/end tags, empty elements, and content parsing are supported.
|
|
1911
|
+
| Attributes | Implemented | Name-value pairs, attribute types (CDATA, ID, IDREF, etc.), and normalization are handled.
|
|
1912
|
+
| Entities (General/Internal) | Partially Implemented | Internal entities and basic entity replacement are supported. External entities and parameter entities may have limited or no support.
|
|
1913
|
+
| Predefined Entities | Implemented | Standard XML entities (`<`, `>`, `&`, `'`, `"`) are recognized.
|
|
1914
|
+
| Character Data & Escaping | Implemented | Character data parsing and escaping of special characters are supported.
|
|
1915
|
+
| CDATA Sections | Implemented | CDATA section parsing and handling are supported.
|
|
1916
|
+
| Processing Instructions | Partially Implemented | Basic PI parsing is supported. Application-specific PI handling may require extension.
|
|
1917
|
+
| Comments | Implemented | XML comments are parsed and can be preserved or ignored as needed.
|
|
1918
|
+
| Notations & Unparsed Entities | Not Implemented | Notation declarations and unparsed entity support are not present.
|
|
1919
|
+
| Whitespace Handling | Implemented | Whitespace normalization and `xml:space` attribute handling are supported.
|
|
1920
|
+
| Language Identification (`xml:lang`) | Implemented | `xml:lang` attribute is recognized and propagated.
|
|
1921
|
+
| DTD Parsing & Validation | Partially Implemented | Internal DTD subset parsing is supported. Full validation and external DTD support are limited.
|
|
1922
|
+
| Validity Constraints | Partially Implemented | Some validity checks (element/attribute types, required attributes) are present. Full DTD-based validation is not complete.
|
|
1923
|
+
| Namespaces | Partially Implemented | Basic namespace parsing is present. Advanced namespace features may be limited.
|
|
1924
|
+
| Error Handling | Implemented | Well-formedness errors are reported. Validity errors may be partially reported.
|
|
1925
|
+
| Best Practices & Recommendations | N/A | Not directly applicable to codebase features.
|
|
1926
|
+
|===
|
|
1927
|
+
|
|
1928
|
+
This table should be updated as new features are added or existing features are improved. For details on specific modules or files, refer to the `lib/lutaml/model/` directory and related adapters.
|
|
1929
|
+
// Detailed Implementation Breakdown
|
|
1930
|
+
|
|
1931
|
+
=== Detailed Feature Implementation Breakdown
|
|
1932
|
+
|
|
1933
|
+
Below is a more detailed explanation of the implementation status for each XML 1.0 feature in the `lutaml-model` codebase:
|
|
1934
|
+
|
|
1935
|
+
* Document Structure & Well-Formedness
|
|
1936
|
+
- **Implemented**: The parser enforces a single root element, proper nesting, and matching start/end tags. Unique attribute specification is checked. Most well-formedness constraints are validated during parsing.
|
|
1937
|
+
|
|
1938
|
+
* Character Encoding (UTF-8/UTF-16)
|
|
1939
|
+
- **Implemented**: Files in UTF-8 and UTF-16 are accepted and parsed. Other encodings (e.g., ISO-8859-1) may require manual handling or conversion before parsing.
|
|
1940
|
+
|
|
1941
|
+
* Elements & Tags
|
|
1942
|
+
- **Implemented**: All element types, start tags, end tags, and empty elements are supported. Content between tags is parsed and validated.
|
|
1943
|
+
|
|
1944
|
+
* Attributes
|
|
1945
|
+
- **Implemented**: Attributes are parsed, including CDATA, ID, IDREF, and enumerated types. Attribute normalization and uniqueness are enforced. Some advanced attribute types (e.g., NOTATION) may not be fully supported.
|
|
1946
|
+
|
|
1947
|
+
* Entities (General/Internal)
|
|
1948
|
+
- **Partially Implemented**: Internal general entities are supported and replaced in content. External entities and parameter entities (used in DTDs) are not fully supported. Recursive entity references are detected and reported as errors.
|
|
1949
|
+
|
|
1950
|
+
* Predefined Entities
|
|
1951
|
+
- **Implemented**: The five standard XML entities (`<`, `>`, `&`, `'`, `"`) are always recognized and replaced.
|
|
1952
|
+
|
|
1953
|
+
* Character Data & Escaping
|
|
1954
|
+
- **Implemented**: Character data is parsed, and special characters are escaped/unescaped as needed. Illegal characters are detected and reported.
|
|
1955
|
+
|
|
1956
|
+
* CDATA Sections
|
|
1957
|
+
- **Implemented**: CDATA sections are parsed and their content is handled as character data. Nested CDATA and invalid CDATA content are detected as errors.
|
|
1958
|
+
|
|
1959
|
+
* Processing Instructions
|
|
1960
|
+
- **Partially Implemented**: Basic parsing of processing instructions (PIs) is supported. PIs are recognized and can be extracted, but application-specific handling or validation of PI targets/data is limited.
|
|
1961
|
+
|
|
1962
|
+
* Comments
|
|
1963
|
+
- **Implemented**: XML comments are parsed and can be preserved or ignored. Invalid comment syntax (e.g., double hyphens) is detected.
|
|
1964
|
+
|
|
1965
|
+
* Notations & Unparsed Entities
|
|
1966
|
+
- **Not Implemented**: Notation declarations and unparsed entity support are not present. Elements and attributes using NOTATION types will not be validated or processed.
|
|
1967
|
+
|
|
1968
|
+
* Whitespace Handling
|
|
1969
|
+
- **Implemented**: Whitespace normalization is performed according to XML rules. The `xml:space` attribute is recognized and affects whitespace preservation in element content.
|
|
1970
|
+
|
|
1971
|
+
* Language Identification (`xml:lang`)
|
|
1972
|
+
- **Implemented**: The `xml:lang` attribute is parsed and its value is propagated to child elements as required.
|
|
1973
|
+
|
|
1974
|
+
* DTD Parsing & Validation
|
|
1975
|
+
- **Partially Implemented**: Internal DTD subsets are parsed for element and attribute declarations. Full validation against external DTDs, parameter entities, and advanced DTD features is not supported.
|
|
1976
|
+
|
|
1977
|
+
* Validity Constraints
|
|
1978
|
+
- **Partially Implemented**: Some validity checks (e.g., required attributes, enumerated values, ID/IDREF matching) are performed. Full validation against DTD content models and constraints is incomplete.
|
|
1979
|
+
|
|
1980
|
+
* Namespaces
|
|
1981
|
+
- **Partially Implemented**: Basic namespace parsing (xmlns attributes, prefixed names) is supported. Advanced namespace features (e.g., namespace scoping, URI resolution) may be limited.
|
|
1982
|
+
|
|
1983
|
+
* Error Handling
|
|
1984
|
+
- **Implemented**: Well-formedness errors are reported and halt parsing. Some validity errors are reported, but error recovery and reporting for all cases may be limited.
|
|
1985
|
+
|
|
1986
|
+
* Best Practices & Recommendations
|
|
1987
|
+
- **N/A**: These are guidelines for XML usage and do not correspond to codebase features.
|
|
1988
|
+
|
|
1989
|
+
Refer to the source code in `lib/lutaml/model/` for details on specific modules and their responsibilities. If you need to know about a particular feature or module, please specify.
|