|
To access the contents, click the chapter and section titles.
Platinum Edition Using HTML 4, XML, and Java 1.2
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 hasnt 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 hasnt 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:
If one of these constraints doesnt 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 isnt 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 isnt 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 JavaThis 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 Heres a breakdown of what you just typed:
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: Cant find content model of <rule>. c:\xmlex\wfq.xml: 24, 5: Cant 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 Javas error messages tend to be more explicit than those generated by DXP. Other XML ParsersThe two Java-based XML parsers youve 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:
|
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. |