INFORMATIO
xquerynotes_2.pdf

Ments or operands to be of a particular type xquery

Info icon This preview shows pages 9–11. Sign up to view the full content.

ments or operands to be of a particular type XQuery type system is based on that of XML Schema XML Schema has built-in datatypes such as xs:integer , xs:string , and xs:date Types are assigned to items in the input document during schema validation If no schema is used, the items are untyped Untyped items are casted to the type required by a particular operation Casting converts a value from one type to another following specified rules 3 doc("order.xml")/order/substring(@num, 1, 4) does not require that the num attribute be declared to be of type xs:string 3 If it is untyped, it is cast to xs:string 3 If attribute is of type xs:integer it is necessary to convert the value of the at- tribute: doc("order.xml")/order/substring(xs:string(@num), 1, 4) 33 Namespaces (1) Namespaces are used to identify the vocabulary to which XML elements and attributes belong, and to disambiguate names from different vocabularies Input document ( prod_ns.xml ) with a namespace declaration <prod:product xmlns:prod=" "> <prod:number>563</prod:number> <prod:name language="en">Floppy Sun Hat</prod:name> </prod:product> The prod prefix is mapped to the namespace This means that any element or attribute name in the document that is prefixed with prod is in that namespace 34 XQuery – Foundations – 17 Namespaces (2) Query declare namespace prod = " "; for $product in doc("prod_ns.xml")/prod:product return $product/prod:name Results <prod:name xmlns:prod=" " language="en">Floppy Sun Hat</prod:name> The namespace declaration in the first line of the query maps the namespace to the prefix prod The prod prefix is used in the body of the query to refer to elements in the input document The namespace ( not the prefix ) is a significant part of the name of an element or attribute The namespace URIs in the query and input document must match exactly Prefixes do not have to be the same in the input document and the query 35 XQuery: Contents Introduction to XQuery XQuery Foundations XQuery Expressions Navigating Input Documents Using Paths Adding Elements and Attributes to Results Selecting and Joining Using FLWORs Sorting and Grouping Functions Updates 36 XQuery – Expressions – 18
Image of page 9

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

Categories of Expressions Primary : literals, variables, function calls, and parenthesized expressions Comparison based on value, node identity, or document order using = , != , < , <= , > , >= , eq , ne , lt , le , gt , ge , is , << , >> Conditional : if-then-else expressions Logical : Boolean operators using or , and Path : Selecting nodes from XML documents using / , // , .. , . , child:: , . . . Constructor : Adding XML to the results using < , > , element , attribute FLWOR : Select and process nodes using for , let , where , order by , return Quantified : Test whether sequences fulfill conditions some , every , in , satisfies Sequence-related : Create and combine sequences using union , intersect , except Type-related : Cast and validate values based on type using instance of , typeswitch , cast as ,
Image of page 10
Image of page 11
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