Register for EarthWeb's Million Dollar Sweepstakes!
home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Platinum Edition Using HTML 4, XML, and Java 1.2
(Publisher: Macmillan Computer Publishing)
Author(s): Eric Ladd
ISBN: 078971759x
Publication Date: 11/01/98

Bookmark It

Search this book:
 
Previous Table of Contents Next


The problem has to do with this line:

<!ATTLIST title keyword CDATA>

This declares the attributes for the title element—in this case, title just has the attribute keyword.

Recall that when you specify an attribute, you need to provide the following information:

  The name of the attribute
  The type of the attribute
  A default

These are all separated by a space. In this case, you have defined:

  The name (keyword)
  The type (CDATA)
  No default

This default needs to be one of the following:

  #REQUIRED
  #IMPLIED
  An attribute value, optionally preceded by #FIXED

This needs to be preceded by a space.

If you choose #IMPLIED, for example, the line becomes

<!ATTLIST title keyword CDATA #IMPLIED>

Parsing the document again, you get the following:

FATAL ERROR: encountered “+”. Was expecting: “*”
Location: file:///c:/xmlex/dtdv.dtd:21:34

Found errors/warnings: 1 fatal error(s), 0 error(s) and 0 warning(s)

Now the problem lies with the following line:

<!ELEMENT menu (#PCDATA|shortcut)+>

When you have mixed content—character data interspersed with child elements—the content model needs to have the * occurrence indicator. Thus, the line needs to become

<!ELEMENT menu (#PCDATA|shortcut)*>

Reparsing the document, you now get

FATAL ERROR: encountered “idref”. Was expecting one of: “ID” , “IDREF” , “IDREFS
“ , “ENTITY” , “ENTITIES” , “NMTOKEN” , “NMTOKENS” , “NOTATION” , “CDATA” , “%”
, “(“
Location: file:///c:/xmlex/dtdv.dtd:24:24

Found errors/warnings: 1 fatal error(s), 0 error(s) and 0 warning(s)

All keywords (including idref) need to be in uppercase in XML. Making the necessary correction and running the parser again produces

ERROR: element declared twice “tip”
Location: file:///c:/xmlex/dtdv.dtd:27:11

ERROR: notation not declared “bmp”
Location: file:///c:/xmlex/dtdv.dtd:31:41

ERROR: notation not declared “gif”
Location: file:///c:/xmlex/dtdv.dtd:31:44

FATAL ERROR: encountered end of file
Location: :3:4

Found errors/warnings: 1 fatal error(s), 3 error(s) and 0 warning(s)

Before encountering the fatal error, the parser found three errors that were not fatal. Note that non-fatal errors do not stop the parser from continuing its work.

The first non-fatal error occurs because the element tip is declared twice. The XML specification states that no element type may be declared more than once. This is a validity constraint, and violations against validity constraints are considered non-fatal errors. Fortunately, this error is simple to correct—you just need to delete the second declaration of the tip element.

The next two non-fatal errors have to do with the bmp and gif notations. This is understandable because, according to the specification, all notation names in the declaration must be explicitly declared. You can compensate for this by adding the following code:

<!NOTATION bmp SYSTEM “paint.exe”>
<!NOTATION gif SYSTEM “”>

After this, there is just one error left:

FATAL ERROR: encountered end of file
Location: :3:4

Found errors/warnings: 1 fatal error(s), 0 error(s) and 0 warning(s)

This is actually a little tricky to diagnose. The problem is no longer with the DTD, but with the XML file itself. The XML file passed to the parser has a prologue with an xml declaration and a doctype declaration, but nothing more—not even a root element! Every XML document must have a root element, and this is what led to the fatal error.

The good news is that there are no longer any errors in your DTD. The final corrected DTD is shown in Listing 16.2.

Listing 16.2 Corrected DTD for DXP Example


<!NOTATION bmp SYSTEM “paint.exe”>
<!NOTATION gif SYSTEM “”>

<!ENTITY % admonitions “(tip | warning | note)” >
<!ENTITY % paracontent “(#PCDATA | icon | menu | xref | iconbmp)*” >

<!ELEMENT helptopic (title, rule, procedure, rule?, %admonitions;) >
<!ATTLIST helptopic id ID #IMPLIED>

<!ELEMENT title (#PCDATA) >
<!ATTLIST title keyword CDATA #IMPLIED>

<!ELEMENT procedure (step+)>
<!ELEMENT step (action, (%admonitions;)*) >

<!ELEMENT action %paracontent; >
<!ELEMENT tip %paracontent; >
<!ATTLIST tip targetgroup (beginners | specialists) “beginners” >

<!ELEMENT warning %paracontent; >
<!ELEMENT note %paracontent; >

<!ELEMENT icon (#PCDATA) >
<!ELEMENT menu (#PCDATA|shortcut)*>

<!ELEMENT xref (#PCDATA) >
<!ATTLIST xref linkend IDREF #REQUIRED>

<!ELEMENT shortcut (#PCDATA)>

<!ELEMENT iconbmp EMPTY>
<!ATTLIST iconbmp src ENTITY #REQUIRED
              type NOTATION (bmp | gif) “gif”>


Parser Warnings

One thing you’ll note in the corrected DTD is that there are some elements for which there is no declaration. You may be wondering why the parser did not flag these instances.

If you read the XML specification, you’ll find the following: “At user option, an XML processor may issue a warning when a declaration mentions an element type for which no declaration is provided, but this is no error.”

Does DXP give you this user option? The answer is yes—you can add the parameter -w to receive warnings.

jre –cp .;c:\datachannel\dxp\classes dxpcl –s –v –w c:\xmlex\dtdv.xml

But DXP doesn’t seem to catch this one, which technically isn’t a problem because the standard says that an XML processor “may issue a warning,” not that it always will.


Declarations in the Internal Subset

The declarations in the internal subset are those you find between [ and ] in the document type declaration:

<!DOCTYPE helptopic [
<!ELEMENT helptopic (title, procedure)>
<!ATTLIST helptopic id ID #REQUIRED>
…
]
<helptopic>….


NOTE:  Remember that the DTD of a document consists of both internal and external subsets taken together.

Suppose for the moment that all your declarations are in the external subset of your document type declaration. What will happen if you copy the content of your file inside your internal subset and don’t refer to the external file with the declarations (as in Listing 16.3)?


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.