/
ExtensibleContentModelMain.xhtml
640 lines (549 loc) · 21.6 KB
/
ExtensibleContentModelMain.xhtml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="generator" content=
"HTML Tidy for Mac OS X (vers 31 October 2006 - Apple Inc. build 13), see www.w3.org" />
<title>XML Design Patterns - Extensible Content Model</title>
<meta name="DESCRIPTION" content=
"XMLPatterns.com - Designing Good XML Structure with Patterns. Extensible Content Model ." />
<meta name="KEYWORDS" content=
"XML, patterns, structure, DTD, XMLSchema, schema, design, designing, structuring, structural, document, documents, pattern, book, markup, language, mark up, effective, software, introduction" />
<link rel="stylesheet" type="text/css" href="indexPage.css" />
<style type="text/css">
/*<![CDATA[*/
:link { color: #556677 }
:visited { color: #668099 }
:active { color: #778899 }
span.c259 {color: #000000; font-size: 80%}
span.c258 {font-size: 64%}
span.c257 {font-size: 80%}
span.c256 {color: #000000; font-size: 64%}
div.c255 {text-align: center}
/*]]>*/
</style>
</head>
<body>
<table width="100%">
<tr>
<td colspan="11">
<div class="c255">
<script type="text/javascript">
//<![CDATA[
<!--
google_ad_client = "pub-2722110793302013";
google_alternate_color = "000000";
google_ad_width = 728;
google_ad_height = 15;
google_ad_format = "728x15_0ads_al_s";
google_ad_channel ="4690258935";
google_color_border = "FFFFFF";
google_color_bg = "FFFFFF";
google_color_link = "000000";
google_color_url = "336699";
google_color_text = "333333";
//-->
//]]>
</script> <script type="text/javascript" src=
"../pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
</td>
</tr>
<tr>
<td width="1"></td>
<td width="1"></td>
<td width="1"></td>
<td width="1"></td>
<td width="1"></td>
<td width="1"></td>
<td width="1"></td>
<td width="1"></td>
<td width="1"></td>
<td width="120">
<table cellpadding="1">
<tr>
<td><a href="index.html"><span class=
"c256"><b>XMLPatterns.com</b></span></a></td>
</tr>
<tr>
<td><br />
<a title="XMLPatterns.com Home Page" href="index.html"
class="navLink">Home</a></td>
</tr>
<tr>
<td><br />
<a title=
"Backround material for understanding XML Design Patterns"
href="intro.shtml" class=
"navLink">Introduction</a></td>
</tr>
<tr>
<td><br />
<a title="The patterns themselves" href=
"patterns.shtml" class="navLink">Patterns</a></td>
</tr>
<tr>
<td><a class="subNavLink" title=
"Patterns organized by Category" href=
"categoryAllPatterns.shtml">Categorized</a><br /></td>
</tr>
<tr>
<td><a class="subNavLink" title=
"Patterns Alphabetically" href=
"alphaAllPatterns.shtml">Alphabetical</a><br /></td>
</tr>
<tr>
<td><a class="subNavLink" title=
"Latest Patterns listed first" href=
"chronoAllPatterns.shtml">Chronological</a><br /></td>
</tr>
<tr>
<td><br />
<a title="Books about patterns and XML" href=
"books.shtml" class="navLink">Books</a></td>
</tr>
<tr>
<td><br />
<a title="Links to other web sites." href="links.shtml"
class="navLink">Links</a></td>
</tr>
<tr>
<td><br />
<a title=
"Information about contacts, privacy and copyright"
href="about.shtml" class="navLink">About</a></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td>
<table>
<tr>
<td><b><a href=
"http://www.vegasfreebie.com/">Vegas
Freebie!</a></b></td>
</tr>
<tr>
<td><a href=
"http://www.vegasfreebie.com/"><span class=
"c257">Free Things to do In Las
Vegas</span></a></td>
</tr>
<tr>
<td><a href=
"http://www.vegasfreebie.com/"><span class=
"c258">www.vegasfreebie.com</span></a></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
<td>
<table width=
"100%">
<tr>
<td>
<div class="title">
Extensible Content Model
</div>
</td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td>
<table width="100%">
<tr>
<td align="right"><a href=
"ExtensibleContentModelPrint.shtml"><span class=
"smallLink">Printable Version</span></a></td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table width="100%" cellspacing="10"
>
<tr>
<td>
<div>
<br />
<div class="text">
<p><a name="Abstract" id=
"Abstract"><span class=
"bigheading">A</span><span class=
"heading">bstract:</span></a></p>Provide a
mechanism which allows additional elements
to be added into existing content models.
</div><br />
<br />
<div class="text">
<p><a name="Problem" id=
"Problem"><span class=
"bigheading">P</span><span class=
"heading">roblem:</span></a></p>At the time
of designing the document type, the
designer may not be able to foresee all of
the uses and situations where document
instances will be used. To provide for
flexibility, the contents of elements can
be made to be redefinable by the document
instance.
</div><br />
<br />
<div class="text">
<p><a name="Context" id=
"Context"><span class=
"bigheading">C</span><span class=
"heading">ontext:</span></a></p>This is a
very general mechanism that can be used
anytime additional flexibility is needed.
</div><br />
<br />
<div class="text">
<p><a name="Forces" id=
"Forces"><span class="bigheading">F</span><span class="heading">orces:</span></a></p>Flexibility
is often required for a document type to be
able to be used effectively. Flexibility,
however often makes processing of the
documents more difficult. Customization of
software is often needed to deal with the
flexibility.
</div><br />
<br />
<div class="text">
<p><a name="Solution" id=
"Solution"><span class=
"bigheading">S</span><span class=
"heading">olution:</span></a></p>The
designer of the document can add a
mechanism to allow the author of a document
instance to extend an element definition
from the document type.
</div><br />
<br />
<div class="text">
<p><a name="Examples" id=
"Examples"><span class=
"bigheading">E</span><span class=
"heading">xamples:</span></a></p>
<div class="subsection">
Using DTDs
</div>
<p>This example uses a DTD that allows the
document instance to extend an <span class=
"sample">Address</span> element. This is
done through use a parameter entity which
is defined in the DTD, but the creator of
the document instance can overwrite.</p>
<p>First a DTD is created that defines a
simple <span class="sample">Address</span>
type, consisting only of the <span class=
"sample">Name</span>, <span class=
"sample">Street</span> and <span class=
"sample">City</span>. Realizing that this
may not be enough for all users of this
document type, the designer defines a
parameter entity called <span class=
"sample">local.address</span> that is blank
("") but can be extended in the document
instance.</p>
<p>purchase_order.dtd</p>
<pre>
<span class="sample">
<!ENTITY % local.address "">
<!ENTITY % address "Name, Street, City %local.address;">
<!ELEMENT PurchaseOrder ( Item, ShipTo, BillTo )>
<!ELEMENT Item (#PCDATA)>
<!ELEMENT ShipTo (%address;)>;
<!ELEMENT BillTo (%address;)>;
<!ELEMENT Name (#PCDATA)>
<!ELEMENT Street (#PCDATA)>
<!ELEMENT City (#PCDATA)>
</span>
</pre>
<p>The creator of a document decides that
the address defined in the DTD is
inadequate for the document being create,
so he extends the definition of an Address
to include State and Zip. To do this he
creates his own definition of the
local.address Parameter Entity. This allows
him to add these elements to his own
address structure.</p>
<p>mydoc.xml</p>
<pre>
<span class="sample">
<!DOCTYPE PURCHASE_ORDER SYSTEM "purchase_order.dtd" [
<!ENTITY % local.address ", State, Zip" >
<!ELEMENT State (#PCDATA)>
<!ELEMENT Zip (#PCDATA)>
]>
<PurchaseOrder>
<Item>X123</Item>
<ShipTo>
<Name>Bob Smith</Name>
<Street>123 Maple Dr.</Street>
<City>Anytown</City>
<State>CA</State>
<Zip>12345</Zip>
</ShipTo>
<BillTo>
<Name>Bob Smith</Name>
<Street>123 Maple Dr.</Street>
<City>Anytown</City>
<State>CA</State>
<Zip>12345</Zip>
</BillTo>
</PurchaseOrder>
</span>
</pre>
<div class="subsection">
Using XML Schemas
</div>This next example uses XML Schemas to
do the same thing. We use the XML Schema
mechanism of deriving types by extension to
do this. This example is based on a working
draft of the XML Schema proposal, so this
example may not be compatible with future
versions of the XML Schema. A schema is
created to include the simple Address type
with a Name, Street, and City.
<p>PurchaseOrder.xsd</p>
<pre>
<span class="sample">
<xsd:schema
xmlns:xsd="http://www.w3.org/1999/XMLSchema">
<xsd:element
name="purchaseOrder"
type="PurchaseOrderType"/>
<xsd:complexType name="PurchaseOrderType">
<xsd:element name="Item" type="xsd:string"/>
<xsd:element name="ShipTo" type="Address"/>
<xsd:element name="BillTo" type="Address"/>
</xsd:complexType>
<xsd:complexType name="Address">
<xsd:element name="Name" type="xsd:string"/>
<xsd:element name="Street" type="xsd:string"/>
<xsd:element name="City" type="xsd:string"/>
</xsd:complexType>
</xsd:schema>
</span>
</pre>
<p>The author of a document realizes that
this simple address definition will not be
adequate, so a new address type is created.
The new type is extended from the old type,
and adds the State and Zip elements.</p>
<p>US-Address.xsd</p>
<pre>
<span class="sample">
<xsd:schema
xmlns:xsd="http://www.w3.org/1999/XMLSchema"
xmlns:po="http:www.xmlpatterns.com/PurchaseOrder">
<xsd:complexType name="US-Address"
base="po:Address"
derivedBy="extension">
<xsd:element name="State" type="xsd:string"/>
<xsd:element name="Zip" type="xsd:decimal"/>
</xsd:complexType>
</xsd:schema>
</span>
</pre>
<p>To use the new address type in a
document instance, both of the schema files
are used.</p>
<p>mydoc.xml</p>
<pre>
<span class="sample">
<PurchaseOrder
xmlns="http:www.xmlpatterns.com/PurchaseOrder"
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
xmlns:us="http://www.xmlpatterns.com/US-Address"
xsi:schemaLocation=
"http://www.xmlpatterns.com/purchaseOrder.xsd
http://www.xmlpatterns.com/US-Address.xsd">
<Item>X123</Item>
<ShipTo xsi:type="us:US-Address">
<Name>Bob Smith</Name>
<Street>123 Maple Dr.</Street>
<City>Anytown</City>
<State>CA</State>
<Zip>12345</Zip>
</ShipTo>
<BillTo xsi:type="us:US-Address">
<Name>Bob Smith</Name>
<Street>123 Maple Dr.</Street>
<City>Anytown</City>
<State>CA</State>
<Zip>12345</Zip>
</BillTo>
</PurchaseOrder>
</span>
</pre>
</div><br />
<br />
<div class="text">
<p><span class=
"bigheading">D</span><span class=
"heading">iscussion:</span></p>
<p>This provides a powerful extension
mechanism to the authors of documents. Like
with all added flexibility, the power comes
with a price. Extensible Content Models
create new element types that standard
processing tools for a document type would
not be able to process correctly. Often
customization of software is needed to
handle the extensions correctly.</p>
<p>This technique has the advantage of not
needlessly over complicating the structure
of the document type if the flexibility is
not needed. Authors can use the document
type without even being aware that the
extension mechanism exists. The existence
of these Extensible Content Models can be
made known only to "power users", if
desired.</p>
</div><br />
<br />
<div class="text">
<p><span class=
"bigheading">R</span><span class=
"heading">elated Patterns:</span></p>This
mechanism is powerful, but also requires
knowledge of DTD syntax to apply. Often the
<a href="GenericElementMain.shtml">Generic
Element</a> pattern combined with <a href=
"RoleAttributeMain.shtml">Role
Attribute</a>s may be a more appropriate
choice if the authors of the document are
not experienced with XML.
</div><br />
<br />
<div class="text">
<p><span class=
"bigheading">K</span><span class=
"heading">nown Uses:</span></p>
<p>The <a href=
"cgi-bin/leave-14797.cgi">Information and
Content Exchange (ICE) Protocol Appendix
A</a> demonstrates applications of this
pattern.</p>
<p>The <a href=
"cgi-bin/leave-37627.cgi#AEN258">XMLspec
DTD</a> uses parameter entities to allow
for customization of many elements.</p>
<p>The DocBook DTD allows for the types of
<a href=
"cgi-bin/leave-24825.cgi">customizations</a>
.</p>
</div><br />
<br />
<div class="text">
<p><span class=
"bigheading">R</span><span class=
"heading">eferences:</span></p>See <a href=
"books.shtml#0136422993">Structuring XML
Documents</a>, Section 8.1.2: Adding
Elements Types to a DTD.
</div><br />
</div>
<hr />
</td>
<td>
<table>
<tr>
<td>
<script type="text/javascript">
//<![CDATA[
<!--
google_ad_client = "pub-2722110793302013";
google_alternate_ad_url = "http://www.alternateurl.com/show?memid=56&size=160x600";
google_ad_width = 160;
google_ad_height = 600;
google_ad_format = "160x600_as";
google_ad_type = "text_image";
google_ad_channel ="9928488069";
google_color_border = "CCCC99";
google_color_bg = "CCCC99";
google_color_link = "000099";
google_color_url = "000000";
google_color_text = "000000";
//-->
//]]>
</script> <script type="text/javascript"
src=
"../pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="11"></td>
</tr>
</table>
<table width="100%" >
<tr>
<td>Visit our sponsors: <span class="c258"><a href=
"mailto:info@xmlpatterns.com">(Interested in advertising on
XMLPatterns.com?</a>)</span></td>
</tr>
</table>
<table width="100%" >
<tr>
<td colspan='6'><span class="c259">XML? Playing online
<a href='http://www.allslots.com/slot-machines.php'>slot
machines</a> is even more fun than creating XML
designs.</span></td>
</tr>
<tr>
<td> </td>
</tr>
</table><!--
<rdf:Description
rdf:about="http://www.xmlpatterns.com/ExtensibleContentModelMain.shtml"
dc:title="XML Design Pattern - Extensible Content Model"
dc:identifier="http://www.xmlpatterns.com/ExtensibleContentModelMain.shtml" />
</rdf:RDF>
-->
</body>
</html>