Querying XML Jim Melton, Stephen Buxton
2011, 2006, 2011-04-08
eBook
XML has become the lingua franca for representing business data, for exchanging information between business partners and applications, and for adding structure– and sometimes meaning—to text-based ...documents. XML offers some special challenges and opportunities in the area of search: querying XML can produce very precise, fine-grained results, if you know how to express and execute those queries.For software developers and systems architects: this book teaches the most useful approaches to querying XML documents and repositories. This book will also help managers and project leaders grasp how "querying XML? fits into the larger context of querying and XML. Querying XML provides a comprehensive background from fundamental concepts (What is XML?) to data models (the Infoset, PSVI, XQuery Data Model), to APIs (querying XML from SQL or Java) and more.* Presents the concepts clearly, and demonstrates them with illustrations and examples; offers a thorough mastery of the subject area in a single book. * Provides comprehensive coverage of XML query languages, and the concepts needed to understand them completely (such as the XQuery Data Model). * Shows how to query XML documents and data using: XPath (the XML Path Language); XQuery, soon to be the new W3C Recommendation for querying XML; XQuery's companion XQueryX; and SQL, featuring the SQL/XML * Includes an extensive set of XQuery, XPath, SQL, Java, and other examples, with links to downloadable code and data samples.
Querying XML Stephen Buxton; Jim Melton
04/2011
eBook
XML has become the lingua franca for representing business data, for exchanging information between business partners and applications, and for adding structure–and sometimes meaning—to text-based ...documents. XML offers some special challenges and opportunities in the area of search: querying XML can produce very precise, fine-grained results, if you know how to express and execute those queries.For software developers and systems architects: this book teaches the most useful approaches to querying XML documents and repositories. This book will also help managers and project leaders grasp how “querying XML fits into the larger context of querying and XML. Querying XML provides a comprehensive background from fundamental concepts (What is XML?) to data models (the Infoset, PSVI, XQuery Data Model), to APIs (querying XML from SQL or Java) and more.* Presents the concepts clearly, and demonstrates them with illustrations and examples; offers a thorough mastery of the subject area in a single book. * Provides comprehensive coverage of XML query languages, and the concepts needed to understand them completely (such as the XQuery Data Model).* Shows how to query XML documents and data using: XPath (the XML Path Language); XQuery, soon to be the new W3C Recommendation for querying XML; XQuery's companion XQueryX; and SQL, featuring the SQL/XML * Includes an extensive set of XQuery, XPath, SQL, Java, and other examples, with links to downloadable code and data samples.
This chapter explains structural metadata, document type definitions (or DTDs) and their role in adding value to Extensible Markup Language (XML) documents. It also explains XML Schema, the ...additional values that it provides, and other structural metadata specification languages and discusses several mechanisms that allow the specification of structural and data type metadata for XML documents. It is possible to describe the structure of that single document and some of the relationships between various parts of the data that it contains by simply parsing a single XML document,. When multiple documents conform to a single structural metadata definition, such as those covered in this chapter, it becomes possible to express meaningful queries across all of those documents. Such queries can depend on the documents' structural characteristics as well as the data contained in the documents. Other reasons for using structural metadata for XML documents include the ability to guarantee certain types of data integrity. The first form of explicit metadata that many people encounter is the Document Type Definition (DTD). The DTDs are in many ways less flexible and powerful than XML Schemas, but they are arguably easier to read and may suffice when more complex structures or specific data types are not required. DTDs were invented as a metadata description language for the Standard General Markup Language (SGML). An XML document that includes a document type declaration can be validated against the DTD provided by, or identified by, that declaration. DTDs are defined using markup declarations that come in several forms: element declarations, attribute list declarations, entity declarations, notation declarations, processing instruction declarations, and comments. However, there are several limitations associated with DTDs, which are also discussed.
This chapter focuses on XQuery, powerful language for querying XML and explains XQuery Data Model and the XQuery type system. The XQuery Data Model is one of the features that set XQuery apart from ...XPath 1.0 and XSLT 1.0. Every XQuery operates over an instance of the X-Query Data Model, and its result is an instance of the XQuery Data Model. The XQuery Data Model is at the core of the XQuery language because every XQuery has an instance of the Data Model as input and output. And the XQuery type system is at the core of the Data Model. The Data Model defines exactly what an XQuery processes and what it is expected to return as a result. The chapter gives a detailed description of the syntax and semantics of XQuery, the functions, operators, and the formal description of the semantics of the language. The Formal Semantics specification defines the static semantics of XQuery, particularly the rules for determining the static types of expressions. These static semantics are defined in a formal, mathematical manner, making XQuery one of relatively few languages to be defined so formally. There are also “XML Query Use Cases” that briefly describes a set of "usage scenarios" for XQuery, showing that XQuery is meant to apply in a very broad range of situations. The XPath 2.0 requirements are laid out in XPath Requirements Version 2.0. XQuery 1.0 includes XPath 2.0 as a subset of the language, so the XPath 2.0 requirements had a big influence on XQuery 1.0 requirements. XPath 2.0 extends the type system of XPath 1.0 considerably. XPath 1.0 has a simple type system in which every expression evaluates to one of four available types - node-set, Boolean, number, or string. By contrast, XPath 2.0 must support the data types and structure types defined by XML Schema.
This chapter introduces XQueryX, and XML syntax for X-Queries. XQueryX is an alternative syntax for the XQuery language, where a query is represented as a well-formed XML document. The XQueryX ...approach is to represent the parsed query, leaving out BNF steps that are not useful and treating expressions, operators, and literals in a special way. This leads to a relatively compact XML representation of an XQuery that is particularly useful for searching. Given the XQuery language, there are a number of ways to define XML syntax—that is, a way to represent any possible XQuery in XML). Hence, the chapter discusses two possible extremes : a trivial embedding and a fully parsed XQuery, some of the design features of XQueryX, and how the XQueryX spec defines XQueryX. The XQueryX spec notes a couple of other benefits of an XML representation of an XQuery: parser reuse and automatic query generation. The simplest way to represent the XQuery syntax as XML is just to wrap each query in a start tag and an end tag. The XQueryX specification defines XQueryX by providing an XML Schema, which defines the syntax of XQueryX, and a stylesheet, which defines the semantics. The Schema follows the XQuery grammar quite closely. One of the advantages of XML Schema over DTDs is that an XML Schema is an XML document, while a DTD is not. This turns out to be a very practical way to go about things — it really is useful to be able to treat an XML Schema, or an X-Query, as an XML document.
This chapter explores several ways in which Extensible Markup Language (XML) documents interact with their environments and the relation of these interactions with querying XML. Extensible Stylesheet ...Language Transformations (XSLT) arguably provides a type of XML querying capability, but it is specialized for transforming XML documents rather than specifically searching within documents or identifying documents within collections. Extensible Stylesheet Language Formatting Objects (XSL FO) is a formatting language and has nothing to do with querying XML, but it is very useful for publishing the results of queries in reader friendly formats. Its purpose is strictly to give instructions to a formatting engine on how to apply formatting to an XML document for display, XML Inclusions (XInclude) allows the modularization of XML documents and does so in a way that makes it possible to query the result of the merger of the various modules. XInclude, by contrast, provides a way of merging (the Infosets of) XML documents into a single XML document (that is, a single Infoset). XML Pointer Language (XPointer) can provide an IDREF-like capability through its shorthand pointers and its element scheme. Its Xpointer 0 scheme is an extension of XPath and is thus, powerful enough to easily be considered a tool for querying XML. XLink provides the ability to define sophisticated linkages between and among XML resources, but it offers very little in the form of querying XML documents. Until popular XML querying languages such as XPath and XQuery support the sort of relationships created through ID/IDREF-typed attributes and elements, through XPointer utilization, or through XLink capabilities, none of these will offer the same promise that SQUs referential constraint-based joins provide. The chapter concludes with relationship constraints in SQL, together referred to as “referential integrity constraints”, that provide a very powerful mechanism for enforcing consistency between the rows in one table and the rows in another.