| 1 |
<chapter id="ch-parse"> |
| 2 |
<?dbhtml filename="ch03.html"?> |
| 3 |
<chapterinfo> |
| 4 |
<pubdate>$Date$</pubdate> |
| 5 |
<releaseinfo>$Revision$</releaseinfo> |
| 6 |
</chapterinfo> |
| 7 |
<title>Parsing DocBook Documents</title> |
| 8 |
<para> |
| 9 |
<indexterm id="parsDocch4" class="startofrange"><primary>parsing</primary> |
| 10 |
<secondary>DocBook documents</secondary></indexterm> |
| 11 |
<indexterm id="docDTDparsch4" class="startofrange"><primary>DocBook DTD</primary> |
| 12 |
<secondary>parsing documents</secondary></indexterm> |
| 13 |
|
| 14 |
A key feature of &SGML; and &XML; markup is that you |
| 15 |
<emphasis>validate</emphasis> it. The DocBook &DTD; is a precise description |
| 16 |
of valid nesting, the order of elements, and their content. All |
| 17 |
DocBook documents must conform to this description or they are not |
| 18 |
DocBook documents (by definition). |
| 19 |
</para> |
| 20 |
<para> |
| 21 |
<indexterm><primary>parsers</primary> |
| 22 |
<secondary>validating</secondary></indexterm> |
| 23 |
<indexterm><primary>validation</primary> |
| 24 |
<secondary>parsers</secondary></indexterm> |
| 25 |
|
| 26 |
A <firstterm>validating parser</firstterm> is a program that can read |
| 27 |
the &DTD; and a particular document and determine whether the exact |
| 28 |
nesting and order of elements in the document is valid according to |
| 29 |
the &DTD;. |
| 30 |
</para> |
| 31 |
<para> |
| 32 |
<indexterm><primary>text editors</primary> |
| 33 |
<secondary>unstructured, parsing and</secondary></indexterm> |
| 34 |
|
| 35 |
If you are not using a structured editor that can enforce the markup |
| 36 |
as you type, validation with an external parser is a particularly |
| 37 |
important step in the document creation process. You cannot expect |
| 38 |
to get rational results from subsequent processing (such as document |
| 39 |
publishing) if your documents are not valid. |
| 40 |
</para> |
| 41 |
<para> |
| 42 |
<indexterm><primary>SP nsgmls parser</primary><see>nsgmls parser</see></indexterm> |
| 43 |
The most popular free &SGML; parser is <acronym>SP</acronym> by James Clark, |
| 44 |
available at <ulink url="http://www.jclark.com/">http://www.jclark.com/</ulink>. |
| 45 |
</para> |
| 46 |
<para> |
| 47 |
<indexterm><primary>nsgmls parser</primary></indexterm> |
| 48 |
<indexterm><primary>parsers</primary> |
| 49 |
<secondary>free</secondary></indexterm> |
| 50 |
<indexterm><primary>XML</primary> |
| 51 |
<secondary>parsers, free</secondary></indexterm> |
| 52 |
<indexterm><primary>xp parser</primary></indexterm> |
| 53 |
|
| 54 |
<acronym>SP</acronym> includes <command>nsgmls</command>, a fast command-line |
| 55 |
parser. In the world of free validating &XML; parsers, |
| 56 |
James |
| 57 |
Clark's <command>xp</command> is a popular choice. |
| 58 |
</para> |
| 59 |
<note> |
| 60 |
<para> |
| 61 |
<indexterm><primary>parsers</primary> |
| 62 |
<secondary>non-validating</secondary></indexterm> |
| 63 |
|
| 64 |
Not all &XML; parsers are validating, and although a |
| 65 |
non-validating parser may have many uses, it cannot ensure that your |
| 66 |
documents are valid according to the &DTD;.</para> |
| 67 |
</note> |
| 68 |
<sect1 id="ch03-validate"><title>Validating Your Documents</title> |
| 69 |
<para> |
| 70 |
The exact way in which the parser is executed varies according to |
| 71 |
the parser in use, naturally. For information about your particular |
| 72 |
parser, consult the documentation that came with it. |
| 73 |
</para> |
| 74 |
|
| 75 |
<sect2><title>Using nsgmls</title> |
| 76 |
<para> |
| 77 |
<indexterm><primary>nsgmls parser</primary> |
| 78 |
<secondary>SGML documents, validating</secondary></indexterm> |
| 79 |
|
| 80 |
The <command>nsgmls</command> command from <acronym>SP</acronym> is a |
| 81 |
validating &SGML; parser. The options used in the example below |
| 82 |
suppress the normal output (<option>-s</option>), except for error messages, |
| 83 |
print the version number (<option>-v</option>), and specify the catalog file |
| 84 |
that should be used to map public identifiers to system |
| 85 |
identifiers. Printing the version number guarantees that you always |
| 86 |
get <emphasis>some</emphasis> output, so that you know the command ran |
| 87 |
successfully: |
| 88 |
</para> |
| 89 |
<screen> |
| 90 |
[n:\dbtdg] nsgmls -sv -c \share\sgml\catalog test.sgm |
| 91 |
m:\jade\nsgmls.exe:I: SP version "1.3.2" |
| 92 |
</screen> |
| 93 |
<para> |
| 94 |
<indexterm><primary>error messages</primary> |
| 95 |
<secondary>nsgmls parser</secondary></indexterm> |
| 96 |
<indexterm><primary>options</primary> |
| 97 |
<secondary>error messages (parser), directing to file</secondary></indexterm> |
| 98 |
|
| 99 |
Because no error messages were printed, we know our document is valid. |
| 100 |
If you're working with a document that you discover has many errors, |
| 101 |
the <option>-f</option> option offers a handy way to direct the errors to a file |
| 102 |
so they don't all scroll off your screen. |
| 103 |
</para> |
| 104 |
<para> |
| 105 |
<indexterm><primary>nsgmls parser</primary> |
| 106 |
<secondary>XML documents, validating</secondary></indexterm> |
| 107 |
<indexterm><primary>declarations</primary> |
| 108 |
<secondary>nsgmls parser</secondary></indexterm> |
| 109 |
<indexterm><primary>xml.dcl declaration (nsgmls parser)</primary></indexterm> |
| 110 |
<indexterm><primary>XML</primary> |
| 111 |
<secondary>nsgmls parser</secondary></indexterm> |
| 112 |
|
| 113 |
If you want to validate an &XML; document with <acronym>SP</acronym>, |
| 114 |
you must make sure that <acronym>SP</acronym> uses the correct |
| 115 |
declaration. An &XML; declaration called <filename>xml.dcl</filename> is |
| 116 |
included with <acronym>SP</acronym>. |
| 117 |
</para> |
| 118 |
|
| 119 |
<para> |
| 120 |
The easiest way to make sure that <acronym>SP</acronym> uses <filename>xml.dcl</filename> is to |
| 121 |
include the declaration explicitly on the command line when you run |
| 122 |
<command>nsgmls</command> (or Jade, or other <acronym>SP</acronym> tools): |
| 123 |
</para> |
| 124 |
<screen> |
| 125 |
[n:\dbtdg] nsgmls -sv -c \share\sgml\catalog m:\jade\xml.dcl test.xml |
| 126 |
m:\jade\nsgmls.exe:I: SP version "1.3.2" |
| 127 |
</screen> |
| 128 |
</sect2> |
| 129 |
|
| 130 |
<sect2><title>Using xp</title> |
| 131 |
<para> |
| 132 |
<indexterm><primary>xp parser</primary></indexterm> |
| 133 |
<indexterm><primary>Time program (xp parser)</primary></indexterm> |
| 134 |
|
| 135 |
The <application>xp</application> distribution includes several sample programs. |
| 136 |
One of these programs, <command>Time</command>, performs a validating parse |
| 137 |
of the document and prints the amount of time required to parse the |
| 138 |
&DTD; and the document. This program makes an excellent validity |
| 139 |
checker: |
| 140 |
</para> |
| 141 |
<screen> |
| 142 |
java com.jclark.xml.apps.Time examples\simple.xml |
| 143 |
6.639 |
| 144 |
</screen> |
| 145 |
<para> |
| 146 |
The result states that it took 6.639 seconds to parse the &DTD; and |
| 147 |
the document. This indicates that the document is valid. If the |
| 148 |
document is invalid, additional error messages are displayed. |
| 149 |
</para> |
| 150 |
</sect2> |
| 151 |
</sect1> |
| 152 |
<sect1 id="ch03-parseerr"><title>Understanding Parse Errors</title> |
| 153 |
<para> |
| 154 |
<indexterm id="errorparsech4" class="startofrange"><primary>errors</primary> |
| 155 |
<secondary>parsing</secondary></indexterm> |
| 156 |
|
| 157 |
<indexterm><primary>parsing</primary> |
| 158 |
<secondary>errors</secondary></indexterm> |
| 159 |
<indexterm><primary>error messages</primary> |
| 160 |
<secondary>parsers</secondary></indexterm> |
| 161 |
|
| 162 |
Every parser produces slightly different error messages, but most |
| 163 |
indicate exactly (at least technically)<footnote> |
| 164 |
<para> |
| 165 |
It is often the case that you can correct an error in the document in |
| 166 |
several ways. The parser suggests one possible fix, but this is not |
| 167 |
always the right fix. For example, the parser may suggest that you |
| 168 |
can correct out of context data by adding another element, when in |
| 169 |
fact it's “obvious” to human eyes that the problem is a |
| 170 |
missing end tag. |
| 171 |
</para> |
| 172 |
</footnote> what is wrong and where the error occurred. With a little |
| 173 |
experience, this information is all you'll need to quickly identify |
| 174 |
what's wrong. |
| 175 |
</para> |
| 176 |
<para> |
| 177 |
|
| 178 |
<indexterm><primary>Jade</primary> |
| 179 |
<secondary>SP parser, using</secondary></indexterm> |
| 180 |
|
| 181 |
In the rest of this section, we'll look at a number of common errors |
| 182 |
and the messages they produce in <acronym>SP</acronym>. We've |
| 183 |
chosen <acronym>SP</acronym> for the rest of these examples because |
| 184 |
that is the same parser used by Jade, which we'll be discussing |
| 185 |
further in <xref linkend="ch-publish"/>. |
| 186 |
</para> |
| 187 |
<sect2><title>&DTD; Cannot Be Found</title> |
| 188 |
<para> |
| 189 |
<indexterm><primary>cannot be found errors</primary></indexterm> |
| 190 |
<indexterm><primary>DTDs</primary> |
| 191 |
<secondary>cannot be found errors</secondary></indexterm> |
| 192 |
<indexterm><primary>public identifiers</primary> |
| 193 |
<secondary>errors</secondary></indexterm> |
| 194 |
|
| 195 |
The telltale sign that SP could not find the &DTD;, or some module of |
| 196 |
the &DTD;, is the error message: "cannot generate system identifier |
| 197 |
for public text …". Generally, the errors that occur after |
| 198 |
this are spurious; if SP couldn't find some part of the &DTD;, |
| 199 |
it's likely to think that <emphasis>everything</emphasis> is wrong. |
| 200 |
</para> |
| 201 |
<para> |
| 202 |
Careful examination of the following document will show that we've |
| 203 |
introduced a simple typographic error into the public identifier (the |
| 204 |
word <quote>DocBook</quote> is misspelled with a lowercase <quote>b</quote>): |
| 205 |
</para> |
| 206 |
<programlisting> |
| 207 |
<inlinegraphic format="linespecific" fileref="examples/errs/nodtd.sgm"/> |
| 208 |
</programlisting> |
| 209 |
<para> |
| 210 |
SP responds dramatically to this error: |
| 211 |
</para> |
| 212 |
<screen> |
| 213 |
hermes:/documents/books/tdg/examples/errs$ nsgmls -sv -c cat1 /usr/lib/sgml/declaration/xml.dcl nodtd.sgm |
| 214 |
nsgmls:I: SP version "1.3.4" |
| 215 |
nsgmls:nodtd.sgm:2:76:E: could not resolve host "www.oasis-open.org" (try again later) |
| 216 |
nsgmls:nodtd.sgm:2:76:E: DTD did not contain element declaration for document type name |
| 217 |
nsgmls:nodtd.sgm:3:8:E: element "chapter" undefined |
| 218 |
nsgmls:nodtd.sgm:3:15:E: element "title" undefined |
| 219 |
nsgmls:nodtd.sgm:4:5:E: element "para" undefined |
| 220 |
nsgmls:nodtd.sgm:10:5:E: element "para" undefined |
| 221 |
nsgmls:nodtd.sgm:11:15:E: there is no attribute "role" |
| 222 |
nsgmls:nodtd.sgm:11:21:E: element "emphasis" undefined |
| 223 |
nsgmls:nodtd.sgm:12:9:E: element "emphasis" undefined |
| 224 |
nsgmls:nodtd.sgm:12:24:E: element "emphasis" undefined |
| 225 |
nsgmls:nodtd.sgm:13:18:E: element "superscript" undefined |
| 226 |
nsgmls:nodtd.sgm:14:16:E: element "subscript" undefined |
| 227 |
nsgmls:nodtd.sgm:16:5:E: element "para" undefined |
| 228 |
</screen> |
| 229 |
<para> |
| 230 |
<indexterm><primary>catalog files</primary> |
| 231 |
<secondary>errors</secondary></indexterm> |
| 232 |
|
| 233 |
Other things to look for, if you haven't misspelled the public |
| 234 |
identifier, are typos in the catalog or failure to specify a catalog |
| 235 |
that resolves the public identifier that can't be found. |
| 236 |
</para> |
| 237 |
</sect2> |
| 238 |
<sect2><title><acronym>ISO</acronym> Entity Set Missing</title> |
| 239 |
<para> |
| 240 |
|
| 241 |
<indexterm><primary>entity sets</primary> |
| 242 |
<secondary>missing</secondary></indexterm> |
| 243 |
|
| 244 |
A missing entity set is another example of either a misspelled public |
| 245 |
identifier, or a missing catalog or catalog entry. |
| 246 |
</para> |
| 247 |
<para> |
| 248 |
In this case, there's nothing wrong with the document, but the catalog |
| 249 |
that's been specified is missing the public identifiers for the |
| 250 |
<acronym>ISO</acronym> entity sets: |
| 251 |
</para> |
| 252 |
<screen> |
| 253 |
[n:\dbtdg]nsgmls -sv -c examples\errs\cat2 examples\simple.sgm |
| 254 |
m:\jade\nsgmls.exe:I: SP version "1.3.2" |
| 255 |
m:\jade\nsgmls.exe:n:/share/sgml/docbook/3.1/dbcent.mod:53:65:W: cannot generate system identifier for public text "ISO 8879:1986//ENTITIES Added Math Symbols:Arrow Relations//EN" |
| 256 |
m:\jade\nsgmls.exe:n:/share/sgml/docbook/3.1/dbcent.mod:54:8:E: reference to entity "ISOamsa" for which no system identifier could be generated |
| 257 |
m:\jade\nsgmls.exe:n:/share/sgml/docbook/3.1/dbcent.mod:52:0: entity was defined here |
| 258 |
m:\jade\nsgmls.exe:n:/share/sgml/docbook/3.1/dbcent.mod:60:66:W: cannot generate system identifier for public text "ISO 8879:1986//ENTITIES Added Math Symbols:Binary Operators//EN" |
| 259 |
m:\jade\nsgmls.exe:n:/share/sgml/docbook/3.1/dbcent.mod:61:8:E: reference to entity "ISOamsb" for which no system identifier could be generated |
| 260 |
m:\jade\nsgmls.exe:n:/share/sgml/docbook/3.1/dbcent.mod:59:0: entity was defined here |
| 261 |
m:\jade\nsgmls.exe:n:/share/sgml/docbook/3.1/dbcent.mod:67:60:W: cannot generate system identifier for public text "ISO 8879:1986//ENTITIES Added Math Symbols:Delimiters//EN" |
| 262 |
m:\jade\nsgmls.exe:n:/share/sgml/docbook/3.1/dbcent.mod:68:8:E: reference to entity "ISOamsc" for which no system identifier could be generated |
| 263 |
m:\jade\nsgmls.exe:n:/share/sgml/docbook/3.1/dbcent.mod:66:0: entity was defined here |
| 264 |
m:\jade\nsgmls.exe:n:/share/sgml/docbook/3.1/dbcent.mod:74:67:W: cannot generate system identifier for public text "ISO 8879:1986//ENTITIES Added Math Symbols:Negated Relations//EN" |
| 265 |
... |
| 266 |
</screen> |
| 267 |
<para> |
| 268 |
<indexterm><primary>entity sets</primary> |
| 269 |
<secondary>locating</secondary></indexterm> |
| 270 |
|
| 271 |
The <acronym>ISO</acronym> entity sets are required by the DocBook |
| 272 |
&DTD;, but they are not distributed with it. That's because they |
| 273 |
aren't maintained by <acronym>OASIS</acronym>.<footnote> |
| 274 |
<para> |
| 275 |
If you need to locate the entity sets, consult <ulink url="http://www.oasis-open.org/cover/topics.html#entities">http://www.oasis-open.org/cover/topics.html#entities</ulink>. |
| 276 |
</para> |
| 277 |
</footnote> |
| 278 |
</para> |
| 279 |
</sect2> |
| 280 |
<sect2><title>Character Data Not Allowed Here</title> |
| 281 |
<para> |
| 282 |
<indexterm><primary>error messages</primary> |
| 283 |
<secondary>character data out of context</secondary></indexterm> |
| 284 |
<indexterm><primary>characters</primary> |
| 285 |
<secondary>errors (out of context)</secondary></indexterm> |
| 286 |
<indexterm><primary>start tags</primary> |
| 287 |
<secondary>errors</secondary></indexterm> |
| 288 |
|
| 289 |
Out of context character data is frequently caused by a missing start |
| 290 |
tag, but sometimes it's just the result of typing in the wrong place! |
| 291 |
</para> |
| 292 |
<programlisting> |
| 293 |
<inlinegraphic format="linespecific" fileref="examples/errs/badpcdata.sgm"/> |
| 294 |
</programlisting> |
| 295 |
<screen> |
| 296 |
[n:\dbtdg] nsgmls -sv -c \share\sgml\catalog examples\errs\badpcdata.sgm |
| 297 |
m:\jade\nsgmls.exe:I: SP version "1.3.2" |
| 298 |
m:\jade\nsgmls.exe:examples\errs\badpcdata.sgm:9:0:E: character data is not allowed here |
| 299 |
</screen> |
| 300 |
<para> |
| 301 |
<indexterm><primary>Chapter element</primary> |
| 302 |
<secondary>errors, character data</secondary></indexterm> |
| 303 |
|
| 304 |
<sgmltag>Chapter</sgmltag>s aren't allowed to contain character data |
| 305 |
directly. Here, a wrapper element, such as <sgmltag>Para</sgmltag>, is |
| 306 |
missing around the sentence between the first two paragraphs. |
| 307 |
</para> |
| 308 |
</sect2> |
| 309 |
<sect2><title>Misspelled Start Tag</title> |
| 310 |
<para> |
| 311 |
<indexterm><primary>start tags</primary> |
| 312 |
<secondary>errors</secondary> |
| 313 |
<tertiary>misspelling</tertiary></indexterm> |
| 314 |
|
| 315 |
If you spell it wrong, the parser gets confused. |
| 316 |
</para> |
| 317 |
<programlisting> |
| 318 |
<inlinegraphic format="linespecific" fileref="examples/errs/misspell.sgm"/> |
| 319 |
</programlisting> |
| 320 |
<screen> |
| 321 |
[n:\documents\books\dbtdg]nsgmls -sv -c \share\sgml\catalog examples\errs\misspe |
| 322 |
ll.sgm |
| 323 |
m:\jade\nsgmls.exe:I: SP version "1.3.2" |
| 324 |
m:\jade\nsgmls.exe:examples\errs\misspell.sgm:9:5:E: element "PAAR" undefined |
| 325 |
m:\jade\nsgmls.exe:examples\errs\misspell.sgm:14:6:E: end tag for element "PARA" which is not open |
| 326 |
m:\jade\nsgmls.exe:examples\errs\misspell.sgm:21:9:E: end tag for "PAAR" omitted, but OMITTAG NO was specified |
| 327 |
m:\jade\nsgmls.exe:examples\errs\misspell.sgm:9:0: start tag was here |
| 328 |
</screen> |
| 329 |
<para> |
| 330 |
Luckily, these are pretty easy to spot, unless you accidentally spell |
| 331 |
the name of another element. In that case, your error might appear to |
| 332 |
be out of context. |
| 333 |
</para> |
| 334 |
</sect2> |
| 335 |
<sect2><title>Misspelled End Tag</title> |
| 336 |
<para> |
| 337 |
<indexterm><primary>end tags</primary> |
| 338 |
<secondary>errors, misspelling</secondary></indexterm> |
| 339 |
|
| 340 |
Spelling the end tag wrong is just as confusing. |
| 341 |
</para> |
| 342 |
<programlisting> |
| 343 |
<inlinegraphic format="linespecific" fileref="examples/errs/misspell2.sgm"/> |
| 344 |
</programlisting> |
| 345 |
<screen> |
| 346 |
[n:\dbtdg]nsgmls -sv -c \share\sgml\catalog examples\errs\misspell2.sgm |
| 347 |
m:\jade\nsgmls.exe:I: SP version "1.3.2" |
| 348 |
m:\jade\nsgmls.exe:examples\errs\misspell2.sgm:2:35:E: end tag for element "TITEL" which is not open |
| 349 |
m:\jade\nsgmls.exe:examples\errs\misspell2.sgm:3:5:E: document type does not allow element "PARA" here; missing one of "FOOTNOTE", "MSGTEXT" start-tag |
| 350 |
m:\jade\nsgmls.exe:examples\errs\misspell2.sgm:9:5:E: document type does not allow element "PARA" here; missing one of "FOOTNOTE", "MSGTEXT" start-tag |
| 351 |
m:\jade\nsgmls.exe:examples\errs\misspell2.sgm:15:5:E: document type does not allow element "PARA" here; missing one of "FOOTNOTE", "MSGTEXT" start-tag |
| 352 |
m:\jade\nsgmls.exe:examples\errs\misspell2.sgm:21:9:E: end tag for "TITLE" omitted, but OMITTAG NO was specified |
| 353 |
m:\jade\nsgmls.exe:examples\errs\misspell2.sgm:2:9: start tag was here |
| 354 |
m:\jade\nsgmls.exe:examples\errs\misspell2.sgm:21:9:E: end tag for "CHAPTER" which is not finished |
| 355 |
</screen> |
| 356 |
<para> |
| 357 |
These are pretty easy to spot as well, but look at how confused the |
| 358 |
parser became. From the parser's point of view, failure to close the |
| 359 |
open <sgmltag>Title</sgmltag> element means that all the following elements |
| 360 |
appear out of context. |
| 361 |
</para> |
| 362 |
</sect2> |
| 363 |
<sect2><title>Out of Context Start Tag</title> |
| 364 |
<para> |
| 365 |
<indexterm><primary>start tags</primary> |
| 366 |
<secondary>errors</secondary> |
| 367 |
<tertiary>out of context</tertiary></indexterm> |
| 368 |
<indexterm><primary>tags</primary> |
| 369 |
<secondary>context errors</secondary></indexterm> |
| 370 |
|
| 371 |
Sometimes the problem isn't spelling, but placing a tag in the wrong |
| 372 |
context. When this happens, the parser tries to figure out what it |
| 373 |
can add to your document to make it valid. Then it proceeds as if it |
| 374 |
had seen what was added in order to recover from the error seen, which |
| 375 |
can cause future errors. |
| 376 |
</para> |
| 377 |
<programlisting> |
| 378 |
<inlinegraphic format="linespecific" fileref="examples/errs/badstarttag.sgm"/> |
| 379 |
</programlisting> |
| 380 |
<screen> |
| 381 |
[n:\dbtdg]nsgmls -sv -c \share\sgml\catalog examples\errs\badstarttag.sgm |
| 382 |
m:\jade\nsgmls.exe:I: SP version "1.3.2" |
| 383 |
m:\jade\nsgmls.exe:examples\errs\badstarttag.sgm:9:12:E: document type does not allow element "TITLE" here; missing one of "CALLOUTLIST", "SEGMENTEDLIST", "VARIABLELIST", "CAUTION", "IMPORTANT", "NOTE", "TIP", "WARNING", "BLOCKQUOTE", "EQUATION", "EXAMPLE", "FIGURE", "TABLE" start-tag |
| 384 |
</screen> |
| 385 |
<para> |
| 386 |
<indexterm><primary>titles</primary> |
| 387 |
<secondary>formal elements</secondary> |
| 388 |
<tertiary>errors</tertiary></indexterm> |
| 389 |
<indexterm><primary>paragraphs</primary> |
| 390 |
<secondary>titles</secondary></indexterm> |
| 391 |
|
| 392 |
In this example, we probably wanted a <sgmltag>FormalPara</sgmltag>, so that |
| 393 |
we could have a title on the paragraph. But note that the parser |
| 394 |
didn't suggest this alternative. The parser only tries to add |
| 395 |
additional elements, rather than rename elements that it's already |
| 396 |
seen. |
| 397 |
</para> |
| 398 |
</sect2> |
| 399 |
<sect2><title>Missing End Tag</title> |
| 400 |
<para> |
| 401 |
<indexterm><primary>end tags</primary> |
| 402 |
<secondary>missing, errors</secondary></indexterm> |
| 403 |
|
| 404 |
Leaving out an end tag is a lot like an out of context start tag. In |
| 405 |
fact, they're really the same error. The problem is never caused by |
| 406 |
the missing end tag per se, rather it's caused by the fact that |
| 407 |
something following it is now out of context. |
| 408 |
</para> |
| 409 |
<programlisting> |
| 410 |
<inlinegraphic format="linespecific" fileref="examples/errs/noendtag.sgm"/> |
| 411 |
</programlisting> |
| 412 |
<screen> |
| 413 |
[n:\dbtdg]nsgmls -sv -c \share\sgml\catalog examples\errs\noendtag.sgm |
| 414 |
m:\jade\nsgmls.exe:I: SP version "1.3.2" |
| 415 |
m:\jade\nsgmls.exe:examples\errs\noendtag.sgm:14:5:E: document type does not allow element "PARA" here; missing one of "FOOTNOTE", "MSGTEXT", "CAUTION", "IMPORTANT", "NOTE", "TIP", "WARNING", "BLOCKQUOTE", "INFORMALEXAMPLE" start-tag |
| 416 |
m:\jade\nsgmls.exe:examples\errs\noendtag.sgm:20:9:E: end tag for "PARA" omitted, but OMITTAG NO was specified |
| 417 |
m:\jade\nsgmls.exe:examples\errs\noendtag.sgm:9:0: start tag was here |
| 418 |
</screen> |
| 419 |
<para> |
| 420 |
In this case, the parser figured out that the best thing it could do |
| 421 |
is end the paragraph. |
| 422 |
</para> |
| 423 |
</sect2> |
| 424 |
<sect2><title>Bad Entity Reference</title> |
| 425 |
<para> |
| 426 |
<indexterm><primary>entities</primary> |
| 427 |
<secondary>errors, spelling</secondary></indexterm> |
| 428 |
|
| 429 |
If you spell an entity name wrong, the parser will catch it. |
| 430 |
</para> |
| 431 |
<programlisting> |
| 432 |
<inlinegraphic format="linespecific" fileref="examples/errs/badent.sgm"/> |
| 433 |
</programlisting> |
| 434 |
<screen> |
| 435 |
[n:\dbtdg]nsgmls -sv -c \share\sgml\catalog examples\errs\badent.sgm |
| 436 |
m:\jade\nsgmls.exe:I: SP version "1.3.2" |
| 437 |
m:\jade\nsgmls.exe:examples\errs\badent.sgm:10:26:E: general entity "xyzzy" not defined and no default entity |
| 438 |
</screen> |
| 439 |
<para> |
| 440 |
More often than not, you'll see this when you misspell a character |
| 441 |
entity name. For example, this happens when you type |
| 442 |
<literal>&ldqou;</literal> instead of |
| 443 |
<literal>&ldquo;</literal>. |
| 444 |
</para> |
| 445 |
</sect2> |
| 446 |
<sect2><title>Invalid 8-Bit Character</title> |
| 447 |
<para> |
| 448 |
<indexterm><primary>characters</primary> |
| 449 |
<secondary>character sets</secondary> |
| 450 |
<tertiary>Unicode character set (SGML errors)</tertiary></indexterm> |
| 451 |
<indexterm><primary>8-bit characters, errors (SGML)</primary></indexterm> |
| 452 |
<indexterm><primary>errors</primary> |
| 453 |
<secondary>8-bit characters (SGML)</secondary></indexterm> |
| 454 |
|
| 455 |
In &XML;, the entire range of Unicode characters is available to you, |
| 456 |
but in &SGML;, the declaration indicates what characters are valid. |
| 457 |
The distributed DocBook declaration doesn't allow a bunch of fairly |
| 458 |
common 8-bit characters. |
| 459 |
</para> |
| 460 |
<programlisting> |
| 461 |
<inlinegraphic format="linespecific" fileref="examples/errs/badchar.sgm"/> |
| 462 |
</programlisting> |
| 463 |
<screen> |
| 464 |
[n:\dbtdg]nsgmls -sv -c \share\sgml\catalog examples\errs\badchar.sgm |
| 465 |
m:\jade\nsgmls.exe:I: SP version "1.3.2" |
| 466 |
m:\jade\nsgmls.exe:examples\errs\badchar.sgm:11:0:E: non SGML character number 147 |
| 467 |
m:\jade\nsgmls.exe:examples\errs\badchar.sgm:11:5:E: non SGML character number 148 |
| 468 |
</screen> |
| 469 |
<para> |
| 470 |
<indexterm><primary>declarations</primary> |
| 471 |
<secondary>character sets, errors</secondary></indexterm> |
| 472 |
<indexterm><primary>entities</primary> |
| 473 |
<secondary>characters</secondary> |
| 474 |
<tertiary>errors</tertiary></indexterm> |
| 475 |
|
| 476 |
In this example, the Windows code page values for |
| 477 |
curly left and right quotes have been used, but they aren't in the |
| 478 |
declared character set. Fix this by converting them to character |
| 479 |
entities. |
| 480 |
</para> |
| 481 |
<para> |
| 482 |
<indexterm><primary>interchange partners</primary></indexterm> |
| 483 |
|
| 484 |
You can also fix them by changing the declaration, but if you do that, |
| 485 |
make sure all your interchange partners are aware of, and have a copy of, |
| 486 |
the modified declaration. See <xref linkend="app-interchange"/>. |
| 487 |
<indexterm startref="errorparsech4" class="endofrange"/> |
| 488 |
<indexterm startref="parsDocch4" class="endofrange"/> |
| 489 |
<indexterm startref="docDTDparsch4" class="endofrange"/> |
| 490 |
</para> |
| 491 |
</sect2> |
| 492 |
</sect1> |
| 493 |
|
| 494 |
<sect1 id="ch03-otherschema"><title>Considering Other Schema Languages</title> |
| 495 |
|
| 496 |
<para>Historically, &DTD;s were the only way to describe the valid |
| 497 |
stricture of SGML and XML documents, but that is no longer the case. |
| 498 |
At the time of this writing (January, 2001), DocBook is experimentally |
| 499 |
available in three other schema languages:</para> |
| 500 |
|
| 501 |
<variablelist> |
| 502 |
<varlistentry> |
| 503 |
<term><ulink url="http://www.w3.org/XML/Schema">XML Schema</ulink></term> |
| 504 |
<listitem> |
| 505 |
<para>The schema language being defined by the |
| 506 |
<ulink url="http://www.w3.org/">W3C</ulink> as the successor to &DTD;s |
| 507 |
for describing the structure of &XML;. XML Schema are likely to become |
| 508 |
a <ulink url="http://www.w3.org/">W3C</ulink> Recommendation in 2001. |
| 509 |
</para></listitem> |
| 510 |
</varlistentry> |
| 511 |
<varlistentry> |
| 512 |
<term><ulink url="http://www.xml.gr.jp/relax/">RELAX</ulink></term> |
| 513 |
<listitem> |
| 514 |
<para>RELAX, the Regular Language description for XML) is a less |
| 515 |
complex alternative to XML Schemas. The RELAX Core module is defined by |
| 516 |
ISO in <citetitle>ISO/IEC DTR 22250-1, Document Description and |
| 517 |
Processing Languages -- Regular Language Description for XML (RELAX) |
| 518 |
-- Part 1: RELAX Core, 2000</citetitle>. The RELAX Namespaces module |
| 519 |
is currently under development. |
| 520 |
</para> |
| 521 |
</listitem> |
| 522 |
</varlistentry> |
| 523 |
<varlistentry> |
| 524 |
<term><ulink url="http://www.thaiopensource.com/trex/">TREX</ulink></term> |
| 525 |
<listitem> |
| 526 |
<para>TREX, Tree Regular Expressions for XML, is another less complex |
| 527 |
alternative to XML Schemas. It is concise, powerful, and datatype |
| 528 |
neutral.</para> |
| 529 |
</listitem> |
| 530 |
</varlistentry> |
| 531 |
</variablelist> |
| 532 |
|
| 533 |
<sect2><title>Parsing and Validation</title> |
| 534 |
|
| 535 |
<para>Before we look closer at these new schema languages, there's one |
| 536 |
significant difference between &DTD;s and all of them that we should |
| 537 |
get out of the way: &XML; parsers (which may understand &DTD;s) build an |
| 538 |
&XML; information set out of a stream of characters, all of these other |
| 539 |
schema languages begin with an information set and perform validation |
| 540 |
on it.</para> |
| 541 |
|
| 542 |
<para>What I mean by that is that an &XML; parser reads a stream of |
| 543 |
bytes: |
| 544 |
|
| 545 |
<screen>"<" "?" "x" "m" "l" " " "v" "e" ... |
| 546 |
"<" "!" "D" "O" "C" "T" "Y" "P" "E" " " "b" "o" "o" "k" ... |
| 547 |
"<" "b" "o" "o" "k" " " "i" "d" "=" "'" "f" "o" "o" "'" ">" |
| 548 |
... |
| 549 |
"<" "/" "b" "o" "o" "k" ">"</screen> |
| 550 |
|
| 551 |
interprets them as a stream of characters (which may change the |
| 552 |
interpretation of some sequences of bytes) and constructs some |
| 553 |
representation of the &XML; document. This representation is the set |
| 554 |
of all the &XML; information items encountered: the information |
| 555 |
set of the document. The <ulink url="http://www.w3.org/">W3C</ulink> |
| 556 |
<ulink url="http://www.w3.org/XML/">XML Core Working Group</ulink> |
| 557 |
is in the process of defining what an |
| 558 |
<ulink url="http://www.w3.org/TR/xml-infoset">&XML; Information Set</ulink> |
| 559 |
contains.</para> |
| 560 |
|
| 561 |
<para>The other schema languages are defined not in terms of the sequence |
| 562 |
of characters in the file but in terms of the information set of the |
| 563 |
&XML; document. They have to work this way because the |
| 564 |
<ulink url="http://www.w3.org/TR/REC-xml">&XML; Recommendation</ulink> |
| 565 |
says what an &XML; document is and they all want to work on top of |
| 566 |
&XML;.</para> |
| 567 |
|
| 568 |
<para>So what, you might ask? Well, it turns out that this has at least |
| 569 |
one very significant implication: there's no way for these languages to |
| 570 |
provide support for entity declarations.</para> |
| 571 |
|
| 572 |
<para>An entity, like <quote><literal>&ora;</literal></quote> |
| 573 |
as a shortcut for <quote>O'Reilly & Associates</quote> or |
| 574 |
<quote><literal>&eacute;</literal></quote> as a mnemonic for |
| 575 |
<quote>é</quote>, is a feature of the character stream seen by |
| 576 |
the &XML; parser, it doesn't exist in the information set of valid |
| 577 |
&XML; documents. More importantly, this means that even if the schema |
| 578 |
language had a syntax for declaring entities, it wouldn't help the &XML; |
| 579 |
parser that needs to know the definitions long before the schema language |
| 580 |
processor comes into play.</para> |
| 581 |
|
| 582 |
<para>There are a couple of other &XML; features that are impacted, |
| 583 |
though not necessarily as significantly: notations and default |
| 584 |
attribute values. One use for notations is on external entity |
| 585 |
declarations, and as we've already seen, the schema language is too |
| 586 |
late to be useful for anything entity related. Default attribute values |
| 587 |
are also problematic since you would like them to be in the information |
| 588 |
set produced by the parser so that the schema language sees them.</para> |
| 589 |
|
| 590 |
</sect2> |
| 591 |
|
| 592 |
<sect2><title>A Coarse Comparison of Three &XML; Schema Languages</title> |
| 593 |
|
| 594 |
<para>FIXME: write a short synopsis of how these languages compare.</para> |
| 595 |
|
| 596 |
</sect2> |
| 597 |
|
| 598 |
</sect1> |
| 599 |
</chapter> |
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|