1 / 20

Using XML data with XQuery (by Greg Wiedeman)

Using XML data with XQuery (by Greg Wiedeman). What is XQuery?. W3C standard Designed for users without formal programming background Designed to extract, transform, and manipulate XML data mySQL for XML data Non-tag based language Looks more like XPath than XSLT. How is it used?.

yagil
Download Presentation

Using XML data with XQuery (by Greg Wiedeman)

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. Using XML data with XQuery(by Greg Wiedeman)

  2. What is XQuery? • W3C standard • Designed for users without formal programming background • Designed to extract, transform, and manipulate XML data • mySQL for XML data • Non-tag based language • Looks more like XPath than XSLT

  3. How is it used? • Extract information to use in a Web Service • Generate summary reports • Transform XML data to HTML • Search Web documents for relevant information

  4. XQuery Processors • Saxon • Zorba (for PHP and Python) • eXist XML Database (REST interface) • Proprietary XML databases (MarkLogic) • BaseX • Java • GUI

  5. Prolog and Body xquery version “3.0”; declare variable $input := doc(“myfile.xml”); for$datain$input/element/info return $data

  6. No XML, Odd Punctuation xquery version “3.0”; for$datain doc("myfile.xml")/folder/info let$x := lower-case($data) where$x >= 733 orderby$data@type return$x

  7. Variables • Can be any text you like $data $x $person $info $my_info not $my info

  8. FLOWR expressions For Let Order by Where Return

  9. FLOWR expressions xquery version “3.0”; for$datain doc("myfile.xml")/folder/info let$x := lower-case($data) where$x >= 733 orderby$data@type return$x

  10. XPath in XQuery xquery version “3.0”; for$datain doc("myfile.xml")/folder/info return$data

  11. XPath in XQuery xquery version “3.0”; for$datain doc("myfile.xml")//info return$data

  12. XPath in XQuery xquery version “3.0”; for$datain doc(“sales.xml")//info@attribute return$data

  13. Operators • Math symbols: + - = * div > < >= <= where$x + 733 = 1000

  14. Integers and Strings Integers are: 1 535 2345.343 Strings are: “Taco Bell" ‘five +2 = 7!' "anything /+&= goes" ‘234’ Strings have indexes that start with 0: “Taco Bell" T is 0 c is 3

  15. IF expressions xquery version "3.0"; for$dataindoc("sales.xml")/folder/info return if ($data = "match") then ("data matches!") else ("data does not match")

  16. IF expressions xquery version "3.0"; for$datain doc("sales.xml")/folder/info return if ($data = "apple") then ("data matches!") elseif ($data = "oranges") then ("data does not match") else ("ERROR")

  17. Functions • Magic Words sum() count() string-join() substring() contains() starts-with() index-of() for$datain doc("sales.xml")//info let$x := lower-case($data) return$x

  18. Formatting results in XML or HTML for$xin doc("myfile.xml")/folder/info return<element>{$x}</element> for$xin doc("myfile.xml")/folder/info return <root> <element>{data($x)}</element> <element>{$x@attrb}</element> </root>

  19. Formatting results in XML or HTML <root> { for$datain doc("sales.xml")//info return <element> <tag>{data($data)}</tag> <tag>{$data@attrb}</tag> </element> } </root>

  20. XQuery can teach you about XML • XML is very flexible • Hard to predict how data will be used until you use it • Breaks document-centric thinking • Query and manipulate not reformat • Further separate data storage and display

More Related