Native Storage within a Relational Database
23.6.2.5 Native Storage within a Relational Database
Some relational databases support native storage of XML . Such systems store XML data as strings or in more efficient binary representations, without converting the data to relational form. A new data type xml is introduced to represent XML data, although the CLOB and BLOB data types may provide the underlying storage mechanism. XML query languages such as XP ath and XQ uery are supported to query XML data.
A relation with an attribute of type xml can be used to store a collection of XML documents; each document is stored as a value of type xml in a separate tuple. Special-purpose indices are created to index the XML data.
Several database systems provide native support for XML data. They provide an xml data type and allow XQ uery queries to be embedded within SQL queries. An XQ uery query can be executed on a single XML document and can be embedded within an SQL query to allow it to execute on each of a collection of documents, with each document stored in a separate tuple. For example, see Section 30.11 for more details on native XML support in Microsoft SQL S erver 2005.
1014 Chapter 23 XML
< university>
< department> < row>
< dept name> Comp. Sci. </dept name> < building> Taylor </building> < budget> 100000 </budget>
< /row> < row>
< dept name> Biology </dept name> < building> Watson </building> < budget> 90000 </budget>
< /row> < /department> < course>
< row>
< course id> CS-101 </course id> < title> Intro. to Computer Science </title> < dept name> Comp. Sci </dept name> < credits> 4 </credits>
< /row> < row>
< course id> BIO-301 </course id> < title> Genetics </title> < dept name> Biology </dept name> < credits> 4 </credits>
< /row> < course> < /university>
Figure 23.15 SQL/XML representation of (part of) university information.
23.6.3 SQL/XML
While XML is used widely for data interchange, structured data is still widely stored in relational databases. There is often a need to convert relational data to XML representation. The SQL/XML standard, developed to meet this need, defines
a standard extension of SQL , allowing the creation of nested XML output. The standard has several parts, including a standard way of mapping SQL types to XML S chema types, and a standard way to map relational schemas to XML schemas, as well as SQL query language extensions.
For example, the SQL/XML representation of the department relation would have an XML schema with outermost element department, with each tuple mapped to an XML element row, and each relation attribute mapped to an XML element of the same name (with some conventions to resolve incompatibilities with special characters in names). An entire SQL schema, with multiple relations, can also be mapped to XML in a similar fashion. Figure 23.15 shows the SQL/XML representa-
23.6 Storage of XML Data 1015
tion of (part of) the university data from 23.1, containing the relations department and course.
SQL/XML adds several operators and aggregate operations to SQL to allow the construction of XML output directly from the extended SQL . The xmlelement function can be used to create XML elements, while xmlattributes can be used to create attributes, as illustrated by the following query.
select xmlelement (name “course”, xmlattributes (course id as course id, dept name as dept name), xmlelement (name “title”, title), xmlelement (name “credits”, credits))
from course The above query creates an XML element for each course, with the course
identifier and department name represented as attributes, and title and credits as subelements. The result would look like the course elements shown in Fig- ure 23.11, but without the instructor attribute. The xmlattributes operator creates the XML attribute name using the SQL attribute name, which can be changed using an as clause as shown.
The xmlforest operator simplifies the construction of XML structures. Its syn- tax and behavior are similar to those of xmlattributes, except that it creates a forest (collection) of subelements, instead of a list of attributes. It takes multi- ple arguments, creating an element for each argument, with the attribute’s SQL name used as the XML element name. The xmlconcat operator can be used to concatenate elements created by subexpressions into a forest.
When the SQL value used to construct an attribute is null, the attribute is omitted. Null values are omitted when the body of an element is constructed. SQL/XML also provides an aggregate function xmlagg that creates a forest (collection) of XML elements from the collection of values on which it is applied. The following query creates an element for each department with a course, con- taining as subelements all the courses in that department. Since the query has
a clause group by dept name, the aggregate function is applied on all courses in each department, creating a sequence of course id elements.
select xmlelement (name “department”, dept name , xmlagg (xmlforest(course id)
order by course id )) from course group by dept name
SQL/XML allows the sequence created by xmlagg to be ordered, as illustrated in the preceding query. See the bibliographical notes for references to more infor- mation on SQL/XML .
1016 Chapter 23 XML
Parts
» Indian Institute of Technology, Bombay
» Data Mining and Information Retrieval
» Structure of Relational Databases
» Database Schema When we talk about a database, we must differentiate between the database
» Basic Structure of SQL Queries
» Modification of the Database
» • Embedded SQL : Like dynamic SQL , embedded SQL provides a means by
» Advanced Aggregation Features**
» The Cartesian-Product Operation
» The Tuple Relational Calculus
» The Entity-Relationship Model
» • For an n-ary relationship set with an arrow on one of its edges, the primary
» Entity-Relationship Design Issues
» Representation of Generalization
» Alternative Notations for Modeling Data
» Other Aspects of Database Design
» Features of Good Relational Designs
» Atomic Domains and First Normal Form
» Decomposition Using Functional Dependencies
» BCNF Decomposition Algorithm
» Decomposition Using Multivalued Dependencies
» Application Programs and User Interfaces
» Overview of Physical Storage Media
» Magnetic Disk and Flash Storage
» Organization of Records in Files
» Comparison of Ordered Indexing and Hashing
» Implementation of Pipelining
» Evaluation Algorithms for Pipelining
» Transformation of Relational Expressions
» (A, r ), the number of distinct values that appear in the relation r for attribute
» Advanced Topics in Query Optimization**
» Transaction Atomicity and Durability
» Transaction Isolation and Atomicity
» Implementation of Isolation Levels
» Transactions as SQL Statements
» Weak Levels of Consistency in Practice
» Concurrency in Index Structures**
» Failure with Loss of Nonvolatile Storage
» Early Lock Release and Logical Undo Operations
» Centralized and Client – Server Architectures
» Parallelism on Multicore Processors
» Recovery and Concurrency Control
» Distributed Query Processing
» Heterogeneous Distributed Databases
» Partitioning and Retrieving Data
» Transactions and Replication
» Decision-Tree Construction Algorithm
» Relevance Ranking Using Terms
» Synonyms, Homonyms, and Ontologies
» Crawling and Indexing the Web
» Information Retrieval: Beyond Ranking of Pages
» Structured Types and Inheritance in SQL
» Array and Multiset Types in SQL
» Application Program Interfaces to XML
» Native Storage within a Relational Database
» Other Issues in Application Development
» Representation of Geographic Data
» Transaction-Processing Monitors
» Real-Time Transaction Systems
» PostgreSQL Implementation of MVCC
» Database Design and Querying Tools
» Database Administration Tools
» Business Intelligence Features
Show more