XML-QL A Query Language for XML - PowerPoint PPT Presentation

About This Presentation
Title:

XML-QL A Query Language for XML

Description:

Find all articles that have at least one author who has also written a book since 1995 : ... www.research.att.com/~mff/xmlql/doc : The XML-QL home page ... – PowerPoint PPT presentation

Number of Views:68
Avg rating:3.0/5.0
Slides: 18
Provided by: Char183
Category:
Tags: xml | at | com | language | query

less

Transcript and Presenter's Notes

Title: XML-QL A Query Language for XML


1
XML-QL A Query Language for XML
  • Charuta Nakhe
  • charuta_at_cse.iitb.ernet.in

2
Querying XML document
  • What is a query language?
  • Why not adapt SQL or OQL to query XML data?
  • What is an XML query?
  • What is the database? -- XML documents
  • What is input to the query? XML document
  • What is the output of the query? XML document

3
Requirements of XML query language
  • Query operations
  • Selection eg. Find books with S. Sudarshan as
    author
  • Extraction eg. Extract the publisher field of
    above books
  • Restructuring Restructuring of elements
  • Combination Queries over more than one
    documents
  • Must be able to transform create XML structures
  • Capability for querying even in absence of schema

4
The XML-QL language
  • The XML-QL language is designed with the
    following features
  • it is declarative, like SQL.
  • it is relational complete, e.g. it can express
    joins.
  • it can be implemented with known database
    techniques.
  • it can extract data from existing XML documents
    and construct new XML documents.
  • XML-QL is implemented as a prototype and is
    freely available in a Java version.

5
Example XML document
  • ltbibgt  
  • ltbook year1997gt     
  • lttitlegtInside COMlt/titlegt
  •      ltauthorgtDale Rogersonlt/authorgt
  •     ltpublishergtltnamegtMicrosoftlt/namelt/publish
    ergt  
  • lt/bookgt  
  • ltbook year1998gt     
  • lttitlegtDatabase system conceptslt/titlegt
  •      ltauthorgtS. Sudarshanlt/authorgt
  • ltauthorgtH. Korthlt/authorgt
  • ltpublishergt ltnamegtMcGrawHilllt/namelt/publi
    shergt lt/bookgt
  • lt/bibgt

6
Matching data using patterns
  • Find those authors who have published books
    for McGraw Hill
  • WHERE
  • ltbibgtltbookgt
  • ltpublishergtltnamegtMcGraw Hilllt/gtlt/gt
  • lttitlegttlt/gt
  • ltauthorgtalt/gt
  • lt/bookgtlt/bibgt IN bib.xml
  • CONSTRUCT ltresultgtlttitlegttlt/gtltauthorgtalt/gtlt/gt
  • the t and a are variables that pick out
    contents.
  • the output is a collection of author names.

7
Result XML document
  • ltresultgt
  •      lttitlegtDatabase system
    conceptslt/titlegt
  •      ltauthorgtS. Sudarshanlt/authorgt
  • lt/resultgt
  • ltresultgt
  •      lttitlegtDatabase system
    conceptslt/titlegt
  •      ltauthorgtH. Korthlt/authorgt
  • lt/resultgt

8
Grouping with Nested Queries
  • Group results by book title
  • WHERE
  • ltbib.bookgtplt/gt IN bib.xml,
  • lttitlegttlt/gt
  • ltpublishergtltnamegtMcGraw Hilllt/gtlt/gt IN p
  • CONSTRUCT ltresultgt lttitlegttlt/gt
  • WHERE ltauthorgtalt/gt IN p CONSTRUCT a
  • lt/gt
  • Produces one result for each title and contains a
    list of all its authors

9
Result XML document
  • ltresultgt
  •      lttitlegtDatabase system
    conceptslt/titlegt
  •      ltauthorgtS. Sudarshanlt/authorgt
  •      ltauthorgtH. Korthlt/authorgt
  • lt/resultgt
  • .
  • .

10
Constructing XML data
  • Results of a query can be wrapped in XML   
  • WHERE ltbib.bookgt
  •           ltpublishergtltnamegtMcGrawHilllt/gtlt/gt
  •           lttitlegttlt/gt
  • ltauthorgtalt/gt
  •         lt/gt IN bib.xml   
  • CONSTRUCT ltresultgtltauthorgtalt/gtlttitlegttlt/gtlt/gt
  • Results are grouped in elements.
  • The pattern matches once for each author, which
    may give duplicates of books.

11
Joining elements by value
  • Find all articles that have at least one
    author who has also written a book since 1995
  • WHERE ltbib.articlegt
  • ltauthorgtnlt/gt
  • I lt/gt CONTENT_AS a IN bib.xml,
  • ltbook yearygt
  • ltauthorgtnlt/gt
  • lt/gt IN bib.xml,
  • y gt 1995
  • CONSTRUCT ltarticlegtalt/gt
  • CONTENT_AS a following a pattern binds the
    content of the matching element to the variable
    a

12
Tag variables
  • Find all publications in 1995 where Smith is
    either an author or editor
  • WHERE ltbib.pgt
  • lttitlegttlt/gt ltyeargt1995lt/gt ltegtSmithlt/gt
  • lt/gt IN bib.xml,
  • e IN author, editor
  • CONSTRUCT ltpgtlttitlegttlt/gtltegtSmithlt/gtlt/gt
  • p matches book and article.
  • e matches author and editor.

13
Regular-path expressions
  • Find the name of every part element that
    contains a brand element equal to Ford,
    regardless of the nesting level at which r
    occurs.
  • WHERE ltpartgt
  • lttitlegtrlt/gt
  • ltnamegtFordlt/gt
  • lt/gt IN bib.xml
  • CONSTRUCT ltresultgtrlt/gt
  • Regular path expressions can specify element
    paths of arbitrary depth

14
Other interesting features
  • Constructing explicit root element
  • Grouping of data
  • Transforming XML data
  • Integrating data from different XML sources

15
Links for more information
  • www.w3.org/TR/NOTE-xml-ql The XML-QL W3C Note
  • www.research.att.com/mff/xmlql/doc The XML-QL
    home page
  • www.w3.org/XML/Activity.htmlquery-wg The XML
    Query Working Group
  • www.w3.org/TR/xmlquery-req XML Query
    Requirements (W3C Working Draft)
  • www.oasis-open.org/cover/xmlQuery.html Robin
    Cover's page on XML query languages

16
Example DTD
  • lt!ELEMENT book (author, title, publisher)gt
  • lt!ATTLIST book year CDATAgt
  • lt!ELEMENT article (author, title, year?)gt
  • lt!ATTLIST article type CDATAgt
  • lt!ELEMENT publisher (name, address)gt
  • lt!ELEMENT author (firstname?, lastname)gt

17
Creating an explicit root element
  • Every XML document must have a single root.
    XML-QL supplies an ltXMLgt element as default, but
    others may be specified   
  • CONSTRUCT ltresultsgt    
  • WHERE ltbib.bookgt
  •        ltpublishergtltnamegtMcGrawHilllt
    /gtlt/gt            lttitlegt  t lt/gt
  •       ltauthorgt a lt/gt         
  • lt/gt IN bib.xml
  • CONSTRUCT ltresultgtltauthorgtalt/gtlttitlegttlt/gtlt/gt
  •   lt/resultsgt
Write a Comment
User Comments (0)
About PowerShow.com