html5-img
1 / 19

XQuery

XQuery. Dário Pinheiro (DSMP). Roteiro. Motivação Introdução XQuery Sintaxe/Exemplos Ferramentas disponíveis Futuro Xquery Referências. Motivação. Crescente número de bancos que utiliza XML Crescente número de aplicações que utiliza XML para troca de mensagem

Télécharger la présentation

XQuery

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. XQuery Dário Pinheiro (DSMP)

  2. Roteiro • Motivação • Introdução XQuery • Sintaxe/Exemplos • Ferramentas disponíveis • Futuro Xquery • Referências

  3. Motivação • Crescente número de bancos que utiliza XML • Crescente número de aplicações que utiliza XML para troca de mensagem • Necessidade de uma linguagem de query para XML • Possivel solução é XQuery

  4. Motivação: casos reais • “Our project team was asked to develop statistical analysis software for various types of aircraft data on behalf of our managers and to our end customer, NASA. In the past year our managers have been requesting enhanced techniques in data querying and extraction. Because the aircraft data is structured in an XML format, we needed a technology that could handle the querying use-case capabilities that our managers were expecting – this is where the use of XQuery really shines. After many months of research, our development staff decided to utilize XQuery as our technique of choice to query XML data stored in an XML database. We now use XQuery for extracting data from structured XML documents stored in an XML database and this process has dramatically improved the querying capabilities of our existing applications.” • MICHAEL RITCHSON DynCorp systems integrator

  5. XQuery • Uma liguagem para consultas em xml • “SQL para xml” • Versão 1.0 não permite insert, update nem delete • Utilização de pequenas extensões como Xquery Update Facility viabilisão update, insert e delete. • Xquery 3.0 permite essa operações

  6. XQuery • Uma extensão de Xpath, utilisando tipos XML-Schema • Linguagem funcional e de query. • Utilisa-se de expressões FLWOR • Xquery é uma recomendação da W3C desde 2007

  7. Estrutura da consulta XQuery • Query Prolog • Namespace e Declarações de Schema • Definição de funções • Expressões de consulta – expressões de caminho – construtores de elementos – expressões FLWOR ("flower") – chamadas de funções – expressões aritméticas e lógicas – expressões condicionais – expressões quantificadas – expressões de seqüências – expressões de tipos

  8. FLWOR 1:LET, RETURN <catalog> <book id="bk102"> <author>Ralls, Kim</author> <title>Midnight Rain</title> <genre>Fantasy</genre> <price>5.95</price> <publish_date>2000-12-16</publish_date> <description>A former architect battles corporate zombies, an evil sorceress, and her own childhood to become queen of the world.</description> </book> <book id="bk101"> <author>Gambardella, Matthew</author> <title>XML Developer's Guide</title> <genre>Computer</genre> <price>44.95</price> <publish_date>2000-10-01</publish_date> <description>An in-depth look at creating applications with XML.</description> </book> ...outros tags book… </catalog> Let $res := doc(‘catalog.xml’)/*/*[@id=‘bk101’] return $res <book id="bk101"> <author>Gambardella, Matthew</author> <title>XML Developer's Guide</title> <genre>Computer</genre> <price>44.95</price> <publish_date>2000-10-01</publish_date> <description>An in-depth look at creating applications with XML.</description> </book>

  9. Comentários e for • (: esse é um comentário feliz  :) • for $book in collection('/db/test')//book

  10. Funções: declare function prefix:function_name($parameter AS datatype)AS returnDatatype{codigo da funcao} declare function local:pegarporId($doc ,$id ) { let $x := $doc/*/*[@id=$id] return $x }; b:alert( local:pegarporId(doc('xml/catalog.xml') , 'bk101' ) )

  11. Namespaces • Importando um esquema, dizendo sua localizacção como namespace e atribuindo-o ao prefixo soap: • import schema namespace soap="http://www.w3.org/2003/05/soap-envelope" at "http://www.w3.org/2003/05/soap-envelope/"; • Importando um schema dizendo apenas o seu namespace e tornando-o onamespace padrão: • import schema default element namespace "http://example.org/abc";

  12. FLWOR 2:for , lista, expressão de construção for $m in (2, 3), $n in (5, 10) return <fact> {$m} times {$n} is {$m * $n} </fact> <fact>2 times 5 is 10</fact> <fact>2 times 10 is 20</fact> <fact>3 times 5 is 15</fact> <fact>3 times 10 is 30</fact

  13. FLWOR 3:for, let, where, orderby for $x in $doc/*:catalog/*:book let $a := avg($doc/*:catalog/*:book/*:price) where $x/*:price>$a order by $x/*:price return b:alert(<o> <nome>nome:{$x/*:title}</nome> <preco> preco: {$x/*:price}</preco> </o>)

  14. Condições declare function local:caroOuBarato($avg , $v ){ if ($v>$avg) then let $r:= 'caro' return $r else let $r:= 'barato' return $r }; declare function local:f($doc) { for $x in $doc/*:catalog/*:book let $a := avg($doc/*:catalog/*:book/*:price) let $e := local:caroOuBarato($a , $x/*:price ) return b:alert(<o>{$x/*:title} eh {$e} </o>) }; local:f(doc('xml/catalog.xml') )

  15. XQUF for $idattr in doc("data.xml")//ITEM/@Id (: selection :) return ( (: updates :) delete node $idattr, insert node <NID>{string($idattr)}</NID> as firstinto $idattr/.. ) declare updatingfunctioninsert-id($elem, $id-value) { insert node attribute id { $id-value } into $elem }

  16. Outras coisas • every, some • union, intersect, excep • satisfies • cast, treat, assert • distinct-values • Funções, funções ,funções...

  17. Ferramentas • Sql Server • Qizx/open • Stylus Studio • Zorba • http://www.zorba-xquery.com/html/demo

  18. Referências • http://www.w3schools.com/xquery/ • http://www.w3.org/TR/xquery/ • http://www.inf.puc-rio.br/~casanova/INF2328-Topicos-WebBD/modulo0-XML/modulo2b-xml-consultas-xquery.pdf • XQuery, Priscilla WalmsleyISBN: 0596006349 1st edition, 2007, O'Reilly Media, Inc • http://en.wikipedia.org/wiki/XQuery

  19. DUVIDAS?

More Related