Beginning XML with DOM and Ajax from Novice to Professional
Total Page:16
File Type:pdf, Size:1020Kb
6765FM.qxd 5/19/06 11:03 AM Page i Beginning XML with DOM and Ajax From Novice to Professional Sas Jacobs 6765FM.qxd 5/19/06 11:03 AM Page ii Beginning XML with DOM and Ajax: From Novice to Professional Copyright © 2006 by Sas Jacobs All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher. ISBN-13 (pbk): 978-1-59059-676-0 ISBN-10 (pbk): 1-59059-676-5 Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1 Trademarked names may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. Lead Editors: Charles Brown, Chris Mills Technical Reviewer: Allan Kent Editorial Board: Steve Anglin, Ewan Buckingham, Gary Cornell, Jason Gilmore, Jonathan Gennick, Jonathan Hassell, James Huddleston, Chris Mills, Matthew Moodie, Dominic Shakeshaft, Jim Sumser, Keir Thomas, Matt Wade Project Manager: Beth Christmas Copy Edit Manager: Nicole LeClerc Copy Editor: Nicole Abramowitz Assistant Production Director: Kari Brooks-Copony Production Editor: Kelly Winquist Compositor: Dina Quan Proofreader: Dan Shaw Indexer: Brenda Miller Artist: Kinetic Publishing Services, LLC Cover Designer: Kurt Krames Manufacturing Director: Tom Debolski Distributed to the book trade worldwide by Springer-Verlag New York, Inc., 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax 201-348-4505, e-mail [email protected], or visit http://www.springeronline.com. For information on translations, please contact Apress directly at 2560 Ninth Street, Suite 219, Berkeley, CA 94710. Phone 510-549-5930, fax 510-549-5939, e-mail [email protected], or visit http://www.apress.com. The information in this book is distributed on an “as is” basis, without warranty. Although every precaution has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indi- rectly by the information contained in this work. The source code for this book is available to readers at http://www.apress.com in the Source Code section. 6765FM.qxd 5/19/06 11:03 AM Page iii Contents at a Glance About the Author . xiii About the Technical Reviewer . xv Acknowledgments . xvii Introduction . xix ■CHAPTER 1 Introduction to XML . 1 ■CHAPTER 2 Related XML Recommendations . 21 ■CHAPTER 3 Web Vocabularies . 53 ■CHAPTER 4 Client-Side XML . 99 ■CHAPTER 5 Displaying XML Using CSS . 121 ■CHAPTER 6 Introduction to XSLT . 169 ■CHAPTER 7 Advanced Client-Side XSLT Techniques . 191 ■CHAPTER 8 Scripting in the Browser . 225 ■CHAPTER 9 The Ajax Approach to Browser Scripting . 265 ■CHAPTER 10 Using Flash to Display XML . 293 ■CHAPTER 11 Introduction to Server-Side XML . 317 ■CHAPTER 12 Case Study: Using .NET for an XML Application . 349 ■CHAPTER 13 Case Study: Using PHP for an XML Application . 381 ■INDEX . 417 iii 6765FM.qxd 5/19/06 11:03 AM Page iv 6765FM.qxd 5/19/06 11:03 AM Page v Contents About the Author . xiii About the Technical Reviewer . xv Acknowledgments . xvii Introduction . xix ■CHAPTER 1 Introduction to XML . 1 What Is XML? . 2 A Brief History of XML . 2 The Goals of XML . 3 Understanding XML Syntax . 4 Well-Formed Documents . 4 Understanding the Difference Between Tags and Elements . 5 Viewing a Complete XML Document . 6 Understanding the Structure of an XML Document . 7 Naming Rules in XML . 8 Understanding the XML Document Prolog . 9 Understanding Sections Within the XML Document Element . 11 The XML Processing Model . 16 XML Processing Types . 17 DOM Parsing . 17 SAX Parsing . 17 Why Have Two Processing Models? . 18 Some XML Tools . 18 Summary . 19 ■CHAPTER 2 Related XML Recommendations . 21 Understanding the Role of XML Namespaces . 21 Adding Namespaces to XML Documents . 23 Adding Default Namespaces . 23 v 6765FM.qxd 5/19/06 11:03 AM Page vi vi ■CONTENTS Defining XML Vocabularies . 24 The Document Type Definition . 25 XML Schema . 29 Comparing DTDs and Schemas . 36 Other Schema Types . 37 XML Vocabularies . 37 Displaying XML . 38 XML and CSS . 39 XSL . 39 XPath . 44 XPath Expressions . 45 Identifying Specific Nodes . 46 Including Calculations and Functions . 46 XPath Summary . 47 Linking with XML . 47 Simple Links . 48 Extended Links . 49 XPointer . 50 XML Links Summary . 51 Summary . 51 ■CHAPTER 3 Web Vocabularies . 53 XHTML . 53 Separation of Presentation and Content . 54 XHTML Construction Rules . 56 XHTML Tools . 66 Well-Formed and Valid XHTML Documents . 67 XHTML Modularization . ..