Download presentation
Presentation is loading. Please wait.
1
XML DOCUMENTS & DATABASES
2
Summary of Introduction to XML
HTML vs. XML Types of Data Basics of XML XML Syntax, XML Elements, XML Attributes XML Document Type Definition - Types, Elements, Attributes, Example XML Schema - XSD vs. DTD, Simple elements, Complex elements, Attributes, Facets, Indicators
3
XML & Databases Extracting XML Documents from Relational Databases
XML Querying: XPath XQuery
4
Extracting XML Documents
5
Extracting XML Documents
6
Extracting XML Documents
7
Extracting XML Documents
8
Extracting XML Documents
9
Extracting XML Documents
10
Extracting XML Documents
11
XML QUERYING XML PATH LANGUAGE - XPath XML QUERY LANGUAGE - XQuery
12
XML PATH LANGUAGE - XPATH
XPath is a language for addressing parts of an XML Document. XPath uses paths to define XML elements XPath defines a library of standard functions XPath is not written using XML Syntax XPath is a W3C Standard !! XPath provides common syntax and semantics for XSLT and XPointer
13
XPath – XML Data model root nodes element nodes text nodes
attribute nodes namespace nodes processing instruction nodes comment nodes
14
XPath Basics - Path In general -> sandeep/xml/xmlpath.ppt
In XPath -> /catalog/cd/price
15
XPath Syntax with examples (overview)
Locating nodes: /catalog/cd/price (absolute path), //cd Unknown elements: Use wildcard (*) /catalog/*, /*/*/price , // * Several paths: //title | // artist Selecting attributes: Use prefix , = ‘UK’] , Specifying Predicates: /catalog/cd[1] , //cd[price], //cd[price = 10]/price
16
XPath – Location Path Most important grammatical construct in the XPath language, that results in a node-set. EBNF format: Location ::= RelativeLocationPath | AbsoluteLocationPath AbsoluteLocationPath: /step/step/... RelativeLocationPath: step/step/...
17
XPath – Location Path EBNF format: Location ::= RelativeLocationPath |
AbsoluteLocationPath AbsoluteLocationPath::=‘/’RelativeLocationPath? | AbbreviatedAbsoluteLocationPath RelativeLocationPath::=Step|RelativeLocationPath ‘/’ Step | AbbreviatedRelativeLocationPath
18
XPath – Location Path Location Step has three parts:
An Axis – Tree Relationship A Node Test – Node type, expanded-name Zero or more Predicates – Expressions to refine set of nodes. Syntax: axisname :: nodetest [predicate] Example: child :: price [price = 10] Context: context node, context position, context size, variable bindings, function library, namespace declarations
19
XPath – Location Path – Uabbreviated Axis Names
20
XPath – Location Path - Examples
child::cd , child::*, child::text() attribute::name,attribute::* descentant::catalog, descendant-or-self::cd child::catalog/self::cd, child::cd[position() = last()] /descendant::cd, /descendant::catalog/child::cd child::para[position()=5][attribute::type=“warning”]………what if .. [att..][pos..] child::*[self::cd or self::catalog]
21
XPath – Predicates A Predicate filters a node-set to a new node-set.
The condition is placed in [ ]
22
XPath – Abbreviated Syntax
Examples: cd, cd[1], cd[last()], */cd, //cd, .., ., .//cd
23
XPath - Expressions Types:
Numerical -> ,- ,* ,div , mod Equality -> =, != Relational -> <,>,<=,>= Boolean -> or, and XPath – Functions Node – set functions, Numeric fuctions, String functions, Boolean functions
24
XPath – Core Function Library
Node – Set: count() ; setnumber=count(node-set) id() ; node-set=id(value) last() ; listnumber=last() local-name() ; namestring=local-name(node) name() ; nodestring=name(node) namespace-uri() ; nodeuri=namespace-uri(node) position() ; processednumber=position() Boolean: boolean() ; bool = boolean(value) false() ; number(false()) lang() ; bool = lang(language) not() ; not(false()) true() ; number(true())
25
XPath – Core Function Library – String
concat() ; string=concat(val1, val2, ..) contains() ; bool=contains(val,substr) normalize-space() ; string=normalize-space(string) starts-with() ; bool=starts-with(string,substr) string() ; string(value) string-length() ; number=string-length(string) substring() ; string=substring(string,start,length) substring-after() ; string=substring-after(string,substr) substring-before() ; string= substring-before(string,substr) translate() ; string=translate(value,string1,string2)
26
XML QUERY LANGUAGE XML Query Language is used to extract data by querying the XML Documents XML is built on XPath which is used in writing queries XML Query and XML Path have same Data Model, Function Library, Data types, Operators XML Query is not yet a W3C Standard !
27
XML Query Language – Extracting Nodes
Using Functions doc(example.xml) Using Functions and Paths doc(example.xml)/catalog/cd or doc(..)//cd Using Expressions doc(example.xml)/catalog/cd[price < 10]
28
XML Query – FLOWR Expression
For <variable bindings to individual nodes> Let <variable bindings to a collection of nodes> Order by <query specifications> Where <conditions> Return <query result specifications>
29
XML QUERY - Example
30
ANY “QUERIES”? Hint: use xml
31
REFERENCES Fundamentals of Database Systems, Fourth Edition, Elmasir and Navathe
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.