INFORMATIO
xquerynotes_2.pdf

The string value of a node can be accessed using the

Info icon This preview shows pages 8–10. Sign up to view the full content.

The string value of a node can be accessed using the string function 3 string(doc("catalog.xml")/catalog/product[4]/number) returns "784" 3 string(<desc>Our <i>favorite</i> shirt!</desc>) returns "Our favorite shirt!" Element and attribute nodes may also have a typed value, if it has been validated with a schema The typed value of a node can be accessed using the data function 3 data(doc("catalog.xml")/catalog/product[4]/number) returns the in- teger 784 , if the number element is declared in a schema to be an integer. Otherwise, its typed value is 784 , but it is considered to be untyped 29 Atomic Values A simple data value such as 784 or ACC , with no markup, and no association with any particular element or attribute An atomic value can have a specific type, such as xs:integer or xs:string , or it can be untyped (i.e. xs:untypedAtomic ) Can be extracted from element or attribute nodes using the string and data functions Can also be created from literals in queries as in @dept = ’ACC’ Functions and operators that expect atomic values as their operands also accept nodes, as in doc("catalog.xml")//product[4]/substring(name, 1, 15) Function substring expects a string atomic value as the first argument, but an element node ( name ) can be passed In this case, the atomic value is automatically extracted from the node in a process known as atomization Atomic values do not have identity 30 XQuery – Foundations – 15 Sequences (1) Sequences are ordered collections of zero, one, or many items Each item in a sequence can be either an atomic value or a node 3 doc("catalog.xml")/catalog/product returns a sequence of four element nodes A sequence can also be created explicitly using a sequence constructor : a series of values, delimited by commas, surrounded by parentheses 3 (1, 2, 3) creates a sequence consisting of three atomic values 3 (doc("catalog.xml")/catalog/product, 1, 2, 3) uses an expression in the sequence constructor Sequences do not have names, they may be bound to a named variable 3 let $prodList := doc("catalog.xml")/catalog/product binds sequence of four product elements to the variable $prodList 31 Sequences (2) Empty sequence : A sequence with zero items The empty sequence is different from a zero-length string ( "" ) or a zero value Many built-in functions and operations accept empty sequence as an argument Some expressions return the empty sequence, such as doc("catalog.xml")//foo , if there are no foo elements in the document Sequences cannot be nested : there is only one level of items 3 (10, (20, 30), 40) is equivalent to (10, 20, 30, 40) Many functions and operators in XQuery operate on sequences 3 Aggregation functions: min , max , avg , sum 3 union , except , and intersect expressions allow sequences to be combined 3 A number of functions operate generically on any sequence, such as index-of and insert-before Like atomic values, sequences have no identity 32 XQuery – Foundations – 16
Image of page 8

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

Types XQuery is a strongly typed language : functions and operators expect argu-
Image of page 9
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.
  • Winter '15
  • MAhmoudali

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern