Click Here!
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


When you submit wfq.xml to DXP, you get the following response:

ERROR: Invalid content : procedure
Possible: rule
Location: file:/c:/xmlex/wfq.xml:8:2

ERROR: element not declared in DTD “rule”
Location: file:/c:/xmlex/wfq.xml:21:2

ERROR: attribute hasn’t been declared in the DTD “form”
Location: file:/c:/xmlex/wfq.xml:21:7

FATAL ERROR: java.lang.NullPointerException:
Location: :0:0

According to the DTD, a helptopic needs to start with a title, followed by a rule, and then the procedure. That is not the case in the file wfq.xml.

Suppose that you add a rule to wfq.xml and run the parser again. This time you get the following:

ERROR: element not declared in DTD “rule”
Location: file:/c:/xmlex/wfq.xml:8:2

ERROR: element not declared in DTD “rule”
Location: file:/c:/xmlex/wfq.xml:21:2

ERROR: attribute hasn’t been declared in the DTD “form”
Location: file:/c:/xmlex/wfq.xml:21:7

FATAL ERROR: java.lang.NullPointerException:
Location: :0:0

The XML specification puts forward the following validity constraints:

  An element is valid if there is a declaration for the element.
  All attributes must be declared.

If one of these constraints doesn’t hold, the document cannot be valid. This means you need to add declarations for the missing elements and attributes. The following code will do the trick:

<!ELEMENT rule EMPTY>
<!ATTLIST rule form (single | double | dotted) “single”>

Once this is done and DXP is rerun, you get the following output:

ERROR: Invalid content : p
Possible: iconbmp, icon, menu, #PCDATA, , xref
Location: file:/c:/xmlex/wfq.xml:23:2

ERROR: element not declared in DTD “p”
Location: file:/c:/xmlex/wfq.xml:23:2

ERROR: unknown ID referred “id45”
Location: file:/c:/xmlex/wfq.xml:26:14

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

The tip after the second rule contains a p element, which isn’t allowed by the DTD. Removing this element and running DXP one more time produces the following:

ERROR: unknown ID referred “id45”
Location: file:/c:/xmlex/wfq.xml:25:14

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

IDREF values must match the value of some ID attribute in the XML document, which isn’t the case in the sample document. There is no element in wfq.xml with an attribute of type ID and a value of id45. Once the xref element is removed, the document will finally be valid.

Checking the Validity of XML Files with XML for Java

This section investigates how to use XML for Java to check the validity of an XML document. Assuming you have the class files downloaded and unzipped, you can type the following commands at a DOS prompt:

jre -cp c:\xml4j\xml4j.jar trlx c:\xmlex\wfq.xml

Here’s a breakdown of what you just typed:

  jre is used to invoke the Java Runtime Engine.
  -cp is used to set the classpath. In this case you refer to the jar (Java archive file) as xml4j.jar.
  trlx is the Java class that does the parsing.
  c:\xmlex\wfq.xml is the file to be checked.

If you submit the original version of wfq.xml to XML for Java, you get the following set of error messages:

c:\xmlex\wfq.xml: 21, 22: Attribute ‘form’ of element ‘rule’ is not declared.
c:\xmlex\wfq.xml: 21, 22: Can’t find content model of ‘<rule>’.
c:\xmlex\wfq.xml: 24, 5: Can’t find content model of ‘<p>’.
c:\xmlex\wfq.xml: 25, 7: Content mismatch in ‘<tip>’.  Content model is
“(#PCDATA|icon|menu|xref|iconbmp)*’.
c:\xmlex\wfq.xml: 26, 13: Content mismatch in ‘<helptopic>’.  Content model is ‘
‘(title,rule,procedure,rule?,(tip|warning|note))’.
c:\xmlex\wfq.xml: 18, 45: ID ‘id45’ is not defined in the document.

Note that all of these errors correspond exactly to the errors you saw using DXP. The one advantage to using XML for Java is that the error messages tell you where the error occurs in the file. Also, XML for Java’s error messages tend to be more explicit than those generated by DXP.

Other XML Parsers

The two Java-based XML parsers you’ve read about in this chapter are by no means the only two available. Indeed, more and more XML-related software is becoming available every day. Here are two more parsers that are worth checking into:

  MSXML—This is a Java-based validating XML parser written by Microsoft. You can visit http://www.microsoft.com/workshop/xml/parser/xmldl.asp to learn how to download and install MSXML.
  Larval—Written by Tim Bray of Textuality, Larval is a validating XML parser based on the non-validating parser Lark. You can find out more about both of these programs at http://www.textuality.com/Lark/.
ON THE WEB
http://www.sil.org/sgml/publicSW.html Because new XML software is always being written, you should consult Robin Cover’s list of SGML and XML software to stay current with the most recent releases.


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.