Java and XML, 3rd Edition

Book description

Java and XML, 3rd Edition, shows you how to cut through all the hype about XML and put it to work. It teaches you how to use the APIs, tools, and tricks of XML to build real-world applications. The result is a new approach to managing information that touches everything from configuration files to web sites.

After two chapters on XML basics, including XPath, XSL, DTDs, and XML Schema, the rest of the book focuses on using XML from your Java applications. This third edition of Java and XML covers all major Java XML processing libraries, including full coverage of the SAX, DOM, StAX, JDOM, and dom4j APIs as well as the latest version of the Java API for XML Processing (JAXP) and Java Architecture for XML Binding (JAXB). The chapters on web technology have been entirely rewritten to focus on the today's most relevant topics: syndicating content with RSS and creating Web 2.0 applications. You'll learn how to create, read, and modify RSS feeds for syndicated content and use XML to power the next generation of websites with Ajax and Adobe Flash.

Topics include:

  • The basics of XML, including DTDs, namespaces, XML Schema, XPath, and Transformations
  • The SAX API, including all handlers, filters, and writers
  • The DOM API, including DOM Level 2, Level 3, and the DOM HTML module
  • The JDOM API, including the core and a look at XPath support
  • The StAX API, including StAX factories, producing documents and XMLPull
  • Data Binding with JAXB, using the new JAXB 2.0 annotations
  • Web syndication and podcasting with RSS
  • XML on the Presentation Layer, paying attention to Ajax and Flash applications

If you are developing with Java and need to use XML, or think that you will be in the future; if you're involved in the new peer-to-peer movement, messaging, or web services; or if you're developing software for electronic commerce, Java and XML will be an indispensable companion.

Publisher resources

View/Submit Errata

Table of contents

  1. A Note Regarding Supplemental Files
  2. Preface
    1. Organization
    2. Conventions Used in This Book
    3. Using Code Examples
    4. We’d Like Your Feedback!
    5. Safari® Enabled
    6. Acknowledgments
      1. Brett D. McLaughlin
      2. Justin Edelson
  3. 1. Introduction
    1. XML 1.0
      1. The Root Element
      2. Elements
      3. Attributes
      4. Namespaces
      5. Entity References
      6. Unparsed Data
    2. XML 1.1
    3. XML Transformations
      1. XSL
        1. XSL and trees
        2. Formatting objects
      2. XSLT
      3. XPath
        1. Template matching
        2. Looping
        3. Performing a transform
    4. And More...
  4. 2. Constraints
    1. DTDs
      1. DTD Semantics
        1. Elements
        2. Attributes
        3. Entities
      2. Generating DTDs from XML Instance Documents
      3. Validating XML Against a DTD
    2. XML Schema
      1. XML Schema Definitions
        1. Elements and attributes
        2. Simple types
        3. Extending base types
      2. Generating XML Schemas from Instance Documents
      3. Generating XML Schemas from a DTD
      4. Validating XML Against an XML Schema
        1. Referencing a schema for nonnamespaced documents
        2. Referencing a schema for namespaced documents
        3. Validating against a schema
    3. RELAX NG
      1. Constraining XML with RELAX NG
        1. Elements
        2. Cardinality and recurrence
        3. Attributes
        4. Data types
      2. Generating RELAX NG from an XML Instance
      3. Converting DTDs to RELAX NG Schemas
      4. Converting XML Schemas to RELAX NG Schemas
      5. Validating XML Against a RELAX NG Schema
  5. 3. SAX
    1. Setting Up SAX
      1. Callbacks and Event-Based Programming
      2. The SAX API
      3. SAX Parsing Setup
    2. Parsing with SAX
      1. Instantiating a Reader
      2. Parsing the Document
        1. Using InputSource for input
        2. Not much going on...
    3. Content Handlers
      1. The Document Locator
      2. The Beginning and the End of a Document
      3. Processing Instructions
      4. Namespace Callbacks
      5. Element Callbacks
      6. Element Data
        1. Sequencing mixups
        2. Whitespace
      7. Ignorable Whitespace
      8. Entities
      9. The Results
    4. Error Handlers
      1. Warnings
      2. Nonfatal Errors
      3. Fatal Errors
      4. Breaking the Data
  6. 4. Advanced SAX
    1. Properties and Features
      1. Setting Properties and Features
      2. Error Handling
    2. Resolving Entities
    3. Notations and Unparsed Entities
    4. The DefaultHandler Class
    5. Extension Interfaces
      1. LexicalHandler
      2. DeclHandler
      3. Attributes2, Locator2, and EntityResolver2
    6. Filters and Writers
      1. XMLFilters
      2. XMLWriter
  7. 5. DOM
    1. The Document Object Model
      1. DOM Levels and Modules
      2. DOM Concepts
      3. When SAX Sucks
    2. Serialization
      1. Getting a DOM Parser
      2. The DOM Document Object
      3. Serializer Preliminaries
      4. Working with Nodes
        1. Document nodes
        2. Accessing the XML declaration
        3. Element nodes
        4. Text and CDATA nodes
        5. Comment nodes
        6. Processing instruction nodes
        7. DocumentType nodes
        8. Entity Reference nodes
      5. The Results
    3. Modifying and Creating XML
      1. Setting Up an Input Servlet
      2. Creating a New DOM Tree
        1. Bootstrapping with DOM Level 3
      3. Modifying a DOM Tree
      4. Traversing a DOM Tree
    4. Namespaces
  8. 6. DOM Modules
    1. Checking for Module Support
      1. Requesting Feature Support in DOM Level 3
    2. DOM Level 2 Modules
      1. Traversal
        1. Selecting nodes
        2. Walking filtered DOM trees
      2. Range
      3. Events, Views, and Style
        1. Events
        2. Views
        3. Style
      4. HTML
    3. DOM Level 3 Modules
      1. Load and Save
        1. Reading XML documents
        2. Writing XML documents
      2. Validation
        1. Node types supporting validation
        2. Enforcing validity as you work
        3. Checking for valid operations
        4. Checking for state validity
  9. 7. JAXP
    1. More Than an API
      1. XML Parsing and Validation
      2. XSL Processing
      3. XPath
    2. Parsing XML
      1. Reading XML with SAX
        1. Creating a parser factory
        2. Configuring the factory
        3. Obtaining a parser
        4. Parsing with JAXP and SAX
        5. Accessing XMLReader directly
      2.  
        1. From SAXParserFactory to DOMBuilderFactory
        2. DOM factory configuration options
      3. Changing the Parser Implementation
    3. Processing XSL
      1. Basic Transformations
        1. Creating a transformer
      2. The Identity Transformation
      3. Caching Transformation Instructions
      4. Changing the Processor Implementation
    4. XPath
      1. Creating an XPath Instance
      2. XPath Examples
      3. Namespaces in XPath
      4. XPath Variables
      5. XPath Functions
    5. XML Validation
      1. Creating a SchemaFactory
      2. Representing a Constraint Model in Java
      3. Validating XML
        1. Fixing errors as they occur
        2. Using ValidatorHandler to customize validation processing
      4. A Big Fat Caveat About JAXP Validation
  10. 8. Pull Parsing With StAX
    1. StAX Basics
      1. StAX Event Types
      2. Obtaining a StAX Implementation
    2. StAX Factories
    3. Parsing with StAX
      1. Creating a Reader
      2. XMLStreamReader
        1. The START_DOCUMENT event
        2. Parsing the rest of the document
        3. Getting character data
        4. Whitespace handling
        5. Two more events
      3. XMLEventReader
        1. XMLEventReader advantages
      4. Other Traversal Options
        1. nextTag()
        2. require()
        3. peek()
      5. StAX Filters
    4. Document Output with StAX
      1. XMLStreamWriter
        1. Namespace support
      2. XMLEventWriter
    5. Factory Properties
      1. Boolean Properties of XMLInputFactory
      2. Object Properties of XMLInputFactory
        1. XMLResolver
        2. XMLReporter
        3. XMLEventAllocator
      3. XMLOutputFactory
    6. Common Issues with StAX
    7. XmlPull
  11. 9. JDOM
    1. The Basics
      1. Java Collections Support
      2. Concrete Classes and Factories
      3. Useful Return Values
      4. Input and Output
      5. The JDOM Distribution
    2. PropsToXML
      1. Java Properties Files
      2. Converting to XML
      3. Creating XML with JDOM
      4. Outputting XML with JDOM
        1. The Format class
        2. Other uses of XMLOutputter
    3. XMLProperties
      1. Storing XML
      2. Loading XML
      3. Taking a Test Drive
      4. Backtracking
    4. More JDOM Classes
      1. The Namespace Class
      2. XSL Transformations with JDOM
      3. XPath and JDOM
      4. JDOM Filters
        1. ElementFilter
        2. ContentFilter
        3. NegateFilter
        4. OrFilter and AndFilter
      5. The EntityRef Class
    5. JDOM and Factories
      1. Creating a Factory
      2. Building with Custom Classes
      3. UncheckedJDOMFactory
    6. Common Issues with JDOM
      1. What Parser Am I Using?
      2. JDOM Isn’t DOM
      3. Null Return Values
      4. Nodes Have Only One Parent
      5. More on Subclassing
      6. Creating Invalid XML
  12. 10. dom4j
    1. Overview
      1. Core dom4j
        1. Factories
      2. dom4j Features
        1. XPath support
        2. Support for Visitor Pattern
        3. Object-orientated transformation API
      3. The dom4j Distribution
    2. Reading and Writing with dom4j
      1. Parsing a Document
      2. Creating a Document Object
        1. Namespaces and qualified names
      3. Document Output
        1. Formatting options
        2. Outputting to other APIs
    3. Document Traversal
      1. Iterator, Lists, and Index-Based Access
      2. XPath
      3. Using the Visitor Pattern
    4. Transformations
      1. TrAX
      2. Rule-Based Transformations
    5. Special-Purpose Factories
      1. DOMDocumentFactory
      2. IndexedDocumentFactory
      3. BeanDocumentFactory
  13. 11. Data Binding with JAXB
    1. Data Binding Basics
      1. Data Binding and Schemas
      2. When to (and When Not to) Use Data Binding
    2. Introducing JAXB
      1. JAXB 1.0
      2. JAXB 2.0
      3. JAXB Reference Implementations
        1. Java WSDP
          1. Downloading Java WSDP
        2. Downloading JAXB 2.0 reference implementation
        3. Contents
    3. Using JAXB
      1. JAXBContext
      2. Compiling a Schema
        1. Compiling with xjc
        2. JAXB 1.0-generated files
        3. JAXB 2.0-generated files
      3. JAXB Annotations
        1. Class-level annotations
          1. XmlRootElement
          2. XmlAccessorType
          3. XmlType
        2. Field-level annotations
          1. XmlElement
          2. XmlAttribute
        3. Package-level annotations
        4. Schema generation
      4. Marshalling
        1. Bidirectional DOM support
        2. Marshaller properties
      5. Unmarshalling
        1. Unmarshall-time validation
        2. Unmarshaller properties
      6. Validation
        1. Validation events
      7. Schema Compilation Customization
        1. Inline declarations
        2. External declaration
        3. Binding declarations
      8. JAXB Callbacks
        1. Class-defined callbacks
        2. External listener
    4. Other Binding Frameworks
      1. XMLBeans
      2. Castor
  14. 12. Content Syndication with RSS
    1. What Is RSS?
      1. RSS Variants
      2. RSS Modules
        1. Dublin Core
        2. Syndication
        3. Content
        4. CommentAPI
        5. iTunes
      3. Atom
    2. Creating an RSS Feed
      1. Introducing ROME
        1. ROME data models
        2. Outputting a ROME feed
      2. Creating a Feed with ROME
    3. Reading an RSS Feed
      1. Feed Input with ROME
      2. Building a Simple Aggregator
    4. Modules with ROME
      1. Creating a Podcast RSS Feed
        1. iTunes categories
      2. Creating a ROME Module
        1. The ICBM module
  15. 13. XML As Presentation
    1. XML and the Model-View-Controller Pattern
      1. XML in MVC Web Applications
    2. Transforming to HTML with JSP
      1. JSTL XML Tags
    3. Using XSLT
      1. Performing Client-Side Transformations
        1. Using processing instructions
        2. Transforming with JavaScript
      2. Performing Server-Side Transformations
        1. Transforming in a filter
        2. Transforming with JSTL
    4. Ajax
      1. XMLHttpRequest
      2. Using DOM with Ajax
      3. Using XSLT with Ajax
      4. Posting XML to the Server
        1. Creating an XML document in JavaScript
        2. Submitting the XML document
    5. Flash
      1. ActionScript
      2. Flex
      3. XML in ActionScript 3.0
        1. E4X
        2. XML data providers
        3. Sending and loading XML
        4. Using Flash XML sockets
      4. Cross-Domain Access
  16. 14. Looking Forward
    1. XML Appliances
    2. XML Databases
    3. XQuery
    4. Fast Infoset
    5. And Many More...
  17. 1. SAX Features and Properties
    1. Core Features
      1. External General Entity Processing
      2. External Parameter Entity Processing
      3. Standalone
      4. Parameter Entity Reporting
      5. Namespace Processing
      6. Namespace Prefix Reporting
      7. Absolute URI Declaration Resolution
      8. String Interning
      9. Unicode Normalization Checking
      10. Attributes2 Usage
      11. Locator2 Usage
      12. EntityResolver2 Usage
      13. Validation
      14. Report Namespace on xmlns Attributes
      15. XML 1.1 Support
    2. Core Properties
      1. Declaration Handler
      2. Document Version
      3. DOM Node
      4. Lexical Handler
      5. Literal (XML) String
  18. Index
  19. About the Authors
  20. Copyright

Product information

  • Title: Java and XML, 3rd Edition
  • Author(s): Brett McLaughlin, Justin Edelson
  • Release date: December 2006
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9780596101497