Presentation is loading. Please wait.

Presentation is loading. Please wait.

XML DOCUMENTS & DATABASES. Summary of Introduction to XML HTML vs. XML HTML vs. XML Types of Data Types of Data Basics of XML Basics of XML XML Syntax,

Similar presentations


Presentation on theme: "XML DOCUMENTS & DATABASES. Summary of Introduction to XML HTML vs. XML HTML vs. XML Types of Data Types of Data Basics of XML Basics of XML XML Syntax,"— Presentation transcript:

1 XML DOCUMENTS & DATABASES

2 Summary of Introduction to XML HTML vs. XML HTML vs. XML Types of Data Types of Data Basics of XML Basics of XML XML Syntax, XML Elements, XML Attributes XML Syntax, XML Elements, XML Attributes XML Document Type Definition XML Document Type Definition - Types, Elements, Attributes, Example - Types, Elements, Attributes, Example XML Schema XML Schema - XSD vs. DTD, Simple elements, Complex elements, Attributes, Facets, Indicators - XSD vs. DTD, Simple elements, Complex elements, Attributes, Facets, Indicators

3 XML & Databases Extracting XML Documents from Relational Databases Extracting XML Documents from Relational Databases XML Querying: XML Querying: 1. XPath 2. XQuery

4 Extracting XML Documents

5

6

7

8

9

10

11 XML QUERYING XML PATH LANGUAGE XML PATH LANGUAGE - XPath - XPath XML QUERY LANGUAGE XML QUERY LANGUAGE - XQuery - XQuery

12 XML PATH LANGUAGE - XPATH XPath is a language for addressing parts of an XML Document. XPath is a language for addressing parts of an XML Document. XPath uses paths to define XML elements XPath uses paths to define XML elements XPath defines a library of standard functions XPath defines a library of standard functions XPath is not written using XML Syntax XPath is not written using XML Syntax XPath is a W3C Standard !! XPath is a W3C Standard !! XPath provides common syntax and semantics for XSLT and XPointer XPath provides common syntax and semantics for XSLT and XPointer

13 XPath – XML Data model root nodes root nodes element nodes element nodes text nodes text nodes attribute nodes attribute nodes namespace nodes namespace nodes processing instruction nodes processing instruction nodes comment nodes comment nodes

14 XPath Basics - Path In general -> sandeep/xml/xmlpath.ppt In general -> sandeep/xml/xmlpath.ppt In XPath -> /catalog/cd/price In XPath -> /catalog/cd/price

15 XPath Syntax with examples (overview) Locating nodes: Locating nodes: /catalog/cd/price (absolute path), //cd /catalog/cd/price (absolute path), //cd Unknown elements: Use wildcard (*) Unknown elements: Use wildcard (*) /catalog/*, /*/*/price, // * /catalog/*, /*/*/price, // * Several paths: //title | // artist Several paths: //title | // artist Selecting attributes: Use prefix (@) Selecting attributes: Use prefix (@) //@country, /catalog/cd[@country = ‘UK’], //cd[@*] //@country, /catalog/cd[@country = ‘UK’], //cd[@*] Specifying Predicates: Specifying Predicates: /catalog/cd[1], //cd[price], //cd[price = 10]/price /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. Most important grammatical construct in the XPath language, that results in a node-set. EBNF format: EBNF format: Location ::= RelativeLocationPath | AbsoluteLocationPath | AbsoluteLocationPath AbsoluteLocationPath: /step/step/... AbsoluteLocationPath: /step/step/... RelativeLocationPath: step/step/... RelativeLocationPath: step/step/...

17 XPath – Location Path EBNF format: EBNF format: Location ::= RelativeLocationPath | Location ::= RelativeLocationPath | AbsoluteLocationPath AbsoluteLocationPath AbsoluteLocationPath::=‘/’RelativeLocationPath? AbsoluteLocationPath::=‘/’RelativeLocationPath? | AbbreviatedAbsoluteLocationPath | AbbreviatedAbsoluteLocationPath RelativeLocationPath::=Step|RelativeLocationPath ‘/’ Step | AbbreviatedRelativeLocationPath RelativeLocationPath::=Step|RelativeLocationPath ‘/’ Step | AbbreviatedRelativeLocationPath

18 XPath – Location Path Location Step has three parts: Location Step has three parts: 1. An Axis – Tree Relationship 2. A Node Test – Node type, expanded-name 3. Zero or more Predicates – Expressions to refine set of nodes. Syntax: axisname :: nodetest [predicate] Syntax: axisname :: nodetest [predicate] Example: child :: price [price = 10] Example: child :: price [price = 10] Context: context node, context position, context size, variable bindings, function library, namespace declarations 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() child::cd, child::*, child::text() attribute::name,attribute::* attribute::name,attribute::* descentant::catalog, descendant-or-self::cd descentant::catalog, descendant-or-self::cd child::catalog/self::cd, child::cd[position() = last()] child::catalog/self::cd, child::cd[position() = last()] /descendant::cd, /descendant::catalog/child::cd /descendant::cd, /descendant::catalog/child::cd child::para[position()=5][attribute::type=“w arning”]………what if.. [att..][pos..] child::para[position()=5][attribute::type=“w arning”]………what if.. [att..][pos..] child::*[self::cd or self::catalog] child::*[self::cd or self::catalog]

21 XPath – Predicates A Predicate filters a node-set to a new node-set. A Predicate filters a node-set to a new node-set. The condition is placed in [ ] The condition is placed in [ ]

22 XPath – Abbreviated Syntax Examples: Examples: cd, *, text(), @src, @*, cd[1], cd[last()], cd, *, text(), @src, @*, cd[1], cd[last()], */cd, //cd, cd[@type and @country],..,., */cd, //cd, cd[@type and @country],..,., cd[5][@type=“classic”],../@src,.//cd cd[@type=“classic”][5] cd[5][@type=“classic”],../@src,.//cd cd[@type=“classic”][5]

23 XPath - Expressions Types: XPath - Expressions Types: 1. Numerical -> +,-,*,div, mod 2. Equality -> =, != 3. Relational ->, = 4. Boolean -> or, and XPath – Functions XPath – Functions Node – set functions, Numeric fuctions, Node – set functions, Numeric fuctions, String functions, Boolean functions String functions, Boolean functions

24 XPath – Core Function Library Node – Set: Node – Set: count() ; setnumber=count(node-set) count() ; setnumber=count(node-set) id() ; node-set=id(value) id() ; node-set=id(value) last() ; listnumber=last() last() ; listnumber=last() local-name() ; namestring=local-name(node) local-name() ; namestring=local-name(node) name() ; nodestring=name(node) name() ; nodestring=name(node) namespace-uri() ; nodeuri=namespace-uri(node) namespace-uri() ; nodeuri=namespace-uri(node) position() ; processednumber=position() position() ; processednumber=position() Boolean: Boolean: boolean() ; bool = boolean(value) boolean() ; bool = boolean(value) false() ; number(false()) false() ; number(false()) lang() ; bool = lang(language) lang() ; bool = lang(language) not() ; not(false()) not() ; not(false()) true() ; number(true()) true() ; number(true())

25 XPath – Core Function Library – String concat() ; string=concat(val1, val2,..) concat() ; string=concat(val1, val2,..) contains() ; bool=contains(val,substr) contains() ; bool=contains(val,substr) normalize-space() ; string=normalize-space(string) normalize-space() ; string=normalize-space(string) starts-with() ; bool=starts-with(string,substr) starts-with() ; bool=starts-with(string,substr) string() ; string(value) string() ; string(value) string-length() ; number=string-length(string) string-length() ; number=string-length(string) substring() ; string=substring(string,start,length) substring() ; string=substring(string,start,length) substring-after() ; string=substring-after(string,substr) substring-after() ; string=substring-after(string,substr) substring-before() ; string= substring-before() ; string= substring-before(string,substr) substring-before(string,substr) translate() ; string=translate(value,string1,string2) translate() ; string=translate(value,string1,string2)

26 XML QUERY LANGUAGE XML Query Language is used to extract data by querying the XML Documents 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 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 and XML Path have same Data Model, Function Library, Data types, Operators XML Query is not yet a W3C Standard ! XML Query is not yet a W3C Standard !

27 XML Query Language – Extracting Nodes Using Functions Using Functions doc(example.xml) doc(example.xml) Using Functions and Paths Using Functions and Paths doc(example.xml)/catalog/cd or doc(..)//cd doc(example.xml)/catalog/cd or doc(..)//cd Using Expressions Using Expressions doc(example.xml)/catalog/cd[price < 10] doc(example.xml)/catalog/cd[price < 10]

28 XML Query – FLOWR Expression For For Let Let Order by Order by Where Where Return Return

29 XML QUERY - Example

30 ANY “QUERIES”? Hint: use xml

31 REFERENCES Fundamentals of Database Systems, Fourth Edition, Elmasir and Navathe Fundamentals of Database Systems, Fourth Edition, Elmasir and Navathe www.w3schools.com www.w3schools.com www.w3schools.com www.w3.org www.w3.org www.w3.org


Download ppt "XML DOCUMENTS & DATABASES. Summary of Introduction to XML HTML vs. XML HTML vs. XML Types of Data Types of Data Basics of XML Basics of XML XML Syntax,"

Similar presentations


Ads by Google