Cover image for Java and XML

Book description

XML has been the biggest buzzword on the Internet community for the past year. But how do you cut through all the hype and actually put it to work? Java revolutionized the programming world by providing a platform-independent programming language. XML takes the revolution a step further with a platform-independent language for interchanging data. Java and XML share many features that are ideal for building web-based enterprise applications, such as platform-independence, extensibility, reusability, and global language (Unicode) support, and both are based on industry standards. Together Java and XML allow enterprises to simplify and lower costs of information sharing and data exchange. Java and XML shows how to put the two together, building real-world applications in which both the code and the data are truly portable. This book covers:

  • The basics of XML

  • Using standard Java APIs to parse XML

  • Designing new document types using DTDs and Schemas

  • Writing programs that generate XML data

  • Transforming XML into different forms using XSL transformations (XSL/T)

  • XML-RPC

  • Using a web publishing framework like Apache-Cocoon

This is the first book to cover the most recent versions of the DOM specification (DOM 2), the SAX API (SAX 2) and Sun's Java API for XML.

Table of Contents

  1. Java and XML
    1. Preface
      1. Organization
      2. Who Should Read This Book?
      3. Software and Versions
      4. Conventions Used in This Book
      5. Comments and Questions
      6. Acknowledgments
    2. 1. Introduction
      1. What Is It?
        1. XML
          1. PI
          2. DTD
        2. Namespaces
        3. XSL and XSLT
        4. XPath
        5. XML Schema
        6. XQL
        7. And All the Rest . . .
      2. How Do I Use It?
        1. SAX
        2. DOM
        3. JAXP
      3. Why Should I Use It?
        1. Java and XML: A Perfect Match
        2. XML Today
          1. XML for presentation
          2. XML for communication
          3. XML-RPC
          4. Business-to-business
          5. XML for configuration
        3. Support for XML
          1. Parsers
          2. Processors
          3. Publishing frameworks
          4. XML editors and IDEs
        4. XML Tomorrow
          1. Configuration repositories
          2. XSP
      4. What’s Next?
    3. 2. Creating XML
      1. An XML Document
      2. The Header
        1. XML Instructions
        2. Document Type Declarations
      3. The Content
        1. The Root Element
        2. Identifying XML with Namespaces
        3. XML Data Elements
        4. Element Attributes
        5. Referring to XML “Constants”
        6. Unparsed Data
      4. What’s Next?
    4. 3. Parsing XML
      1. Getting Prepared
        1. Obtaining a Parser
        2. Getting the SAX Classes and Interfaces
        3. Have an XML Document on Hand
      2. SAX Readers
        1. Instantiating a Reader
        2. Parsing the Document
        3. Using an InputSource
      3. Content Handlers
        1. The Document Locator
        2. The Start and the End of a Document
        3. Processing Instructions
        4. Namespace Callbacks
        5. Element Callbacks
        6. Element Data
        7. Whitespace, Just the Whitespace
        8. Skipped Entities
        9. The Results
      4. Error Handlers
        1. Warnings
        2. Non-Fatal Errors
        3. Fatal Errors
        4. Breaking the Data
      5. A Better Way to Load a Parser
      6. “Gotcha!”
        1. My Parser Doesn’t Support SAX 2.0: What Can I Do?
        2. The SAX XMLReader: Reused and Reentrant
        3. The Misplaced Locator
        4. Getting Ahead of the Data
      7. What’s Next?
    5. 4. Constraining XML
      1. Why Constrain XML Data?
        1. Self-Documentation
        2. Portability
      2. Document Type Definitions
        1. Specifying Elements
          1. Nesting elements
          2. Parsed data
          3. Empty elements
          4. Entity references
        2. Say It Again One More Time
          1. Zero, one, or more
          2. Grouping
          3. Either or
        3. Defining Attributes
          1. Attribute types
          2. To be or not to be
        4. Things Left Out
      3. XML Schema
        1. The Schema Namespace
        2. Specifying Elements
          1. Start at the bottom
          2. User-defined data types
          3. Implicit types and empty content
          4. How many?
        3. Defining Attributes
          1. What’s left out
          2. The definition
          3. Required attributes, default values, and enumerations
      4. What’s Next?
    6. 5. Validating XML
      1. Configuring the Parser
        1. Setting Properties and Features
        2. Turning on Validation
      2. Output of XML Validation
        1. Warnings
        2. Non-Fatal Errors
        3. Fatal Errors
      3. The DTDHandler Interface
        1. Unparsed Entity Declarations
        2. Notation Declarations
        3. Registering the Handler
        4. The Rest of the Story . . .
      4. “Gotcha!”
        1. Handling Validation and Handling DTDs
        2. Validate in Development, Cruise in Production
      5. What’s Next?
    7. 6. Transforming XML
      1. The Purpose
        1. The Client of the Client of the Client
        2. It’s Greek to Me
      2. The Components
        1. The Extensible Stylesheet Language (XSL)
          1. XSL and trees
          2. Formatting objects
        2. XSL Transformations (XSLT)
        3. XML Path Language (XPath)
      3. The Syntax
        1. XSL Is XML
        2. XSL Templates
        3. Control Structures
          1. Using XPath for filtering
          2. Looping and iteration
          3. Choosing elements to process
        4. Elements and Attributes
        5. Data . . . Just the Data
        6. When Text Just Isn’t Good Enough
      4. What’s Next?
    8. 7. Traversing XML
      1. Getting the Output
      2. Getting the Input
        1. SAX Is Sequential
        2. SAX Siblings
        3. Why Use SAX At All?
      3. The Document Object Model (DOM)
        1. The DOM and Java
        2. Getting a DOM Parser
        3. DOM Parser Output
        4. Using a DOM Tree
          1. Getting the ball rolling
          2. Determining a node’s type
        5. The DOM Node Types
          1. The Document node
          2. DOM elements
          3. Applying formatting
          4. Textual nodes
          5. Processing instructions
          6. Document types
          7. Entity references
        6. Mutability of a DOM Tree
      4. “Gotcha!”
        1. Memory and Performance with DOM
        2. DOM Parsers Throwing SAX Exceptions
      5. What’s Next?
    9. 8. JDOM
      1. Parsers and the Java API for XML Parsing
        1. Using JAXP with SAX
        2. Using JAXP with DOM
        3. Selecting the Parser to Use
      2. JDOM: Another API?
        1. Specification Slowdown
        2. Java-Optimized
      3. Getting a Document
        1. Starting from Scratch
        2. Building a Document from XML
          1. SAXBuilder
          2. DOMBuilder
      4. Using a Document
        1. The Document DocType
        2. Processing Instructions
        3. Elements
          1. Namespaces
          2. Attributes
        4. Comments
      5. Outputting a Document
        1. Standard XML Output
        2. Firing Off SAX Events
        3. Putting JDOM to Work
      6. What’s Next?
    10. 9. Web Publishing Frameworks
      1. Selecting a Framework
        1. Stability
        2. Integration with Other XML Tools and APIs
        3. Production Presence
        4. Making the Decision
      2. Installation
        1. Getting Ant
        2. Getting Cocoon
        3. Building Cocoon
        4. Configuring the Servlet Engine
      3. Using a Publishing Framework
        1. Viewing XML Converted to HTML
        2. Viewing PDFs from XML
        3. Browser-Dependent Styling
        4. WAP and WML
      4. XSP
        1. Creating an XSP Page
        2. Using XSP Tag Libraries
      5. Cocoon 2.0 and Beyond
        1. Servlet Engine Mappings
        2. The Sitemap
        3. Producers and Processors
      6. What’s Next?
    11. 10. XML-RPC
      1. RPC Versus RMI
        1. What Is RMI?
        2. What Is RPC?
        3. XML-RPC
      2. Saying Hello
        1. Getting XML-RPC Libraries
        2. Writing the Handler
        3. Writing the Server
        4. Writing the Client
        5. Talk to Me
      3. Putting the Load on the Server
        1. A Shared Handler
        2. A Configurable Server
        3. A Useful Client
        4. Talk to Me (Again)
      4. The Real World
        1. Where’s the XML in XML-RPC?
        2. Shared Instances
        3. To Servlet or Not To Servlet
      5. What’s Next?
    12. 11. XML for Configurations
      1. EJB Deployment Descriptors
        1. The Basics
        2. Organization
      2. Creating an XML Configuration File
        1. Getting Started
        2. Organization
          1. Shared information
          2. XML-RPC handlers
        3. Document Constraints
        4. Final Preparations
      3. Reading an XML Configuration File
        1. Getting the Configuration Information
        2. Loading the Configuration Information
        3. Using the Configuration Information
          1. Updating the server
          2. Updating the client
      4. The Real World
        1. XML Versus Databases
        2. XML Versus Directory Services and LDAP
        3. JDOM, SAX, or DOM
          1. SAX
          2. DOM
      5. What’s Next?
    13. 12. Creating XML with Java
      1. Loading the Data
        1. An Entry Point for Modification
        2. Displaying the Configuration
      2. Modifying the Data
        1. Updating the Configuration Information
      3. XML from Scratch
      4. The Real World
        1. Threading, Writing, and Arithmetic
        2. JDOM, SAX, or DOM, Revisited
          1. SAX
          2. DOM
        3. Where Did That XmlRpcConfiguration Go?
      5. What’s Next?
    14. 13. Business-to-Business
      1. The Foobar Public Library
        1. Evaluating the Requirements
        2. Entering Books
        3. Providing a Listing of Available Books
      2. mytechbooks.com
        1. Filtering the XML Data
        2. XSLT from a Servlet
      3. Push Versus Pull
        1. Rich Site Summary
        2. Creating an RSS XML Document
        3. Validating the RSS Channel
        4. Registering the Channel
        5. Using the Channel
      4. The Real World
        1. XML Versus EDI
        2. RSS Channels: Here to Stay?
      5. What’s Next?
    15. 14. XML Schema
      1. To DTD or Not To DTD
        1. Stability of the XML Schema Specification
        2. Enhanced Document Constraints
        3. Namespace Issues with DTDs
      2. Java Parallels
        1. Equivalence
        2. Complementing Java with XML Schema
        3. Pattern Matching
        4. XML-RPC and Distributed Systems
        5. Databases and XML
      3. What’s Next?
    16. A. API Reference
      1. SAX 2.0
        1. Package: org.xml.sax
          1. AttributeList
          2. Attributes
          3. ContentHandler
          4. DocumentHandler
          5. DTDHandler
          6. EntityResolver
          7. ErrorHandler
          8. HandlerBase
          9. InputSource
          10. Locator
          11. Parser
          12. SAXException
          13. SAXNotRecognizedException
          14. SAXNotSupportedException
          15. SAXParseException
          16. XMLFilter
          17. XMLReader
        2. Package: org.xml.sax.ext
          1. DeclHandler
          2. LexicalHandler
        3. Package: org.xml.sax.helpers
          1. AttributeListImpl
          2. AttributesImpl
          3. DefaultHandler
          4. LocatorImpl
          5. NamespaceSupport
          6. ParserAdapter
          7. ParserFactory
          8. XMLFilterImpl
          9. XMLReaderAdapter
          10. XMLReaderFactory
      2. DOM Level 2
        1. Package: org.w3c.dom
          1. Attr
          2. CDATASection
          3. CharacterData
          4. Comment
          5. Document
          6. DocumentFragment
          7. DocumentType
          8. DOMException
          9. DOMImplementation
          10. Element
          11. Entity
          12. EntityReference
          13. NamedNodeMap
          14. Node
          15. NodeList
          16. Notation
          17. ProcessingInstruction
          18. Text
      3. JAXP 1.0
        1. Package: javax.xml.parsers
          1. DocumentBuilder
          2. DocumentBuilderFactory
          3. FactoryConfigurationException
          4. ParserConfigurationException
          5. SAXParser
          6. SAXParserFactory
      4. JDOM 1.0
        1. Package: org.jdom
          1. Attribute
          2. Comment
          3. DataConversionException
          4. DocType
          5. Document
          6. Element
          7. JDOMException
          8. Namespace
          9. NoSuchAttributeException
          10. NoSuchElementException
          11. NoSuchProcessingInstructionException
          12. ProcessingInstruction
        2. Package: org.jdom.adapters
          1. AbstractDOMAdapter
          2. DOMAdapter
        3. Package: org.jdom.input
          1. AbstractBuilder
          2. Builder
          3. DOMBuilder
          4. SAXBuilder
        4. Package: org.jdom.output
          1. XMLOutputter
    17. B. SAX 2.0 Features and Properties
      1. Core Features
        1. Namespace Processing
        2. Namespace Prefix Reporting
        3. String Interning
        4. Validation
        5. Process External Entities (General)
        6. Process External Entities (Parameter)
      2. Core Properties
        1. Lexical Handler
        2. Declaration Handler
        3. DOM Node
        4. Literal (XML) String
    18. Index
    19. Colophon