xml documents & databases. summary of introduction to xml html vs. xml html vs. xml types of...

Post on 27-Dec-2015

274 Views

Category:

Documents

5 Downloads

Preview:

Click to see full reader

TRANSCRIPT

XML DOCUMENTSXML DOCUMENTS&&

DATABASES DATABASES

Summary of Introduction to Summary of Introduction to XMLXML• HTML vs. XMLHTML vs. XML• Types of DataTypes of Data• Basics of XMLBasics of XML• XML Syntax, XML Elements, XML XML Syntax, XML Elements, XML

AttributesAttributes• XML Document Type DefinitionXML Document Type Definition - Types, Elements, Attributes, Example- Types, Elements, Attributes, Example• XML Schema XML Schema - XSD vs. DTD, Simple elements, - XSD vs. DTD, Simple elements,

Complex elements, Attributes, Facets, Complex elements, Attributes, Facets, IndicatorsIndicators

XML & DatabasesXML & Databases

• Extracting XML Documents from Extracting XML Documents from Relational DatabasesRelational Databases

• XML Querying:XML Querying:

1.1. XPathXPath

2.2. XQuery XQuery

Extracting XML Documents Extracting XML Documents

Extracting XML DocumentsExtracting XML Documents

Extracting XML DocumentsExtracting XML Documents

Extracting XML DocumentsExtracting XML Documents

Extracting XML DocumentsExtracting XML Documents

Extracting XML DocumentsExtracting XML Documents

Extracting XML DocumentsExtracting XML Documents

XML QUERYINGXML QUERYING

• XML PATH LANGUAGE XML PATH LANGUAGE

- XPath- XPath

• XML QUERY LANGUAGEXML QUERY LANGUAGE

- XQuery- XQuery

XML PATH LANGUAGE - XML PATH LANGUAGE - XPATHXPATH

• XPath is a language for addressing parts XPath is a language for addressing parts of an XML Document.of an XML Document.

• XPath uses paths to define XML XPath uses paths to define XML elements elements

• XPath defines a library of standard XPath defines a library of standard functions functions

• XPath is not written using XML SyntaxXPath is not written using XML Syntax

• XPath is a W3C Standard !!XPath is a W3C Standard !!

• XPath provides common syntax and XPath provides common syntax and semantics for XSLT and XPointer semantics for XSLT and XPointer

XPath – XML Data modelXPath – XML Data model

• root nodesroot nodes

• element nodeselement nodes

• text nodestext nodes

• attribute nodesattribute nodes

• namespace nodesnamespace nodes

• processing instruction nodesprocessing instruction nodes

• comment nodescomment nodes

XPath Basics - PathXPath Basics - Path

• In general -> sandeep/xml/xmlpath.pptIn general -> sandeep/xml/xmlpath.ppt• In XPath -> /catalog/cd/priceIn XPath -> /catalog/cd/price

XPath Syntax XPath Syntax with examples with examples (overview)(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 | // artistSeveral 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

XPath – Location PathXPath – Location Path• Most important grammatical construct in Most important grammatical construct in

the XPath language, that results in a the XPath language, that results in a node-set.node-set.

• EBNF format:EBNF format:

Location ::= RelativeLocationPath Location ::= RelativeLocationPath

| AbsoluteLocationPath| AbsoluteLocationPath

• AbsoluteLocationPath: /step/step/... AbsoluteLocationPath: /step/step/...

• RelativeLocationPath: step/step/...RelativeLocationPath: step/step/...

XPath – Location PathXPath – Location Path

• EBNF format:EBNF format: Location ::= RelativeLocationPath |Location ::= RelativeLocationPath | AbsoluteLocationPathAbsoluteLocationPath

AbsoluteLocationPath::=‘/’RelativeLocationPath?AbsoluteLocationPath::=‘/’RelativeLocationPath? | AbbreviatedAbsoluteLocationPath| AbbreviatedAbsoluteLocationPath

RelativeLocationPath::=Step|RelativeLocationPath::=Step|RelativeLocationPath ‘/’ Step | RelativeLocationPath ‘/’ Step | AbbreviatedRelativeLocationPathAbbreviatedRelativeLocationPath

XPath – Location PathXPath – Location Path• Location Step has three parts:Location Step has three parts:1.1. An Axis – Tree RelationshipAn Axis – Tree Relationship2.2. A Node Test – Node type, expanded-A Node Test – Node type, expanded-

namename3.3. Zero or more Predicates – Expressions to Zero or more Predicates – Expressions to

refine set of nodes.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: context node, context position,

context size, variable bindings, function context size, variable bindings, function library, namespace declarationslibrary, namespace declarations

XPath – Location Path – XPath – Location Path – Uabbreviated Axis NamesUabbreviated Axis Names

XPath – Location Path - XPath – Location Path - ExamplesExamples

• child::cd , child::*, child::text()child::cd , child::*, child::text()• attribute::name,attribute::*attribute::name,attribute::*• descentant::catalog, descendant-or-descentant::catalog, descendant-or-

self::cdself::cd• child::catalog/self::cd, child::cd[position() child::catalog/self::cd, child::cd[position()

= last()]= last()]• /descendant::cd, /descendant::cd,

/descendant::catalog/child::cd/descendant::catalog/child::cd• child::para[position()=5]child::para[position()=5]

[attribute::type=“warning”]………what [attribute::type=“warning”]………what if .. [att..][pos..]if .. [att..][pos..]

• child::*[self::cd or self::catalog]child::*[self::cd or self::catalog]

XPath – Predicates XPath – Predicates

• A Predicate filters a node-set to a A Predicate filters a node-set to a new node-set.new node-set.

• The condition is placed in [ ]The condition is placed in [ ]

XPath – Abbreviated SyntaxXPath – Abbreviated Syntax

• Examples:Examples:

cd, *, text(), @src, @*, cd[1], cd, *, text(), @src, @*, cd[1], cd[last()],cd[last()],

*/cd, //cd, cd[@type and */cd, //cd, cd[@type and @country], .., .,@country], .., .,

cd[5][@type=“classic”], ../@src, .//cd cd[5][@type=“classic”], ../@src, .//cd cd[@type=“classic”][5]cd[@type=“classic”][5]

• XPath - Expressions Types: XPath - Expressions Types: 1.1. Numerical -> + ,- ,* ,div , modNumerical -> + ,- ,* ,div , mod

2.2. Equality -> =, !=Equality -> =, !=

3.3. Relational -> <,>,<=,>=Relational -> <,>,<=,>=

4.4. Boolean -> or, andBoolean -> or, and

• XPath – FunctionsXPath – Functions Node – set functions, Numeric Node – set functions, Numeric

fuctions,fuctions,

String functions, Boolean functionsString functions, Boolean functions

XPath – Core Function XPath – Core Function LibraryLibrary• 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-namespace-uri() ; nodeuri=namespace-

uri(node)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())

XPath – Core Function Library – XPath – Core Function Library – StringString

• 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-substring-after() ; string=substring-after(string,substr) 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)

XML QUERY LANGUAGEXML QUERY LANGUAGE

• XML Query Language is used to extract XML Query Language is used to extract data by querying the XML Documentsdata by querying the XML Documents

• XML is built on XPath which is used in XML is built on XPath which is used in writing querieswriting queries

• XML Query and XML Path have same XML Query and XML Path have same Data Model, Function Library, Data Data Model, Function Library, Data types, Operatorstypes, Operators

• XML Query is not yet a W3C Standard !XML Query is not yet a W3C Standard !

XML Query Language – Extracting XML Query Language – Extracting NodesNodes

• Using FunctionsUsing Functions doc(example.xml)doc(example.xml)

• Using Functions and PathsUsing Functions and Paths doc(example.xml)/catalog/cd or doc(example.xml)/catalog/cd or

doc(..)//cddoc(..)//cd

• Using ExpressionsUsing Expressions doc(example.xml)/catalog/cd[price < 10]doc(example.xml)/catalog/cd[price < 10]

XML Query – FLOWR XML Query – FLOWR ExpressionExpression

• For <variable bindings to individual For <variable bindings to individual nodes>nodes>

• Let <variable bindings to a collection of Let <variable bindings to a collection of nodes>nodes>

• Order by <query specifications>Order by <query specifications>

• Where <conditions>Where <conditions>

• Return <query result specifications>Return <query result specifications>

XML QUERY - ExampleXML QUERY - Example

ANY “QUERIES”?ANY “QUERIES”?

Hint: use xml Hint: use xml

REFERENCESREFERENCES

•Fundamentals of Database Fundamentals of Database Systems, Fourth Edition, Elmasir Systems, Fourth Edition, Elmasir and Navatheand Navathe

•www.w3schools.comwww.w3schools.com

•www.w3.orgwww.w3.org

top related