Thư viện tri thức trực tuyến
Kho tài liệu với 50,000+ tài liệu học thuật
© 2023 Siêu thị PDF - Kho tài liệu học thuật hàng đầu Việt Nam

Tài liệu Querying XML, : XQuery, XPath, and SQL/XML in context pptx
Nội dung xem thử
Mô tả chi tiết
Querying XML
XQuery, XPath, and SQUXML
in Context
The Morgan Kaufmann Series in Data Management Systems
Series Editor: Jim Gray, Microsoft Research
Querying XML: XQuery, XPath, and SQL/XML in
Context
Jim Melton and Stephen Buxton
Data Mining: Concepts and Techniques, Second
Edition
Jiawei Han and Micheline Kamber
Database Modeling and Design: Logical Design,
Fourth Edition
Toby J, Teorey, Sam S. Lightstone and Thomas E
Nadeau
Foundations of Muhidimensional and Metric Data
Structures
Hanan Samet
Joe Celko's SQL for Smarties: Advanced SQL
Programming, Third Edition
Joe Celko
Moving Objects Databases
Ralf Hartmut G~iting and Markus Schneider
Joe Celko's SQL Programming Style
Joe Celko
Data Mining, Second Edition: Concepts and
Techniques
Ian Witten and Eibe Frank
Fuzzy Modeling and Genetic Algorithms for Data
Mining and Exploration
Earl Cox
Data Modeling Essentials, Third Edition
Graeme C. Simsion and Graham C. Witt
Transactional Information Systems: Theory,
Algorithms, and Practice of Concurrency Control and
Recovery
Gerhard Weikum and Gottfried Vossen
Spatial Databases: ~th Application to GIS
Philippe Rigaux, Michel Scholl, and Agnes Voisard
Information Modeling and Relational Databases:
From Conceptual Analysis to Logical Design
Terry Halpin
Component Database Systems
Edited by Klaus R. Dittrich and Andreas Geppert
Managing Reference Data in Enterprise Databases:
Binding Corporate Data to the Wider World
Malcolm Chisholm
Understanding SQL and Java Together: A Guide to
SQLJ, JDBC, and Related Technologies
Jim Melton and Andrew Eisenberg
Database: Principles, Programming, and Performance,
Second Edition
Patrick and Elizabeth O'Neil
The Object Data Standard: ODMG 3.0
Edited by R. G. G. Cattell and Douglas K. Barry
Data on the Web: From Relations to Semistructured
Data and XML
Serge Abiteboul, Peter Buneman, and Dan Suciu
Data Mining: Practical Machine Learning Tools and
Techniques with Java Implementations
Ian Witten and Eibe Frank
Understanding SQL's Stored Procedures: A Complete
Guide to SQL/PSM
Jim Melton
Principles of Muhimedia Database Systems
V. S. Subrahmanian
Principles of Database Query Processing for Advanced
Applications
Clement T. Yu and Weiyi Meng
Advanced Database Systems
Carlo Zaniolo, Stefano Ceri, Christos Faloutsos,
Richard T. Snodgrass, V. S. Subrahmanian, and
Roberto Zicari
Principles of Transaction Processing
Philip A. Bernstein and Eric Newcomer
Using the New DB2: IBMs Object-Relational
Database System
Don Chamberlin
Distributed Algorithms
Nancy A. Lynch
Active Database Systems: Triggers and Rules For
Advanced Database Processing
Edited by Jennifer Widom and Stefano Ceri
Migrating Legacy Systems: Gateways, Inte~aces, & the
Incremental Approach
Michael L. Brodie and Michael Stonebraker
Atomic Transactions
Nancy Lynch, Michael Merritt, William Weihl, and
Alan Fekete
Location-Based Services
Jochen Schiller and Agn& Voisard
Database Modeling with Micros~" Visio for Enterprise
Architects
Terry Halpin, Ken Evans, Patrick Hallock, Bill
Maclean
Designing Data-Intensive Web Applications
Stephano Ceri, Piero Fraternali, Aldo Bongio,
Marco Brambilla, Sara Comai, and Maristella
Matera
Mining the Web: Discovering Knowledge from
Hypertext Data
Soumen Chakrabarti
Advanced SQL: 1999--Understanding ObjectRelational and Other Advanced Features
Jim Melton
Database Tuning: Principles, Experiments, and
Troubleshooting Techniques
Dennis Shasha and Philippe Bonnet
SQL:1999--Understanding Relational Language
Components
Jim Melton and Alan R. Simon
Information Visualization in Data Mining and
Knowledge Discovery
Edited by Usama Fayyad, Georges G. Grinstein,
and Andreas Wierse
Joe Celko's SQL for Smarties: Advanced SQL
Programming, Second Edition
Joe Celko
Joe Celko's Data and Databases: Concepts in Practice
Joe Celko
Developing 7~me-Oriented Database Applications in
SQZ
Richard T. Snodgrass
Web Farming for the Data Warehouse
Richard D. Hackathorn
Management of Heterogeneous and Autonomous
Database Systems
Edited by Ahmed Elmagarmid, Marek
Rusinkiewicz, and Amit Sheth
Object-Relational DBMSs: Tracking the Next Great
Wave, Second Edition
Michael Stonebraker and Paul Brown,with Dorothy
Moore
A Complete Guide to DB2 Universal Database
Don Chamberlin
Universal Database Management: A Guide to Object/
Relational Technology
Cynthia Maro Saracco
Readings in Database Systems, Third Edition
Edited by Michael Stonebraker and Joseph M.
Hellerstein
Query Processing for Advanced Database Systems
Edited by Johann Christoph Freytag, David Maier,
and Gottfried Vossen
Transaction Processing: Concepts and Techniques
Jim Gray and Andreas Reuter
Building an Object-Oriented Database System: The
Story of 02
Edited by Fram;ois Bancilhon, Claude Delobel, and
Paris Kanellakis
Database Transaction Models for Advanced
Applications
Edited by Ahmed K. Elmagarmid
A Guide to Developing Client~Server SQL
Applications
Setrag Khoshafian, Arvola Chan, Anna Wong, and
Harry K. T. Wong
The Benchmark Handbook for Database and
Transaction Processing Systems, Second Edition
Edited by Jim Gray
Camelot and Avalon: A Distributed Transaction
Facility
Edited by Jeffrey L. Eppinger, Lily B. Mummert,
and Alfred Z. Spector
Readings in Object-Oriented Database Systems
Edited by Stanley B. Zdonik and David Maier
Querying XML
XQuery, XPath, and SQL/XML
in Context
Jim Melton
and
Stephen Buxton
ELSEVIER
Amsterdam 9 Boston
Heidelberg 9 London
New York 9 Oxford 9 Paris
San Diego. San Francisco
Singapore 9 Sydney 9 Tokyo MORGAN KAUFMANN PUBLISHERS
Publisher
Publishing Services Manager
Editorial Assistant
Cover Design
Cover Image
Composition
Technical Illustration
Copyeditor
Proofreader
Indexer
Interior printer
Cover printer
Diane Cerra
Simon Crump
Asma Stephan
Ross Carron Design
OJavier Pierini/Digital Images/Getty Images
Multiscience Press
Dartmouth Publishing, Inc.
Elliot Simon
Jacqui Brownstein
Northwind Editorial Services
Maple-Vail Book Manufacturing Group
Phoenix Color
Morgan Kaufmann Publishers is an imprint of Elsevier.
500 Sansome Street, Suite 400, San Francisco, CA 94111
This book is printed on acid-free paper.
9 2006 by Elsevier Inc. All rights reserved.
Designations used by companies to distinguish their products are often claimed as trademarks or registered
trademarks. In all instances in which Morgan Kaufmann Publishers is aware of a claim, the product names appear
in initial capital or all capital letters. Readers, however, should contact the appropriate companies for more
complete information regarding trademarks and registration.
No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or by any
means-electronic, mechanical, photocopying, scanning, or otherwise-without prior written permission of the
publisher.
Permissions may be sought directly from Elsevier's Science & Technology Rights Department in Oxford, UK:
phone: (+44) 1865 84383O, fax: (+44) 1865 853333,
e-mail: [email protected]. You may also complete your request on-line via the Elsevier homepage
(http://elsevier.com) by selecting "Customer Support" and then "Obtaining Permissions."
Library of Congress Cataloging-in-Publication Data
Application submitted
ISBN 13:978-1-55860-711-8
ISBN 10:1-55860-711-0
For information on all Morgan Kaufmann publications,
visit our Web site at www.mkp.com or www.books.elsevier.com
Printed in the United States of America
06 07 08 09 10 5 4 3 2 1
To rescued Shelties, and Shelties in need of rescue, everywhere. Especially
to senior Shelties who, after years of devotion to their owners, are cruelly
discarded for the most pathetic of reasons: "We're thinking about
moving", "She's just in the way", "He's too old to be fun any more", and
the worst of all - "We're getting a puppy and, you know...". And to the
loving people who welcome these old dogs into their lives, knowing that
older Shelties are calmer, settled, cuddly, and devoted - they selflessly
deal with medical needs, arthritic limitations, and the piddles of old age.
Wonderful karma accrues to these people for giving these seniors love
and respect, allowing them to live out their lives in comfort and
happiness.
Jim
To my Mum and Dad, for their long, long journey.
Stephen
This Page Intentionally Left Blank
Contents
Foreword
Preface
Why the subject matter is important xix
Why we wrote this book xx
Who should read this book xxi
How the book is organized xxi
The example we're using xxiii
Syntax Conventions xxiii
9 Additional resources xxv
9 Type conventions xxv
9 Acknowledgements xxv
Part I XML: Documents and Data
Chapter I XML
I. I Introduction 3
1.2 Adding Markup to Data 3
1.2. I Raw Data 4
1.2.2 Separating Fields 4
1.2.3 Grouping Fields Together 5
1.2.4 Naming Fields 6
1.2.5 A Structural Map of the Data 8
1.2.6 Markup and Meaning 12
1.2.7 Why XML? 13
1.3 XML-Based Markup Languages 14
1.4 XML Data 19
1.4.1 Structured Data 19
1.4.2 Unstructured Data 20
xvii
xix
vii
viii Contents
1.5
1.6
1.4.3 Messages 20
1.4.4 XML Data ~ Summary 20
Some Other Ways to Represent Data 21
1.5. I SQL ~ Structure Only 21
1.5.2 Presentation Languages ~ Presentation Only 24
1.5.3 SGML 26
1.5.4 HTML 27
Chapter Summary 28
Chapter 2 Querying
2.1
2.2
2.3
2.4
Introduction 31
2. I. I Definitions of Query 3 I
Querying Traditional Data 32
2.2. I The Relational Model and SQL 33
2.2.2 Extensions to SQL 36
2.2.3 Querying Traditional Data ~ Summary 38
Querying Nontraditional Data 39
2.3. I Metadata 40
2.3.2 Objects 41
2.3.3 Markup 41
2.3.4 Querying Content 43
Chapter Summary 43
Chapter 3 Querying XML
3. I Introduction 45
3.2 Navigating an XML Document 46
3.2. I Walking the XML Tree 48
3.2.2 Some Additional Wrinkles 56
3.2.3 Summary ~Things to Consider 60
3.3 What DoYou Know about Your Data? 61
3.4 SomeWays to Query XMLToday 63
3.5 Chapter Summary 64
Part II Metadata and XML
Chapter 4 Metadata-- An Overview
4.1
4.2
4.3
4.4
Introduction 67
Structural Metadata 69
Semantic Metadata 75
Catalog Metadata 78
31
45
65
67
Contents ix
Chapter 5
Chapter 6
4.5
4.6
Integration Metadata 82
Chapter Summary 84
Structural Metadata
5.1
5.2
5.3
5.4
5.5
5.6
85
Introduction 85
DTDs 86
5.2.1 SGML Heritage 87
5.2.2 Relatively Simple, Easy to Write, and Easy to Read 88
5.2.3 Limited Capabilities, Especially with Respect to Data Types 94
5.2.4 An Example Document and DTD 97
XML Schema 100
5.3. I Exploring an XML Schema 101
5.3.2 Simple Types (Primitive Types and Derived Types) 107
5.3.3 Complex Types and Structures 110
Other Schema Languages for XML II 5
5.4.1 RELAX NG 115
5.4.2 Schematron 117
5.4.3 Decisions, Decisions, Decisions 118
Deriving an Implied Schema from a DTD II 9
Chapter Summary 120
The XML Information Set (Infoset)
and Beyond
6.1
6.2
6.3
6.4
6.5
6.6
6.7
6.8
6.9
123
Introduction 123
What Is the Infoset? 124
The Infoset Information Items and Their Properties 125
The Infoset vs.the Document 133
The XPath 1.0 Data Model 136
The Post-Schema-Validation Infoset (PSVI) 138
6.6. I Infoset + Additional Properties and Information Items 139
6.6.2 Additional Information in the PSVI 140
6.6.3 Limitations of the PSVI 141
6.6.4 Visualizing the PSVI 142
The Document Object Model (DOM)~An API 142
Introducing the XQuery Data Model 146
A Note Regarding Data Model Terminology 147
6.10 Chapter Summary and Further Reading 149
x Contents
Part III Managing and Storing XML for Querying 151
Chapter 7 Managing XML: Transforming and Connecting 153
7.1
7.2
7.3
7.4
7.5
Introduction 153
Transforming, Formatting, and Displaying XML 154
7.2. I Extensible Stylesheet Language Transformations (XSLT) 155
7.2.2 Extensible Stylesheet Language: Formatting
Objects (XSL FO) 162
The Relationships between XML Documents 163
7.3.1 XML Inclusions (Xlnclude) 164
7.3.2 XML Pointer Language (XPointer) 168
7.3.3 XML Linking Language (XLink) 173
Relationship Constraints: Enforcing Consistency 185
Chapter Summary 191
Chapter 8 Storing: XML and Databases
8. I Introduction 193
8.2 The Need for Persistence 194
8.2. I Databases 195
8.2.2 Other Persistent Media 200
8.2.3 ShreddingYour Data 20 I
8.3 SQL/XML's XMLType 206
8.4 Accessing Persistent XML Data 207
8.5 XML on the Fly: Nonpersistent XML Data 209
8.6 Chapter Summary 21 I
193
Part IV Querying XML 213
Chapter 9 XPath 1.0 and XPath 2.0
9.1
9.2
9.3
9.2.1
9.2.2
9.2.3
9.2.4
9.2.5
9.2.6
9.2.7
9.2.8
Introduction 215
XPath 1.0 217
Expressions 218
Contexts 222
Paths and Steps 224
Axes and Shorthand Notations 228
Node Tests 239
Predicates 241
XPath Functions 243
Putting the Pieces Together 248
XPath 2.0 Components 252
215
Contents xi
9.4
9.5
9.3.1 Expressions 252
9.3.2 The for and return Expressions 256
XPath 2.0 and XQuery 1.0 258
Chapter Summary 259
Chapter I0 Introduction to XQuery 1.0
10.1 Introduction 261
10.2 A Brief History 262
10.3 Requirements 264
10.3.1 General Requirements for XQuery 266
10.3.2 Data Model Requirements 267
10.3.3 XQuery Functionality Requirements 268
10.3.4 XPath 2.0 Requirements 269
10.4 Use Cases 269
10.5 The XQuery 1.0 Suite of Specifications 275
10.5.1 XQuery 1.0 Language Specification 276
10.5.2 XPath 2.0 and XQuery 1.0 Formal Semantics 278
10.5.3 XPath 2.0 and XQuery 1.0 Functions & Operators 278
10.5.4 XQuery 1.0 Serialization 279
10.5.5 XQueryX 280
10.6 The Data Model 280
10.6.1 Data Model Instances 282
10.6.2 What Is an XQuery Data Model Instance? 283
10.6.3 The Seven Kinds of Nodes 284
10.6.4 The Data Model as Tree- Representing aWelI-Formed
Document 293
10.6.5 The Data Model as Sequence- Representing an
Arbitrary Sequence 295
10.7 The XQueryType System 297
10.7. I What Is a Type System Anyway? 297
10.7.2 XML SchemaTypes 300
10.7.3 From XML Schema to the XQueryType System 304
10.7.4 Types and Queries 305
10.8 XQuery 1.0 Formal Semantics and Static Typing 306
10.8.1 Notations 307
10.8.2 Static Typing 31 I
10.8.3 Dynamic Semantics 312
10.9 Functions and Operators 313
10.9.1 Functions 313
10.9.2 Operators 316
10.10 XQuery 1.0 and XSLT 2.0 Serialization 319
261
xii Contents
10.10.1 XML Output Method 322
10.10.2 XHTML Output Method 325
10.10.3 HTML Output Method 326
10.10.4 Text Output Method 327
10.1 I Chapter Summary 327
Chapter II XQuery 1.0 Definition
I I.I Introduction 329
11.2 Overview of XQuery 330
11.2.1 Concepts 330
11.3 The XQuery Processing Model 333
11.3.1 The Static Context 334
11.3.2 The Dynamic Context 337
11.4 The XQuery Grammar 338
11.5 XQuery Expressions 339
I 1.5.1 Literal Expressions 341
11.5.2 Constructor Functions 342
11.5.3 Sequence Constructors 343
11.5.4 Variable References 345
11.5.5 Parenthesized Expressions 346
11.5.6 Context Item Expression 346
11.5.7 Function Calls 346
11.5.8 Filter Expressions 349
11.5.9 Node Sequence-Combining Expressions 349
I 1.5.10 Arithmetic Expressions 35 I
11.5. II Boolean Expressions: Comparisons and Logical
Operators 354
I 1.5.12 Constructors ~ Direct and Computed 361
11.5.13 Ordered and Unordered Expressions 370
I 1.5.14 Conditional Expression 371
I 1.5.15 Quantified Expressions 372
I 1.5.16 Expressions on XQueryTypes 374
I 1.5.17 Validation Expression 378
11.6 FLWOR Expressions 380
11.6.1 The for Clause and the let Clause 380
11.6.2 The where Clause 389
11.6.3 The order by Clause 390
11.6.4 The return Clause 392
11.7 Error Handling 393
11.8 Modules and Query Prologs 394
11.8.1 Prologs 395
329
Contents xiii
11.8.2 Main Modules 398
11.8.3 Library Modules 400
11.9 A Longer Example with Data 402
II. 10 XQuery for SQL Programmers 402
I1.11 Chapter Summary 403
Chapter 12 XQueryX
12.1 Introduction 407
12.2 How Far to Go? 408
12.2.1 Trivial Embedding 409
12.2.2 Fully-Parsed XQuery 410
12.2.3 The XQueryXApproach 41 I
12.3 The XQueryX Specification 416
12.4 XQueryX By Example 417
12.4.1 The Simplest XQueryX Example ~ 42 417
12.4.2 Simple XQueryX Example 423
12.4.3 Useful XQuery Example 430
12.5 Querying XQueryX 433
12.5. I Querying XQueryX for XQueryTuning 434
12.5.2 Querying XQueryX for Application Improvement 436
12.6 Chapter Summary 437
Chapter 13 What's Missing?
13.1
13.2
13.3
Introduction 439
Full-Text 440
13.2. I What Is a Full-Text Query? 440
13.2.2 Full-Text and XML 448
13.2.3 Defining XQuery Full-Text 449
13.2.4 W3C XQuery Full-Text ~ Grammar Extension 455
13.2.5 W3C XQuery Full-Text ~ Some Discussion Topics 471
13.2.6 XQuery Full-Text ~ Some Implementations 474
Update 478
13.3. I Motivation:Where/WhyWe Need Update 479
13.3.2 Requirements 481
13.3.3 Alternatives: Syntax and Semantics 485
13.3.4 How Products Handle Update Today 488
13.3.5 What Lies Ahead? 495
13.4 Chapter Summary 495
407
439
xiv Contents
Chapter 14 XQuery APIs
14.1 Introduction 497
14.2 Alphabet-Soup Review 498
14.2.1 ODBC andJDBC 499
14.2.2 DOM, SAX, StAX, JAXP, JAXB 501
14.2.3 Alphabet-Soup Summary 502
14.3 XQJ ~ XQuery for Java 503
14.3.1 Connecting to a Data Source 504
14.3.2 Executing a Query 507
14.3.3 Manipulating XML Data 509
14.3.4 Static and Dynamic Context 517
14.3.5 Metadata 518
14.3.6 Summary 519
14.4 SQL/XML 520
14.5 Looking Ahead 521
Chapter 1 5 SQIL/XML
15.1 Introduction 523
15.2 SQL/XML Publishing Functions 526
15.2.1 Examples 526
15.2.2 XMLAGG 529
15.2.3 XMLFOREST 531
15.2.4 XMLCONCAT 535
15.2.5 Summary 536
15.3 XML DataType 537
15.4 XQuery Functions 540
15.4.1 XMLQUERY 541
15.4.2 XMLTABLE 546
15.4.3 XMLEXISTS 570
15.5 Managing XML in the Database 572
15.6 Talking the Same Language ~ Mappings 573
15.6.1 Character Sets 573
15.6.2 Names 574
15.6.3 Types andValues 575
15.7 Chapter Summary 580
Part V Querying and The World Wide Web
Chapter 16 XML-Derived Markup Languages
16.1 Introduction 585
16.2 Markup Languages 586
497
523
583
585