+ All Categories
Home > Documents > Unit III - Class 4

Unit III - Class 4

Date post: 02-Jun-2018
Category:
Upload: vanajaraghu
View: 219 times
Download: 0 times
Share this document with a friend

of 12

Transcript
  • 8/10/2019 Unit III - Class 4

    1/12

    1

    Unit III

    XML Databases

  • 8/10/2019 Unit III - Class 4

    2/12

    2

    XML Querying XML Query Languages:

    XPath Provides language constructs that specifies path

    expressions. These path expressions identifies nodes (elements) in an

    XML document.

    These nodes match the patterns specified in the pathexpression.

    XQuery More general query language

    XQuery uses XPath expressions

    Has some additional constructs

  • 8/10/2019 Unit III - Class 4

    3/12

    3

    XML Querying XPath

    An XPath expression returns a collection of element nodesthat satisfycertain patterns specified in the expression.

    The names in the Xpath expression are node names in theXML document tree.

    They are either tag (element) names or attribute nameswith additional qualifier conditions.

    Qualifier conditions further restrict the nodes that satisfythe pattern.

  • 8/10/2019 Unit III - Class 4

    4/12

    4

    XML Querying XPath

    There are two main separators when specifying a path. Single Slash (/) and Double Slash (//)

    A single slash before a tag specifies that the tag mustappear as the direct child of the previous parent tag.

    A double slash specifies that the tag can appear as adescendent of the previous tag at any level.

  • 8/10/2019 Unit III - Class 4

    5/12

    5

    XML Querying XPath

    It is customary to include the file name in any XPath queryallowing us to specify any local file name or path name that

    specifies the path. doc(www.company.com/info.XML)/company => Company

    XML doc

  • 8/10/2019 Unit III - Class 4

    6/12

    6

    XML Querying Examples of XPath Expressions on XML documents

    that follow the XML schema file COMPANY

  • 8/10/2019 Unit III - Class 4

    7/127

    XML Querying

    1. /company

    Returns the COMPANY root node and all its descendent nodes.

    It returns the whole XML document. 2. /company/department

    Returns all the department nodes (elements) and theirdescendent subtrees.

    3. //employee [employeeSalary gt 70000]/employeeName

    Returns all employeeName nodes that are direct children of theemployee node, such that employeeSalary (another childelement of employee node) value is greater than 70000.

  • 8/10/2019 Unit III - Class 4

    8/128

    XML Querying

    4./company/employee[employeeSalary gt 70000]/employeeName

    Returns the same result as above one.

    Only difference is that full path name is specified

    5. /company/project/projectWorker [hours ge 20.0]

    Returns all projectWorker nodes and their descendent nodesthat are children under the path /company/project that have achild node hours with value greater than or equal to 20.0 hours.

  • 8/10/2019 Unit III - Class 4

    9/129

    XML Querying XQuery

    XQuery uses XPath expressions but has additionalconstructs.

    XQuery permits the specification of more general querieson one or more XML documents.

    The typical form of query in XQuery is known as FLWRexpression, which stands for the four main clauses ofXQuery and has the following form: FOR

    LET

    WHERE

    RETURN

  • 8/10/2019 Unit III - Class 4

    10/1210

    XML Querying

    Examples

    ofXquery

    queries

    on

    XML

  • 8/10/2019 Unit III - Class 4

    11/1211

    XML Querying

    XQuery

    1. First query retrieves the first and last names ofemployees who earn more than 70000. Variable $x is bound to each employeeName element child

    of an employee element only if the employee lementsatisfies the qualifier that employeeSalary is greater than70000.

    2. Second query also returns the same result as the firstquery. This is another way of representing the same query

  • 8/10/2019 Unit III - Class 4

    12/1212

    XML Querying

    XQuery

    3. Third query illustrates how a join operation can beperformed by having more than one variable. $x variable is bound to each projectWorker element that is

    the child of project number 5.

    $y variable is bound to each employee element

    The join condition matches the SSN values in order to

    retrieve the employee names.


Recommended