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

XML documents are text. This means that you can create an XML document using any technique you would normally use to create text files—including but not limited to output streams, writers, toString() methods, char arrays, or anything else that produces text. When you do this, you're responsible for maintaining well-formedness and validity. But, doing this is not hard, certainly no harder than debugging any other part of a program, and often considerably easier.

Because XML documents are text, it's best to use a Writer rather than an OutputStream to generate an XML document. However, because the Writer class has no standard method of determining what encoding it's using, you should normally build your Writer from an OutputStream you control, which you chain to an OutputStreamWriter (rather than accepting a Writer of unknown provenance). This is the only way to ensure that the encoding declaration matches what you're actually outputting.

On the client side, the java.net.URLConnection class is needed to talk to XML-RPC and SOAP servers because it allows you to use the HTTP POST method. You can send the request just by writing the XML document representing the request onto the URLConnection's output stream, and then flushing. The response will return an XML document also. Future chapters will address the parsing of such response documents.

On the server side, Java servlets serve XML just as easily as they serve HTML. You simply have to remember to set the MIME media type of the response to text/xml and include an encoding in the MIME type if you want anything other than Latin-1. You write the XML document onto the servlet's OutputStream just as you'd write an HTML document. There's really nothing special about servlets in this respect, other than that this is a book about Java. Similar techniques work for CGIs written in C, AppleScript, or Perl or for other server-side programming environments such as ASP and PHP.

    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
    Chapter 1. XML for Data
    Chapter 2. XML Protocols: XML-RPC and SOAP
    Chapter 3. Writing XML with Java
    Fibonacci Numbers
    Writing XML
    Output Streams, Writers, and Encodings
    A Simple XML-RPC Client
    A Simple SOAP Client
    Servlets
    Summary
    Chapter 4. Converting Flat Files to XML
    Chapter 5. Reading XML
    Part II: SAX
    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