You are previewing Perl and XML.
O'Reilly logo
Perl and XML

Book Description

XML is a text-based markup language that has taken the programming world by storm. More powerful than HTML yet less demanding than SGML, XML has proven itself to be flexible and resilient. XML is the perfect tool for formatting documents with even the smallest bit of complexity, from Web pages to legal contracts to books. However, XML has also proven itself to be indispensable for organizing and conveying other sorts of data as well, thus its central role in web services like SOAP and XML-RPC. As the Perl programming language was tailor-made for manipulating text, few people have disputed the fact that Perl and XML are perfectly suited for one another. The only question has been what's the best way to do it. That's where this book comes in. Perl & XML is aimed at Perl programmers who need to work with XML documents and data. The book covers all the major modules for XML processing in Perl, including XML::Simple, XML::Parser, XML::LibXML, XML::XPath, XML::Writer, XML::Pyx, XML::Parser::PerlSAX, XML::SAX, XML::SimpleObject, XML::TreeBuilder, XML::Grove, XML::DOM, XML::RSS, XML::Generator::DBI, and SOAP::Lite. But this book is more than just a listing of modules; it gives a complete, comprehensive tour of the landscape of Perl and XML, making sense of the myriad of modules, terminology, and techniques. This book covers:

  • parsing XML documents and writing them out again

  • working with event streams and SAX

  • tree processing and the Document Object Model

  • advanced tree processing with XPath and XSLT

Most valuably, the last two chapters of Perl & XML give complete examples of XML applications, pulling together all the tools at your disposal. All together, Perl & XML is the single book that gives you a solid grounding in XML processing with Perl.

Table of Contents

  1. Perl and XML
  2. A Note Regarding Supplemental Files
  3. Preface
    1. Assumptions
    2. How This Book Is Organized
    3. Resources
      1. The perl-xml Mailing List
      2. CPAN
    4. Font Conventions
    5. How to Contact Us
    6. Acknowledgments
  4. 1. Perl and XML
    1. 1.1. Why Use Perl with XML?
    2. 1.2. XML Is Simple with XML::Simple
    3. 1.3. XML Processors
    4. 1.4. A Myriad of Modules
    5. 1.5. Keep in Mind...
    6. 1.6. XML Gotchas
  5. 2. An XML Recap
    1. 2.1. A Brief History of XML
    2. 2.2. Markup, Elements, and Structure
    3. 2.3. Namespaces
    4. 2.4. Spacing
    5. 2.5. Entities
    6. 2.6. Unicode, Character Sets, and Encodings
    7. 2.7. The XML Declaration
    8. 2.8. Processing Instructions and Other Markup
    9. 2.9. Free-Form XML and Well-Formed Documents
    10. 2.10. Declaring Elements and Attributes
    11. 2.11. Schemas
      1. 2.11.1. Other Schema Strategies
    12. 2.12. Transformations
  6. 3. XML Basics: Reading and Writing
    1. 3.1. XML Parsers
      1. 3.1.1. Example (of What Not to Do): A Well-Formedness Checker
    2. 3.2. XML::Parser
      1. 3.2.1. Example: Well-Formedness Checker Revisited
      2. 3.2.2. Parsing Styles
    3. 3.3. Stream-Based Versus Tree-Based Processing
    4. 3.4. Putting Parsers to Work
    5. 3.5. XML::LibXML
    6. 3.6. XML::XPath
    7. 3.7. Document Validation
      1. 3.7.1. DTDs
      2. 3.7.2. Schemas
    8. 3.8. XML::Writer
      1. 3.8.1. Other Methods of Output
    9. 3.9. Character Sets and Encodings
      1. 3.9.1. Unicode, Perl, and XML
      2. 3.9.2. Unicode Encodings
        1. 3.9.2.1. UTF-8
        2. 3.9.2.2. UTF-16
        3. 3.9.2.3. UTF-32
      3. 3.9.3. Other Encodings
        1. 3.9.3.1. Core Perl support
      4. 3.9.4. Encoding Conversion
        1. 3.9.4.1. iconv and Text::Iconv
        2. 3.9.4.2. Unicode::String
        3. 3.9.4.3. Byte order marks
  7. 4. Event Streams
    1. 4.1. Working with Streams
    2. 4.2. Events and Handlers
    3. 4.3. The Parser as Commodity
    4. 4.4. Stream Applications
    5. 4.5. XML::PYX
    6. 4.6. XML::Parser
  8. 5. SAX
    1. 5.1. SAX Event Handlers
    2. 5.2. DTD Handlers
    3. 5.3. External Entity Resolution
    4. 5.4. Drivers for Non-XML Sources
    5. 5.5. A Handler Base Class
    6. 5.6. XML::Handler::YAWriter as a Base Handler Class
    7. 5.7. XML::SAX: The Second Generation
      1. 5.7.1. XML::SAX::ParserFactory
      2. 5.7.2. SAX2 Handler Interface
        1. 5.7.2.1. Content event handlers
        2. 5.7.2.2. Entity resolver
        3. 5.7.2.3. Lexical event handlers
        4. 5.7.2.4. Error event handlers and catching exceptions
      3. 5.7.3. SAX2 Parser Interface
      4. 5.7.4. Example: A Driver
      5. 5.7.5. Installing Your Own Parser
  9. 6. Tree Processing
    1. 6.1. XML Trees
    2. 6.2. XML::Simple
    3. 6.3. XML::Parser's Tree Mode
    4. 6.4. XML::SimpleObject
    5. 6.5. XML::TreeBuilder
    6. 6.6. XML::Grove
  10. 7. DOM
    1. 7.1. DOM and Perl
    2. 7.2. DOM Class Interface Reference
      1. 7.2.1. Document
        1. 7.2.1.1. Properties
        2. 7.2.1.2. Methods
      2. 7.2.2. DocumentFragment
      3. 7.2.3. DocumentType
        1. 7.2.3.1. Properties
      4. 7.2.4. Node
        1. 7.2.4.1. Properties
        2. 7.2.4.2. Methods
      5. 7.2.5. NodeList
        1. 7.2.5.1. Properties
        2. 7.2.5.2. Methods
      6. 7.2.6. NamedNodeMap
        1. 7.2.6.1. Properties
        2. 7.2.6.2. Methods
      7. 7.2.7. CharacterData
        1. 7.2.7.1. Properties
        2. 7.2.7.2. Methods
      8. 7.2.8. Element
        1. 7.2.8.1. Properties
        2. 7.2.8.2. Methods
      9. 7.2.9. Attr
        1. 7.2.9.1. Properties
      10. 7.2.10. Text
        1. 7.2.10.1. Methods
      11. 7.2.11. CDATASection
      12. 7.2.12. ProcessingInstruction
        1. 7.2.12.1. Properties
      13. 7.2.13. Comment
      14. 7.2.14. EntityReference
      15. 7.2.15. Entity
        1. 7.2.15.1. Properties
      16. 7.2.16. Notation
        1. 7.2.16.1. Properties
    3. 7.3. XML::DOM
    4. 7.4. XML::LibXML
  11. 8. Beyond Trees: XPath, XSLT, and More
    1. 8.1. Tree Climbers
    2. 8.2. XPath
    3. 8.3. XSLT
    4. 8.4. Optimized Tree Processing
  12. 9. RSS, SOAP, and Other XML Applications
    1. 9.1. XML Modules
    2. 9.2. XML::RSS
      1. 9.2.1. Introduction to RSS
      2. 9.2.2. Using XML::RSS
        1. 9.2.2.1. Parsing
        2. 9.2.2.2. Inheriting from XML::Parser
      3. 9.2.3. The Object Model
      4. 9.2.4. Input: User or File
      5. 9.2.5. Off-the-Cuff Output
    3. 9.3. XML Programming Tools
      1. 9.3.1. XML::Generator::DBI
      2. 9.3.2. Further Ruminations on DBI and SAX
    4. 9.4. SOAP::Lite
      1. 9.4.1. First Example: A Temperature Converter
      2. 9.4.2. Second Example: An ISBN Lookup Engine
  13. 10. Coding Strategies
    1. 10.1. Perl and XML Namespaces
    2. 10.2. Subclassing
      1. 10.2.1. Subclassing Example: XML::ComicsML
    3. 10.3. Converting XML to HTML with XSLT
      1. 10.3.1. Example: Apache::DocBook
    4. 10.4. A Comics Index
  14. Index
  15. About the Authors
  16. Colophon
  17. Copyright