1 / 31

XML DOCUMENTS & DATABASES

XML DOCUMENTS & DATABASES. 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

Download Presentation

XML DOCUMENTS & DATABASES

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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 (@) //@country , /catalog/cd[@country = ‘UK’] , //cd[@*] • 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, *, text(), @src, @*, cd[1], cd[last()], */cd, //cd, cd[@type and @country], .., ., cd[5][@type=“classic”], ../@src, .//cd cd[@type=“classic”][5]

  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 • www.w3schools.com • www.w3.org

More Related