Debian Codegraph @

ru/ch03.xml

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