Processing Xml With Java - A Guide To Sax, Dom, Jdom, Jaxp, And Trax Free Open Book

Processing Xml With Java - A Guide To Sax, Dom, Jdom, Jaxp, And Trax

Previous Section Next Section

Summary

The SAX XMLReader interface represents an XML parser. The actual implementation class will vary from one parser to the next, but generally you'll only interact with it through the parser-independent methods in XMLReader. Parser-specific instances of this interface are built by the XMLReaderFactory factory class.

The XMLReader's parse() method actually reads the XML document. One parser object can read multiple documents in series. However, parsers are neither thread safe nor reentrant and should not be used to read documents in parallel. The source from which the XML document is read—be it an InputStream, Reader, or URI—is wrapped inside an org.xml.sax.InputSource object. You can use an EntityResolver to replace one InputSource with a different InputSource behind the parser's back. If anything goes wrong during the parse process, this method throws a SAXException or an IOException.

You can configure the parser by setting features and properties. Both features and properties have names given by absolute URIs. Features have boolean values: true or false. Properties have object values. Standard features have names beginning with http://xml.org/sax/features/ and include

  • http://xml.org/sax/features/external-general-entities

  • http://xml.org/sax/features/external-parameter-entities

  • http://xml.org/sax/features/string-interning

  • http://xml.org/sax/features/validation

Standard properties have names beginning with http://xml.org/sax/properties/ and include

  • http://xml.org/sax/properties/declaration-handler

  • http://xml.org/sax/properties/dom-node

  • http://xml.org/sax/properties/lexical-handler

  • http://xml.org/sax/properties/xml-string

This is not an exhaustive list. Parser vendors add custom features and properties with names in their own domain, such as http://apache.org/xml/features/validation/schema and http://apache.org/xml/properties/schema/external-schemaLocation, to configure functionality unique to their parser. Of course, not all features and properties, not even all standard features and properties, are supported by any one parser. If you try to set a feature or property that the parser is unfamiliar with and never allows under any circumstances, then setFeature()/setProperty() throws a SAXNotRecognizedException. If you try to set a feature or property that the parser recognizes but cannot set at the current time or cannot set to the requested value, then setFeature()/setProperty() throws a SAXNotSupportedException.

The parser reports the content of the XML document to methods in one or more callback interfaces. The most basic such callback interface, and the one that accounts for 90 percent of what you need, is ContentHandler. Other callback interfaces for special needs include ErrorHandler for reporting fatal errors, errors, and warnings; and DTDHandler for keeping track of unparsed entity and notation declarations. In addition there are two optional callback interfaces registered by setting properties: LexicalHandler for reporting comments, parsed entities, and CDATA sections and DeclHandler for reporting ELEMENT, ATTLIST, and ENTITY declarations.

    Previous Section Next Section


         Main Menu
    Main Page
    Table of content
    Copyright
    Praise for Elliotte Rusty Harold's 'Processing XML with Java™'
    List of Examples
    List of Figures
    Preface
    Part I: XML
    Part II: SAX
    Chapter 6. SAX
    Chapter 7. The XMLReader Interface
    Building Parser Objects
    Input
    Exceptions and Errors
    Features and Properties
    DTDHandler
    Summary
    Chapter 8. SAX Filters
    Part III: DOM
    Part IV: JDOM
    Part V: XPath/XSLT
    Part VI: Appendixes


    More Books
    PHP Hacks
    Processing Xml With Java - A Guide To Sax, Dom, Jdom, Jaxp, And Trax
    The Koran (Holy Qur'an)
    Macromedia Flash 8 Bible
    Search Engine Optimization for Dummies
    YouTube Traffic
    PHP 5 for Dummies
    Harry Potter and The Chamber of Secrets
    Harry Potter and the Sorcerer's Stone
    The Pilgrim's Progress
    Wireless Hacks
    Flash Hacks. 100 Industrial-Strength Tips & Tools
    PayPal Hacks. 100 Industrial-Strength Tips and Tools
    Amazon Hacks
    Pdf Hacks
    The Da Vinci Code
    Google Hacks
    The Holy Bible
    Windows XP For Dummies
    Harry Potter and the Half-Blood Prince
    Seo Book
    Upgrading and Repairing Networks
    Macromedia Dreamweaver 8 UNLEASHED
    Windows XP Annoyances
    Windows XP Hacks
    Microsoft Windows XP Power Toolkit
    Teach Yourself MS Office In 24Hours
    iPod & iTunes Missing Manual
    PC Hacks 100 Industrial-Strength Tips and Tools
    PC Overclocking, Optimization, and Tuning - 2th Edition
    PC Hardware In A Nutshell 3rd Edition
    PC Hardware in a Nutshell, 2nd Edition
    Upgrading and Repairing PCs
    Google for Dummies
    MySQL Cookbook
    Teach Yourself Macromedia Flash 8 In 24 Hours
    PHP CookBook
    Sams Teach Yourself JavaScript in 24 Hours
    PHP5 Manual
    Free Games Paper Airplanes
    500 Juegos Gratis 500 Giochi Gratis 500 Jeux Gratuits 500 Jogos Gratis 500 Kostenlose Spiele