If you have any questions, suggestions, or corrections, please contact me.
All the examples and accompanying files are copyright ©2000 by Elizabeth Castro. All rights reserved.
The files from this chapter are in the introduction folder.
Page | Section | Code |
---|---|---|
12 | The Problem wth HTML | |
13 | The Power of XML | |
15 | XML in the Real World | |
16 | About This Book |
The files from this chapter are in the writing folder.
Page | Section | Code |
---|---|---|
23 | Rules for Writing XML (note) | |
24 | Declaring the XML Version | version.xml |
25 | Creating the Root Element | root.xml |
26 | Writing Non-Empty Elements | nonempty.xml |
27 | Nesting Elements | |
28 | Adding Attributes | |
29 | Using Empty Elements | empty.xml |
30 | Writing Comments | comments.xml |
31 | Writing Five Special Symbols | specialsymbols.xml |
32 | Displaying Elements as Text | cdata.xml |
The files from this chapter are in the dtd_creating folder.
Page | Section | Code |
---|---|---|
36 | Declaring an Internal DTD |
internal.xml |
37 | Writing an External DTD | end_species.dtd |
39 |
Declaring a Personal External DTD |
Figure 2.4: external.xml |
40 | Declaring a Public External DTD | external_public.xml |
The files in this section are in the dtd_defining folder. You'll note that these files contain more than what is shown in the illustrations. I have fleshed out these examples so that you can really test them against an XML Validator. In fact, I heartily recommend doing so. Copy them to your server, play around with them, and then study the error messages that XML Validator gives you! I hope you find them useful.
Page | Section | Code |
---|---|---|
44 | Defining an Element to Contain Only Text | onlytext.dtd, onlytext.xml |
45 | Defining an Element to Contain One Child | onechild.dtd, onechild.xml |
46 | Defining an Element to Contain a Sequence | sequence.dtd, sequence.xml |
47 | Defining Choices |
choices.dtd, |
48 | Defining How Many Units | |
50 - 51 | Defining Simple Attributes |
Figure 3.16: att_optional.dtd Figure 3:18: att_required.dtd Figure 3.20: att_default.dtd Figure 3.22: att_fixed.dtd |
52 | Defining Attributes with Unique Values | att_unique.dtd Figure 3.25: att_unique1.xml (top), att_unique2.xml (bottom) |
53 | Referencing Attributes with Unique Values |
Figures 3.26 and 3.28: idref.dtd |
54 | Restricting Attributes to Valid XML Names |
The files in this section are in the dtd_entities folder.
Page | Section | HTML |
---|---|---|
56 | Creating Shortcuts for Text | |
57 | Using Shortcuts for Text | shortcuts.xml |
58 | Shortcuts for Text in External Files | Figure 4.5: hwi.ent Figure 4.6: shortcuts_ext.dtd Figure 4.7: shortcuts_ext.xml |
60 | Creating and Using Shortcuts for DTDs |
Figure 4.9: pic.dtd |
62 | Creating Entites for Unparsed Content | Figure 4.13: tiger.jpg Figure 4.14, 4.15: unparsed.dtd |
63 | Embedding Unparsed Content |
Figure 4.16 and top part of Figure 4.17: unparsed.dtd
(same as Figs. 4.14 and 4.15) |
Note that the examples in these chapters are almost all based on the end_species.xsd and end_species.xml files, with minor changes, according to the topic in question. More importantly, I have gone to the trouble (over two excrutiating months) to flesh out the examples so that you can really play around with them, send them to XSV for validation and see how they work. Please do copy them to your own site, and then test them and retest them and analyze them. Pay special attention to the comments within the documents, in which I explain which parts are in question and what is going on with them. I hope you find them useful. Let me know.
The files in this section are in the schemas folder.
Page | Section | Code |
---|---|---|
72 | Beginning a Simple Schema | begin.xsd |
73 | Indicating a Simple Schema's Location | location.xml |
74 | Annotating Schemas | annotation.xsd |
The files in this section are in the schemas_simple folder.
Page | Section | Code |
---|---|---|
76-77 | Declaring an Element with a Simple Type |
Figure 6.1: simpletype.xsd Figure 6.4:simpletype_date.xsd |
78-79 | Using Date and Time Types |
Figure 6.7: timeDuration.xsd, timeDuration.xml Figure 6.8: time.xsd, time.xml Figure 6.9: timeInstant.xsd, timeInstant.xml Figure 6.10: date.xsd, date.xml Figure 6.11: month.xsd, month.xml Figure 6.12: year.xsd, year.xml Figure 6.13: century.xsd, century.xml Figure 6.14: recurringDate.xsd, recurringDate.xml Figure 6.15: recurringDay.xsd, recurringDay.xml |
80 | Using Number Types | numbers.xsd Figure 6.17: numbers.xml Figure 6.18: numbers2.xml |
81 | Deriving Custom Simple Types | custom_simple.xsd, custom_simple.xml |
82 | Using Anonymous Custom Types | anonymous_simple.xsd, anonymous_simple.xml |
83 | Specifying a Set of Acceptable Values | enumeration.xsd, enumeration.xml |
84-85 | Specifying a Pattern for a Simple Type |
Figure 6.27: pattern.xsd Figure 6.29: timeDuration_andpattern.xsd Figure 6.31: pattern_choices.xsd |
86-87 | Specifying a Range of Acceptable Values |
Figure 6.33: maxInclusive.xsd Figure 6.35: maxExclusive.xsd Figure 6.37: minInclusive.xsd Figure 6.39: minExclusive.xsd |
88 | Limiting the Length of a Simple Type |
Figures 6:41 and 6:42: length.xsd, length.xml Figure 6:43: maxLength.xsd |
89 | Limiting a Number's Digits |
precision_scale.xsd |
90 | Creating List Types |
Figures 6.49 and 6.50: list.xsd, list.xml Figures 6.51 and 6.52: list_length.xsd, list_length.xml |
91 | Predefining an Element's Content |
Figure 6.53: fixed.xsd Figure 6.56: default.xsd |
The files in this section are in the schemas_complex folder.
Page | Section | Code |
---|---|---|
94 | Defining Elements to Contain Only Elements | onlyelements.xsd (onlyelements.xml) |
95 | Requiring Elements to Appear in Sequence | sequence.xsd (sequence.xml) |
96 | Creating a Set of Choices | choice.xsd Figure 7.8: top: choice.xml bottom: choice2.xml |
97 | Allowing Elements to Appear in Any Order | all.xsd, all.xml |
98 | Defining Named Groups | group.xsd |
99 | Referencing a Named Group | group.xml |
100 | Referencing Already Defined Elements | referencing.xsd (referencing.xml) |
101 | Controlling How Many |
Figure 7.18: howmany2.xsd (howmany2.xml) |
102 | Defining Elements to Contain Only Text |
Figures 7.19 and 7.20: textonly.xsd |
103 | Defining Empty Elements | Figures 7.23 and 7.24: empty.xsd Figure 7.25: empty.xml |
104 | Defining Elements with Mixed Content | Figures 7.26 and 7.27: mixed.xsd Figure 7.28: mixed.xml |
105 | Basing Complex Types on Complex Types | Figures 7.29, 7.30, 7.31: basing.xsd Figure 7.32: basing.xml |
106 | Declaring an Element of Complex Type |
Figure 7.33: basing.xsd Figure 7.34: declaring.xsd
(declaring.xml) |
107 | Elements with Anonymous Complex Types |
Figure 7.36: anonymous.xsd |
108 | Declaring Attributes | attributes.xsd, attributes.xml |
109 | Requiring an Attribute |
Figure 7.40: required.xsd Figure 7.41: top: required.xml; bottom: required2.xml required3.xml (an invalid instance, not shown in the book) |
110 | Predefining an AttributeÕs Content |
Figure 7.42: fixed.xsd Figure 7.44: default.xsd |
111 | Defining Attribute Groups | attgroups.xsd |
112 | Referencing Attribute Groups |
The files in this section are in the namespaces folder. Note that no Schema files are given for the latter examples...we don't get to validating XML files that use namespaces until the next chapter. If there is sufficient interest, I could work out the appropriate schema files. Let me know.
Page | Section | Code |
---|---|---|
113 | Using Namespaces in XML |
Figure 8.1: rivers.xsd (rivers.xml) Figure 8.2: global_endspecies.xsd (global_endspecies.xml) |
115 | Declaring Default Namespaces |
Figure 8.4: default1.xml Figure 8.5: default2.xml |
116-117 | Namespaces for Individual Elements |
Figures 8.6 and 8.7: individual.xml Figure 8.8: individual2.xml |
The files in this section are in the namespaces_sv folder.
Page | Section | Code |
---|---|---|
123 | Populating a Namespace |
populating.xsd (populating.xml, if you insist) |
124 | Adding All Locally Declared Elements | |
125 | Adding Particular Locally Declared Elements | |
126-127 | Referencing Components with Namespaces |
Figure 9.4: referencing_namespaces.xsd
Figure 9.5: referencing_namespaces2.xsd
|
128 | The Schema of Schemas as the Default | referencing_namespaces3.xsd (referencing_namespaces3.xml, for the impatient) |
129 | Namespaces and Validating XML | validating.xml (you can validate this file with referencing_namespaces.xsd if you like by typing in both URLs--first the xml then the xsd--in the XSV) |
130 | Indicating Where a Schema Is | location.xml (referencing_namespaces.xsd) |
131 | Schemas in Multiple Files | threats.xsd, include.xsd (and then use include.xml as an instance) |
132 | Importing Components | import.xsd, rivers_import.xsd (not rivers.xsd), and then import.xml as an instance. Note the errata resolved in the notes here. |
Note that the examples in these chapters are almost all based on the tigers_rhinos.xml and tigers_complete.xsl files. The XSLT files gradually build up to the tigers_complete.xsl file, with minor changes depending on the topic in question. For maximum effect, you'll also need the tiger.jpg and rhino.jpg images.
The files in this section are in the xslt folder. Note that all of these XSLT files transform the very same tigers_rhinos.xml file. The HTML files shown were generated by transforming the tigers_rhinos.xml file with the given XSLT file, using Saxon.
Page | Section | Code |
---|---|---|
136-137 | Transforming XML with XSLT | Figure 10.1: tigers_rhinos.xml Figure 10.3: tigers_complete.xsl |
138 | Beginning an XSLT Style Sheet | begin.xsl |
139 | Creating the Root Template | root.xsl, root.xml |
140-141 | Outputting HTML Code | html.xsl, html.html |
142-143 | Outputting a Node's Content | node.xsl, node.html |
144-145 | Creating and Applying Template Rules | templates.xsl, templates.html |
146-147 | Batch-Processing Nodes | for-each.xsl, for-each.html |
148 | Processing Nodes Conditionally | if.xsl, if.html |
149 | Adding Additional Choices | choose.xsl, choose.html |
150 | Sorting Nodes Before Processing | sort.xsl, sort.html |
151 | Generating Attributes | attributes.xsl, attributes.html |
The files in this section are in the xpath folder. Note that many of the examples in this chapter use the same files as examples from the XSLT chapter. That's because we've already seen some of these patterns and expressions, but they are explained and highlighted here. Note also that the HTML files shown were generated by transforming the tigers_rhinos.xml file with the given XSLT file, using Saxon.
Page | Section | Code |
---|---|---|
154 | Determining the Current Node | same as sort.xsl, sort.html (from page 150 in Chapter 10) |
155 | Referring to the Current Node | same as sort.xsl, sort.html (from page 150 in Chapter 10) |
156 | Selecting a Node's Children | same as sort.xsl, sort.html (from page 150 in Chapter 10) |
157 | Selecting a Node's Parent or Siblings | siblings.xsl, siblings.html |
158 | Selecting All of the Descendants | descend.xsl, descend.html |
159 | Disregarding the Current Node | disregardnode.xsl, disregardnode.html |
160 | Selecting a Node's Attributes | same as siblings.xsl, siblings.html |
161 | Selecting Subsets | same as siblings.xsl, siblings.html |
The files in this section are in the expressions folder. Note that the first seven HTML files (pages 164-170) shown were generated by transforming the tigers_rhinos.xml file with the given XSLT file, using Saxon. The examples from pages 171-173 are generated by transforming the tigers_rhinos_noinitials.xml file with the given XSLT file, also using Saxon. Also note that up until page 169, for simplicity's sake, I did not include the picture template. It appears again from page 170 on. You can find more information about the picture template in the Generating Attributes section on page 151 in Chapter 10.
Page | Section | Code |
---|---|---|
164 | Comparing Two Values | same as choose.xsl, choose.html (from page 149, Chapter 10) |
165 | Testing the Position | position.xsl, position.html |
166 | Subtotaling Values | sum.xsl, sum.html |
167 | Counting Nodes | count.xsl, count.html |
168 | Multiplying, Dividing, Adding, Subtracting | multiply.xsl, multiply.html |
169 | Formatting Numbers | formatnumber.xsl, formatnumber.html |
170 | Rounding Numbers | ceiling.xsl, ceiling.html (again, notice that the picture template from page 151 is used here--for the first time in this chapter) |
171-172 | Extracting Substrings |
Figure 12.19: tigers_rhinos_noinitials.xml (All the other XSLT files refer to the tigers_rhinos.xml file.) Figures 12.20 and 12.21: substring.xsl, substring.html Figures 12.22 and 12.23: substring_after.xsl, substring_after.html |
173 | Capitalizing Strings | translate.xsl, translate.html |
Note that the examples in these chapters are almost all based on the panthers.xml and panthersblurb.xml files. I have created a separate xml file for each example that references the proper CSS stylesheet, but unless noted, all the XML files are otherwise identical. The CSS files build on each other gradually.
The files in this section are in the css folder.
Page | Section | Code |
---|---|---|
177 | Setting up CSS |
Figure 13.1: panthers.xml |
178 | CSS with XML vs. CSS with HTML | Figure 13.3: panthers.xml Figure 13.4: panthers.html |
180-181 | Specifying Where Styles Are To Be Applied |
Figure 13.6: where1.css Figure 13.7: where2.css |
182-183 | Creating an External Style Sheet | external.css |
184-185 | Calling a Style Sheet for an XML Document |
Figure 13.11: call_stylesheet.xml (end_species.css) Figure 13.12: call_stylesheet_xml.xsl is the document shown. It is used to transform panthers.xml into call_stylesheet_xml.xml which calls end_species.css for formatting information. |
186 | Calling a Style Sheet for an HTML Document | callstyles_html.xsl, (tigers_rhinos.xml, callstyles_html.html, callstyles.css) |
187 | Using Internal Style Sheets | callstyles_html_internal.xsl |
188 | Applying Styles Locally | local_styles.xsl (local_styles.html) |
The files in this section are in the css_layout folder. The XML files formatted by the CSS examples on pages 190-197 are identical to panthers.xml, except for the call to the individual stylesheet. The XML files used from pages 198-205 are identical to panthersblurb.xml--except for the call to the individual stylesheet--(which only differs from panthers.xml in the addition of an extra sidebar (blurb) paragraph.) Finally, the examples in the last two sections (pages 206-9) are identical to the pantherlist.xml file--again, except for the call to the individual stylesheet.
Page | Section | Code |
---|---|---|
190 | Defining Elements as Block-Level or Inline | |
191 | Hiding Elements Completely | hide.css (hide.xml) |
192 | Offsetting Elements In the Natural Flow | relative.css (relative.xml) |
193 | Positioning Elements Absolutely | absolute.css (absolute.xml) |
194 | Setting the Height or Width for an Element | heightwidth.css (heightwidth.xml) |
195 | Setting the Border | border.css (border.xml) |
196 | Adding Padding Around an Element | padding.css (padding.xml) |
197 | Setting the Margins around an Element | margin.css (margin.xml) |
198 | Wrapping Text around Elements | float.css (float.xml) |
199 | Stopping Text Wrap | clear.css (clear.xml) |
200 | Changing the Foreground Color | foreground.css (foreground.xml) |
201 | Changing the Background | background.css (background.xml) |
202 | Positioning Elements in 3D | zindex.css (zindex.xml) |
203 | Aligning Elements Vertically | verticalalign.css (verticalalign.xml) |
204 | Determining Where Overflow Should Go | overflow.css (overflow.xml) |
205 | Clipping an Element | clip.css (clip.xml) |
206-207 | Setting List Properties | lists.css (pantherlist.xml) |
208 | Specifying Page Breaks | pagebreak.css (pagebreak.xml) |
The files in this section are in the css_text folder. All of the XML files are identical to panthers_layout.xml, except for the call to the individual stylesheet. Indeed panthers_layout.xml is simply the same panthersblurb.xml file we saw in the last chapter with a call to the layout.css stylesheet which includes all the layout information we added in Chapter 14. Note also that you'll need the embedded font files for all the examples from page 211 on, and that the embedded fonts will only be visible in IE5 for Windows.
Page | Section | Code |
---|---|---|
210 | Choosing a Font Family | |
211 | Embedding Fonts on a Page | embedfonts.css (embedfonts.xml) |
212 | Creating Italics | italic.css (italic.xml) |
213 | Applying Bold Formatting | bold.css (bold.xml) |
214 | Setting the Font Size | font-size.css (font-size.xml) |
215 | Setting the Line Height | line-height.css (line-height.xml) |
216 | Setting All Font Values at Once | font.css (font.xml) |
217 | Setting the Text Color | color.css (color.xml) |
218 | Changing the TextÕs Background | background.css (background.xml) |
219 | Controlling Spacing | spacing.css (spacing.xml) |
220 | Aligning Text | text-align.css (text-align.xml) |
221 | Underlining Text | underline.css (underline.xml) |
222 | Changing the Text Case | transform.css (transform.xml) |
Since none of the examples in this chapter can really be tested yet (except for well-formedness, but that's pretty boring), I haven't taken the trouble of posting the code. If you really want a copy of it, just let me know. I'd be happy to give it to you (or post it, if a lot of you want it). Once browsers can deal with XLink and XPointer, I will make these examples more real and then post the code so you can see how they work for yourselves. Comments?
You can find these files in the xhtml folder.
Page | Section | Code |
---|---|---|
240 | How Does a Browser Know? | Figures A.1 and A.3: xhtml.xml Figure A.2:xhtml.html |
241 | Writing XHTML | xhtml.xml |
242 | Declaring a DTD for XHTM | xhtml_dtd.xml |
These are the most up-to-date links to the tools listed.
Page | Section | Code |
---|---|---|
244 | Validating XML Files against a DTD | Brown University's Scholarly Technology Group's XML Validator |
245 | Validating XML with a Schema | XML Schema Validator from the W3C |
246 | Transforming XML with an XSLT Processor |
Michael Kay's Saxon Hopefully, I'll have a link to a Macintosh-compatible XSLT processor soon! |
You can find links to these tables in the Extras section of my HTML4 Web site. Click on Useful Files to find the appropriate table.
You can find the complete index online!