Sams Teach Yourself XML in 21 Days
Total Page:16
File Type:pdf, Size:1020Kb
Steven Holzner Teach Yourself XML in 21 Days THIRD EDITION 800 East 96th Street, Indianapolis, Indiana, 46240 USA Sams Teach Yourself XML in 21 Days, ASSOCIATE PUBLISHER Michael Stephens Third Edition ACQUISITIONS EDITOR Copyright © 2004 by Sams Publishing Todd Green All rights reserved. No part of this book shall be reproduced, stored in a retrieval DEVELOPMENT EDITOR system, or transmitted by any means, electronic, mechanical, photocopying, record- Songlin Qiu ing, or otherwise, without written permission from the publisher. No patent liability MANAGING EDITOR is assumed with respect to the use of the information contained herein. Although every precaution has been taken in the preparation of this book, the publisher and Charlotte Clapp author assume no responsibility for errors or omissions. Nor is any liability assumed PROJECT EDITOR for damages resulting from the use of the information contained herein. Matthew Purcell International Standard Book Number: 0-672-32576-4 INDEXER Library of Congress Catalog Card Number: 2003110401 Mandie Frank PROOFREADER Printed in the United States of America Paula Lowell First Printing: October 2003 TECHNICAL EDITOR 06050403 4321 Chris Kenyeres Trademarks TEAM COORDINATOR Cindy Teeters All terms mentioned in this book that are known to be trademarks or service marks have been appropriately capitalized. Sams Publishing cannot attest to the accuracy INTERIOR DESIGNER of this information. Use of a term in this book should not be regarded as affecting Gary Adair the validity of any trademark or service mark. COVER DESIGNER Warning and Disclaimer Gary Adair PAGE LAYOUT Every effort has been made to make this book as complete and as accurate as possi- ble, but no warranty or fitness is implied. The information provided is on an “as is” Michelle Mitchell basis. The author and the publisher shall have neither liability nor responsibility to any person or entity with respect to any loss or damages arising from the informa- tion contained in this book. Bulk Sales Sams Publishing offers excellent discounts on this book when ordered in quantity for bulk purchases or special sales. For more information, please contact U.S. Corporate and Government Sales 1-800-382-3419 [email protected] For sales outside of the U.S., please contact International Sales 1-317-428-3341 [email protected] Contents at a Glance Introduction 1 Part I Creating XML Documents 7 Day 1 Welcome to XML 9 2 Creating XML Documents 43 3 Creating Well-Formed XML Documents 77 4 Creating Valid XML Documents: DTDs 107 5 Handling Attributes and Entities in DTDs 141 6 Creating Valid XML Documents: XML Schemas 179 7 Creating Your Own Types in XML Schemas 207 Part I In Review 239 Part II Formatting XML Documents 247 Day 8 Formatting XML by Using Cascading Style Sheets 249 9 Formatting XML by Using XSLT 285 10 Working with XSL Formatting Objects 331 Part II In Review 371 Part III XML at Work 379 Day 11 Extending HTML with XHTML 381 12 Putting XHTML to Work 419 13 Creating Graphics and Multimedia: SVG and SMIL 449 14 Handling XLinks, Xpointer, and XForms 485 Part III In Review 521 Part IV Programming and XML 529 Day 15 Using JavaScript and XML 531 16 Using Java and .NET: DOM 567 17 Using Java and .NET: SAX 607 18 Working with SOAP and RDF 645 Part IV In Review 683 Part V Data Handling and XML 691 Day 19 Handling XML Data Binding 693 20 Working with XML and Databases 727 21 Handling XML in .NET 765 Part V In Review 801 Appendix A Answers to Quiz Questions 807 Index 817 Table of Contents Introduction 1 PART I At a Glance 7 DAY 1 Welcome to XML 9 All About Markup Languages ..............................................................................10 All About XML ....................................................................................................12 Looking at XML in a Browser ............................................................................17 Working with XML Data Yourself ......................................................................20 Structuring Your Data ..........................................................................................24 Creating Well-Formed XML Documents ............................................................24 Creating Valid XML Documents ..........................................................................25 How XML Is Used in the Real World ..................................................................26 Using XML: Mathematical Markup Language ..............................................27 Using XML: Chemical Markup Language ....................................................28 Using XML: Synchronized Multimedia Integration Language ......................29 Using XML: XHTML ....................................................................................30 Using XML: HTML+TIME ............................................................................32 Using XML: Microsoft’s .NET ......................................................................33 Using XML: Scalable Vector Graphics ..........................................................35 Using XML: SOAP ........................................................................................36 Online XML Resources ........................................................................................37 Summary ..............................................................................................................40 Q&A ......................................................................................................................41 Workshop ..............................................................................................................41 Quiz ................................................................................................................41 DAY 2 Creating XML Documents 43 Choosing an XML Editor ....................................................................................44 Using XML Browsers ..........................................................................................46 Using XML in Internet Explorer ....................................................................47 Using XML in Netscape Navigator ................................................................47 Using CML in Jumbo ......................................................................................48 Using XML Validators ..........................................................................................48 Creating XML Documents Piece by Piece ..........................................................51 Character Encodings: ASCII, Unicode, and UCS ..........................................52 Understanding XML Markup and XML Data ................................................55 Using Whitespace and Ends of Lines ............................................................57 Creating Prologs ..................................................................................................58 vi Sams Teach Yourself XML in 21 Days, Third Edition Creating an XML Declaration ..............................................................................59 Creating XML Comments ....................................................................................60 Creating Processing Instructions ..........................................................................62 Creating Tags and Elements ................................................................................63 Creating Tag Names ........................................................................................63 Creating Empty Elements ................................................................................64 Creating a Root Element ................................................................................64 Creating Attributes ..........................................................................................65 Creating CDATA Sections ....................................................................................70 Handling Entities ..................................................................................................73 Summary ..............................................................................................................74 Q&A ......................................................................................................................74 Workshop ..............................................................................................................75 Quiz ................................................................................................................75 DAY 3 Creating Well-Formed XML Documents 77 What Makes an XML Document Well-Formed? ................................................78 Matching the Production Labeled document ..................................................79 Meeting the Well-Formedness Constraints ....................................................80 Making Parsed Entity Must Be Well-Formed ................................................80 Creating an Example XML Document ................................................................80 Understanding the Well-Formedness Constraints ................................................84 Beginning the Document with an XML Declaration ......................................84 Using Only Legal Character References ........................................................85 Including at Least One Element ......................................................................85 Structuring Elements Correctly ......................................................................85