Java & XML, 2nd (Web hosts) Edition Java and XML,
Tuesday, July 31st, 2007Java & XML, 2nd Edition
Java and XML, 2nd edition, is now available at bookstores, as well as through O’Reilly at http://www.oreilly.com.
In this XHTML fragment, the whitespace between the opening p element and the opening i element is not ignorable, and therefore reported through the characters( ) callback. If you aren’t completely confused (and I don’t think you are), be prepared to closely monitor both of the character-related callbacks. That will make explaining the last SAX callback related to this issue a snap. 3.3.7 Ignorable Whitespace With all that whitespace discussion done, adding an implementation for the ignorableWhitespace( ) method is a piece of cake. Since the whitespace reported is ignorable, the code does just that ignore it: public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException { // This is ignorable, so don’t display it } Whitespace is reported in the same manner as character data; it can be reported with one callback, or a SAX parser may break up the whitespace and report it over several method invocations. In either case, adhere closely to the precautions about not making assumptions or counting on whitespace as textual data in order to avoid troublesome bugs in your applications. 3.3.8 Entities As you recall, there is only one entity reference in the contents.xml document, OReillyCopyright. When parsed and resolved, this results in another file being loaded, either from the local filesystem or some other URI. However, validation is not turned on in the reader implementation being used.3 An often overlooked facet of nonvalidating parsers is that they are not required to resolve entity references, and instead may skip them. This has caused some headaches before, as parser results may simply not include entity references that were expected to be included. SAX 2.0 nicely accounts for this with a callback that is issued when an entity is skipped by a nonvalidating parser. The callback gives the name of the entity, which can be included in the viewer’s output: public void skippedEntity(String name) throws SAXException { DefaultMutableTreeNode skipped = new DefaultMutableTreeNode(”Skipped Entity: ‘” + name + “‘”); current.add(skipped); } Before you go looking for the OReillyCopyright node, though, you should be aware that most established parsers will not skip entities, even if they are not validating. Apache Xerces, I’m assuming that even if you aren’t using Apache Xerces, your parser does not leave validation on by default. If you get different results than shown in this chapter, consult your documentation and see if validation is on. If it is, sneak a peek at Chapter 4 and see how to turn it off.
You want to have a cheap webhost for your apache application, then check apache web hosting services.