XQuery
by Priscilla Walmsley
Copyright 2016 Priscilla Walmsley. All rights reserved.
Printed in the United States of America.
Published by OReilly Media, Inc. , 1005 Gravenstein Highway North, Sebastopol, CA 95472.
OReilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://safaribooksonline.com). For more information, contact our corporate/institutional sales department: 800-998-9938 or corporate@oreilly.com .
- Editor: Meg Foley
- Production Editor: Shiny Kalapurakkel
- Copyeditor: Nan Reinhardt
- Proofreader: Sonia Saruba
- Indexer: Priscilla Walmsley
- Interior Designer: David Futato
- Cover Designer: Karen Montgomery
- Illustrator: Rebecca Demarest
- March 2007: First Edition
- December 2015: Second Edition
Revision History for the Second Edition
- 2015-11-30: First Release
See http://oreilly.com/catalog/errata.csp?isbn=9781491915103 for release details.
The OReilly logo is a registered trademark of OReilly Media, Inc. XQuery, the cover image, and related trade dress are trademarks of OReilly Media, Inc.
While the publisher and the author have used good faith efforts to ensure that the information and instructions contained in this work are accurate, the publisher and the author disclaim all responsibility for errors or omissions, including without limitation responsibility for damages resulting from the use of or reliance on this work. Use of the information and instructions contained in this work is at your own risk. If any code samples or other technology this work contains or describes is subject to open source licenses or the intellectual property rights of others, it is your responsibility to ensure that your use thereof complies with such licenses and/or rights.
978-1-491-91510-3
[LSI]
Preface
This book provides complete coverage of the W3C XQuery 3.1 standard. In addition, it provides the background knowledge in namespaces, schemas, built-in types, and regular expressions that is relevant to writing XML queries.
This book is designed for query writers who have some knowledge of XML basics but not necessarily advanced knowledge of XML-related technologies. It can be used as a tutorial, by reading it cover to cover, and as a reference, by using the comprehensive index and appendixes.
Warning
As of the date of publication of this book, XQuery 3.1 is a Candidate Recommendation. No significant changes are expected, but there may be small differences between this book and the specification. These will be documented in detail as errata at http://www.datypic.com/books/xquery/.
Contents of This Book
The book is organized into six parts:
Chapters provide a high-level overview and quick tour of XQuery.
Chapters provide enough information to write sophisticated queries, without being bogged down by the details of types, namespaces, and schemas.
Chapters introduce some advanced concepts for users who want to take advantage of modularity, namespaces, typing, and schemas.
Chapters provide guidelines for working with specific types of data, such as numbers, strings, dates, URIs, processing instructions, and maps.
Chapters describe XQuerys implementation-specific features and its relationship to other standards, including SQL and XSLT.
Appendices provide a complete alphabetical reference to the built-in functions, types, and error messages.
Reading the Syntax Diagrams
illustrates the components of a syntax diagram, showing the schema import syntax as an example.
Figure P-1. Example syntax diagram
Rules for interpreting the syntax diagrams are:
Parts of the diagram in constant width
font are literal values. In , import schema
and at
should appear literally in your query.
Quotes that appear in syntax diagrams also must appear in your query. shows that the <
namespace-name
>
must be surrounded by quotes, whereas the <
prefix
>
must not. Either single or double quotes can be used in XQuery, but only double quotes are included in the diagrams for simplicity.
Where you can specify a value, such as a name, a descriptive name for that value appears in constant width italic and is surrounded by angle brackets. shows that you fill in the <
namespace-name
>
, <
prefix
>
, and <
location
>
with your own values.
Multiple options are indicated by parallel lines in the diagram. shows that you may choose to specify a namespace prefix or default element namespace
.
Optional parts of the expression are indicated by a line that bypasses the main arrow. In , it is not necessary to include the namespace <
prefix
> =
or the default element namespace
keywords.
Repeating parts of an expression are indicated by an arrow that returns to the beginning. shows that you can specify multiple <
location
>
s (separated by commas) as part of the at
clause.
Conventions Used in This Book
Constant width
is used for:
Code examples and fragments
Anything that might appear in an XML document, including element and attribute names, element contents, attribute values, and processing instructions
Anything that might appear in a query, including keywords, operators, and literals
Constant width bold
is used for:
Italic is used for:
New terms where they are defined
Emphasis in body text
Pathnames, filenames, and program names
Host and domain names
Warning
This icon indicates a warning or caution.
The numbered examples in this book are self-sufficient and contain all the necessary declarations to run them independently. When they use functionality that is only available in XQuery 3.0 or 3.1, they contain a version declaration to indicate this. Other (non-numbered) examples appear as code fragments that may not be able to run independently because, for example, they are dependent on a variable that is defined elsewhere. These code fragments are placed into a separate paragraph like this:
for $prod
as element(*, ProductType)
in doc("catalog.xml")/catalog/*return $prod/name
Using Code Examples
Supplemental material (code examples, exercises, etc.) is available for download at http://www.datypic.com/books/xquery/examples.html.
This book is here to help you get your job done. In general, you may use the code in this book in your programs and documentation. You do not need to contact us for permission unless youre reproducing a significant portion of the code. For example, writing a query that uses several chunks of code from this book does not require permission. Selling or distributing a CD-ROM of examples from OReilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your products documentation does require permission.