1.2 - XML Basics - IBM · parent/child relationships to form a hierarchy. Only one representation...

27
1 1 © 2008 IBM Corporation IBM Software Group Data Management Solutions Information Management IBM Software Group XML Basics 2 © 2008 IBM Corporation IBM Software Group Data Management – DB2 9.5 pureXML ® Summer/Fall 2008 Data Management Solutions Information Management IBM Software Group

Transcript of 1.2 - XML Basics - IBM · parent/child relationships to form a hierarchy. Only one representation...

1

1 © 2008 IBM Corporation

IBM Software Group

Data Management SolutionsInformation ManagementIBM Software Group

XML Basics

2 © 2008 IBM Corporation

IBM Software Group

Data Management – DB2 9.5 pureXML ®

Summer/Fall 2008

Data Management SolutionsInformation ManagementIBM Software Group

2

3 © 2008 IBM Corporation

?

Ready to “talk XML” ?

XPath

DOM

SAX

XML SchemaElement

Namespaces

Default Namespace

Text Nodes

Mixed Content

XSLT

Parent Step

Serialization

Well-formedValidation

URI

Target Namespace

XSLFO

4 © 2008 IBM Corporation

Agenda

What is XML ?

Well-formed XML documents

Namespaces

XPATH

XML Schema

What is XSL?

Further Reading

3

5 © 2008 IBM Corporation

Agenda

What is XML ?

Well-formed XML documents

Namespaces

XPATH

XML Schema

What is XSL?

XML Parsers: DOM vs. SAX

Further Reading

6 © 2008 IBM Corporation

47; John Doe; 58; Peter Pan; Database systems; 29; SQL; relational

Let's start with an example...

Here is some data from an ordinary delimited flat file:

What does this data mean?

What is XML?

4

7 © 2008 IBM Corporation

<book><authors>

<author id=“47”>John Doe</author><author id=“58”>Peter Pan</author>

</authors><title>Database systems</title><price>29</price><keywords>

<keyword>SQL</keyword><keyword>relational</keyword>

</keywords></book>

XML = eXtensible Markup Language

XML: Describes dataHTML: Describes display

XML is "self-describing data"

What is XML?

8 © 2008 IBM Corporation

<book><authors>

<author id=“47”>John Doe</author><author id=“58”>Peter Pan</author>

</authors><title>Database systems</title><price>29</price><keywords>

<keyword>SQL</keyword><keyword>relational</keyword>

</keywords></book>

Start Tag

Data

End Tag

Element

Attribute

XML: Describes dataHTML: Describes display

End Tag

Start Tag

XML = eXtensible Markup LanguageWhat is XML?

5

9 © 2008 IBM Corporation

<book><authors>

<author id=“47”>John Doe</author><author id=“58”>Peter Pan</author>

</authors><title>Database systems</title><price>29</price><keywords>

<keyword>SQL</keyword><keyword>relational</keyword>

</keywords></book>

<book price=“29” title=“Database systems“><authors>

<author><id>47</id><name>John Doe</name>

</author><author>

<id>58</id><name>Peter Pan</name>

</author></authors><keywords>

<keyword>SQL</keyword><keyword>relational</keyword>

</keywords></book>Design Choice

• Elements can be repeated, e.g. “keyword”, “author”. Attributes can not.• Elements can be extended (made deeper), e.g. “author”.• Attributes are shorter, can often be stored/processed more efficiently.

Attributes vs. Elements

10 © 2008 IBM Corporation

<book><authors>

<author id=“47”>John Doe</author><author id=“58”>Peter Pan</author>

</authors><title>Database systems</title><price>29</price><keywords>

<keyword>SQL</keyword><keyword>relational</keyword>

</keywords></book>

XML Parsing

book

title price

author

authors

author

keywords

keyword keyword

id=47 id=58 SQL relational

DatabaseSystems 29

John Doe Peter Pan

Serialization

The XML Document Tree

6

11 © 2008 IBM Corporation

Answer 1: eXtensible Markup Language

Answer 2: A hierarchical data model !

A data model, consisting of nodes of several types linked through ordered parent/child relationships to form a hierarchy.

Only one representation of that data model is textual,there are others that are not text....

What is XML?

12 © 2008 IBM Corporation

XML vs. Relational

<DEPARTMENT deptid="15" deptname="Sales"><EMPLOYEE>

<EMPNO>10</EMPNO><FIRSTNAME>CHRISTINE</FIRSTNAME><LASTNAME>SMITH</LASTNAME><PHONE>408-463-4963</PHONE><SALARY>52750.00</SALARY>

</EMPLOYEE><EMPLOYEE>

<EMPNO>27</EMPNO><FIRSTNAME>MICHAEL</FIRSTNAME><LASTNAME>THOMPSON</LASTNAME> <SALARY>41250.00</SALARY>

</EMPLOYEE></DEPARTMENT> Department

DEPTID DEPTNAME15 Sales

EmployeeDEPTID EMPNO FIRSTNAME LASTNAME PHONE SALARY

15 27 MICHAEL THOMPSON NULL 4125015 10 CHRISTINE SMITH 408-463-4963 52750

Relational XMLSet oriented Sequences (ordered!)Structure Semi-structuredStrong schema Schema-chaosStrongly typed Optionally typedTabular data model XML data modelFlat Nested, hierarchical3 value logic 2 value logic"Null" Not there at allANSI/ISO W3C

7

13 © 2008 IBM Corporation

Schema Evolution

<DEPARTMENT deptid="15" deptname="Sales"><EMPLOYEE>

<EMPNO>10</EMPNO><FIRSTNAME>CHRISTINE</FIRSTNAME><LASTNAME>SMITH</LASTNAME><PHONE>408-463-4963</PHONE><PHONE>415-010-1234</PHONE><SALARY>52750.00</SALARY>

</EMPLOYEE><EMPLOYEE>

<EMPNO>27</EMPNO><FIRSTNAME>MICHAEL</FIRSTNAME><LASTNAME>THOMPSON</LASTNAME><PHONE>406-463-1234</PHONE><SALARY>41250.00</SALARY>

</EMPLOYEE></DEPARTMENT>

PhoneEMPNO PHONE

27 406-463-123410 415-010-123410 408-463-4963

Requires:• Normalization of existing data !• Change of applications

Costly!

DepartmentDEPTID DEPTNAME

15 SalesEmployeeDEPTID EMPNO FIRSTNAME LASTNAME PHONE SALARY

15 27 MICHAEL THOMPSON 406-463-1234 4125015 10 CHRISTINE SMITH 408-463-4963 52750

“Employees are now allowed to have multiple phone numbers…”

14 © 2008 IBM Corporation

Agenda

What is XML ?

Well-formed XML documents

Namespaces

XPATH

XML Schema

What is XSL?

XML Parsers: DOM vs. SAX

Further Reading

8

15 © 2008 IBM Corporation

Well-formed XML Documents

An XML document is well-formed, if:

See http://www.w3.org/TR/REC-xml for full definition.

………

<a><b>bla</b></a><a><b>bla</a>Each opening tag is matched by a closing tag

<a> 3&lt;5 </a><a> 3<5 </a>Does not use disallowed characters in tags or values

<a id=“15”></a><a id=15></a>Attribute values must be quoted

<a><b>bla</b></a><a><b>bla</a></b>All elements are properly nested

<a>

<b>bla</b>

<c>blub</c>

</a>

<b>bla</b>

<c>blub</c>Has exactly one root element

Well-formednot well-formed

16 © 2008 IBM Corporation

<?xml version="1.0"?><book>

<authors><author id=“47”>John Doe</author><author id=“58”>Peter Pan</author>

</authors><title>Database systems</title><price>29</price><keywords>

<keyword>SQL</keyword><keyword>relational</keyword>

</keywords></book>

<?xml version="1.0" encoding="UTF-8"?><book>

<authors><author id=“47”>John Doe</author><author id=“58”>Peter Pan</author>

</authors><title>Database systems</title><price>29</price><keywords>

<keyword>SQL</keyword><keyword>relational</keyword>

</keywords></book>

The XML Declaration is NOT required for wellformedness.Nobody uses XML 1.1.Encoding Declaration optional. Encoding can also be determined by the application code page or a Unicode Byte Order Mark (BOM)

The XML Declaration

9

17 © 2008 IBM Corporation

“Well-formed” or “valid”?

An XML document is well-formed, if…

– …it complies with the rules on the previous page

– i.e. it can be parsed by an XML parser without error

An XML document is valid, if…

– …it is well-formed AND

– …it complies with a specific DTD or XML Schema

• XML Parsers can optionally perform “validation”

(Document Type Definitions) and XML Schema define a specific XML document structure

18 © 2008 IBM Corporation

<book><authors>

<author id=“47”>John Doe</author><author id=“58”>Peter Pan</author>

</authors><title>Database systems</title><price>29</price><keywords>

<keyword>SQL</keyword><keyword>relational</keyword>

</keywords></book>

book

title price

author

authors

author

keywords

keyword keyword

id=47 id=58 SQL relational

DatabaseSystems 29

John Doe Peter Pan

Document node Document node Element nodesElement nodesAttribute nodesAttribute nodesText nodesText nodesNamespace nodesNamespace nodesProcessing instruction nodesProcessing instruction nodesComment nodesComment nodes

txt

Matthias Nicola, IBM SVL

The XML Data Model: Node Types

10

19 © 2008 IBM Corporation

<customerinfo><name>Matt Foreman</name><phone>905-555-4789</phone>

</customerinfo>

customerinfo

phonename

905-555-4789Matt ForemanText

Nodes

ElementNodes

<customerinfo><name>Matt<MI>P</MI>Foreman</name><phone>905-555-4789</phone>

</customerinfo>

customerinfo

phone

MI

name

905-555-4789Matt Foreman

P

Mixed Content: An element containstext AND other elements

Text Nodes and Mixed Content

20 © 2008 IBM Corporation

Agenda

What is XML ?

Well-formed XML documents

Namespaces

XPATH

XML Schema

What is XSL?

XML Parsers: DOM vs. SAX

Further Reading

11

21 © 2008 IBM Corporation

Problem: Name Collision

Three different XML elements:

<title>Database Administrator</title>

<title>Mr</title>

<title>Gone with the wind</title>

Same element name, but different meaning !

Can result in processing/application errors.

Need to distinguish between different domains.

22 © 2008 IBM Corporation

Solution: Namespaces

A prefix identifies the domain (“namespace”), and

distinguishes between duplicate element names

<job:title>Database Administrator</job:title>

<person:title>Mr</person:title>

<movies:title>Gone with the wind</movies:title>

Namespaces need to be uniquely identified….-> URIs

12

23 © 2008 IBM Corporation

URI = Universal Resource Identifier

URI Examples:

http://www.ibm.com/db2xml

http://abcdefghijklmn.xyz

URIs uniquely identify a namespace

URIs typically look like a URL

URIs are just an identifier, they may to point to a web page, but don’t have to !

For more details on URIs see http://www.ietf.org/rfc/rfc2396.txt

24 © 2008 IBM Corporation

Namespace Declaration and URIs

The reserved attribute “xmlns” defines namespaces, and (optionally) assigns them to a namespace prefix

Example: element name: person namespace URI: http://www.foobar.orgnamespace prefix: foo

<foo:person xmlns:foo="http://www.foobar.org"><foo:name>John Doe</foo:name>

</foo:person>

The namespace applies to the current element and all sub-elements and attributes that it contains.

13

25 © 2008 IBM Corporation

Multiple Namespaces

<cust:person xmlns:cust=“http://www.foobar.com/customer”><cust:name>John Doe</cust:name><prod:product xmlns:prod=“http://www.foobar.com/product”>

<prod:name>Thinkpad T40</prod:name><prod:orderdate>2004-11-18</prod:orderdate>

</prod:product></cust:person>

The namespace applies to the current element and all sub-elements and attributes that it contains – unless it’s overridden !

Scope of the namespace “prod”

26 © 2008 IBM Corporation

Default Namespaces

<person xmlns=“http://www.foobar.org”><age>45</age><name>

<first>John</first><last>Doe</last>

</name></person>

A namespace declaration without prefix defines a defaultnamespace. The namespace is implicit for all elements/attributes in scope, without using a prefix.

The default namespace applies to the current element and all sub-elements (but not to attributes) that it contains.

14

27 © 2008 IBM Corporation

Agenda

What is XML ?

Well-formed XML documents

Namespaces

XPATH

XML Schema

What is XSL?

XML Parsers: DOM vs. SAX

Further Reading

28 © 2008 IBM Corporation

<dept bldg=“101”><employee id=“901”>

<name>John Doe</name><phone>408 555 1212</phone><office>344</office>

</employee><employee id=“902”>

<name>Peter Pan</name><phone>408 555 9918</phone><office>216</office>

</employee></dept>

//dept/dept/employee/dept/employee/@id/dept/employee/name/dept/employee/phone/dept/employee/phone/text()(...)

Each nodehas a path

XPath Concepts

dept

name

employee

phoneid=901

John Doe

office

408-555-1212 344

name

employee

phoneid=902

Peter Pan

office

408-555-9918 216

bldg=101

15

29 © 2008 IBM Corporation

XPath:Simple XPath Expressions

Use fully qualified paths to specify elements/attributes“@” is used to specify an attributeuse “text()” to specify the text node under an element

John Doe

Peter Pan

/dept/employee/name/text()

<name>John Doe</name>

<name>Peter Pan</name>

/dept/employee/name

901

902

/dept/employee/@id

101/dept/@bldg

ResultXPath

<dept bldg=“101”><employee id=“901”>

<name>John Doe</name><phone>408 555 1212</phone><office>344</office>

</employee><employee id=“902”>

<name>Peter Pan</name><phone>408 555 9918</phone><office>216</office>

</employee></dept>

30 © 2008 IBM Corporation

XPath:Wildcards

* matches any tag name // is the “descendent-or-self” wildcard

<phone>408 555 1212</phone>

<phone>408 555 9918</phone>/dept//phone

John Doe

Peter Pan//name/text()

901

902/dept/*/@id

John Doe

408 555 1212

344

Peter Pan

408 555 9918

216

/dept/employee/*/text()

ResultXPath

<dept bldg=“101”><employee id=“901”>

<name>John Doe</name><phone>408 555 1212</phone><office>344</office>

</employee><employee id=“902”>

<name>Peter Pan</name><phone>408 555 9918</phone><office>216</office>

</employee></dept>

16

31 © 2008 IBM Corporation

XPath:Predicates

Predicates are enclosed in square brackets […]Can have multiple predicates in one XpathPositional predicates: [n] selects the n-th child

902/dept/employee[2]/@id

901

902

//employee[office=“344” or office=“216”]/@id

<name>John Doe</name>/dept[@bldg=“101”]/employee[office >“300”]/name

<name>Peter Pan</name>/dept/employee[@id=“902”]/name

ResultXPath

<dept bldg=“101”><employee id=“901”>

<name>John Doe</name><phone>408 555 1212</phone><office>344</office>

</employee><employee id=“902”>

<name>Peter Pan</name><phone>408 555 9918</phone><office>216</office>

</employee></dept>

32 © 2008 IBM Corporation

XPath:The Parent Axis

Current context: “.”Parent context: “..”

<office>344</office>/dept/employee[office > “300”]/office

<name>Peter Pan</name>/dept/employee/name[../@id=“902”]

101/dept/employee/name[.=“John Doe”]/../../@bldg

101/dept/employee[name=“John Doe”]/../@bldg

<office>344</office>/dept/employee/office[.>“300”]

ResultXPath

<dept bldg=“101”><employee id=“901”>

<name>John Doe</name><phone>408 555 1212</phone><office>344</office>

</employee><employee id=“902”>

<name>Peter Pan</name><phone>408 555 9918</phone><office>216</office>

</employee></dept>

17

33 © 2008 IBM Corporation

XPath:Namespaces

Add prefixes to XPath steps !Could also use *: as wildcard

<dep:dept xmlns:dep=“http://www.foobar.com/dept” bldg=“101”><dep:employee id=“901”>

<dep:name>John Doe</dep:name><dep:phone>408 555 1212</dep:phone><dep:office>344</dep:office>

</dep:employee><dep:employee id=“902”>

<dep:name>Peter Pan</dep:name><dep:phone>408 555 9918</dep:phone><dep:office>216</dep:office>

</dep:employee></dep:dept>

/dept/employee/name

901

902

/dep:dept/dep:employee/@id

<name>Peter Pan</name>

<name>John Doe</name>

/dep:dept/dep:employee/dep:name

ResultXPath

34 © 2008 IBM Corporation

Agenda

What is XML ?

Well-formed XML documents

Namespaces

XPATH

XML Schema

What is XSL?

XML Parsers: DOM vs. SAX

Further Reading

18

35 © 2008 IBM Corporation

What is an XML Schema?

Defines structure, content, data types for XML documents

Consists of 1 or more schema documents

A schema document can define a namespace (optionally)

Example:

– 1 XML Schema, 3 Schema Documents, 2 Namespaces

order.xsd

Order Lineitem

lineitem.xsd parts.xsd

import

include

Namespace: Namespace:Orderschema

http://www.w3.org/TR/xmlschema-0/

36 © 2008 IBM Corporation

Advantages of XML Schema over DTDs

Can define data types for elements/attributes

– Basic types: integer, date, decimal, string, etc.

– User Defined Types, Complex Element Types, etc.

– Allowed length and patterns for string values

– Supports type inheritance and derived data types

An XML Schema document is in XML syntax

– You can use same editors/parsers/appls to manipulate them

Detailed occurrence and value range definitions

XML Schema supports XML Namespaces

Can define a certain element to be the root element

A Schema can be composed of multiple schema documents

– Import/Include of other schemas is supported

19

37 © 2008 IBM Corporation

Types in XML Schema

Built-In Simple Types:

string

boolean

float

double

decimal

integer

positiveInteger

byte

date

datetime

anyType

….

Derived Simple Types:

Restriction of a simple type“integer between 5 and 10”

Union of simple types“integer ∪ string”

Enumerations

etc.

Complex Types:

may include elements/attribute definitions

can define choice or sequence of elements

38 © 2008 IBM Corporation

<xsd:schema targetNamespace=“http://www.mycompany/products“xmlns:xsd="http://www.w3.org/2001/XMLSchema“>

<xsd:simpleType name=“PriceType"><xsd:restriction base="xsd:decimal">

<xsd:minInclusive value="0"/><xsd:maxInclusive value=“100000"/><xsd:totalDigits value=“9"/><xsd:fractionDigits value=“3"/>

</xsd:restriction></xsd:simpleType><xsd:complexType name=“StockPriceType">

<xsd:sequence><xsd:element name="Ask" type="PriceType"/><xsd:element name="Bid" type="PriceType"/><xsd:element name="P50DayAvg" type="PriceType"/>

</xsd:sequence></xsd:complexType><xsd:element name=“StockPrice" type=“StockPriceType"/>

</xsd:schema >

XML Schema: Example

XML Schema Namespace

20

39 © 2008 IBM Corporation

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema“>……

</xsd:schema>

The XML Schema Namespace

All predefined XML Schema tags (e.g. simpleType, restriction, sequence) are from one namespace, i.e. the XML schema namespace

xs: and xsd: are commonly used prefixes.

Therefore, all XML schemas begin and end like this:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema“>……

</xsd:schema>

40 © 2008 IBM Corporation

XML Schema: Simple & Complex Types<xsd:simpleType name=“PriceType">

<xsd:restriction base="xsd:decimal"><xsd:minInclusive value="0"/><xsd:maxInclusive value=“100000"/><xsd:totalDigits value=“9"/><xsd:fractionDigits value=“3"/>

</xsd:restriction></xsd:simpleType>

PriceType: derived from “Decimal” by defining additional restrictions

Once defined, PriceTypecan be used multiple times!

<StockPrice><Ask>96.349</Ask><Bid>95.871</Bid><P50DayAvg>89.304</P50DayAvg>

</StockPrice>

<xsd:complexType name=“StockPriceType"><xsd:sequence>

<xsd:element name="Ask" type="PriceType"/><xsd:element name="Bid" type="PriceType"/><xsd:element name="P50DayAvg" type="PriceType"/>

</xsd:sequence></xsd:complexType>

<xsd:element name=“StockPrice" type=“StockPriceType"/>

A valid instance document:

21

41 © 2008 IBM Corporation

<xsd:schematargetNamespace=“http://www.mycompany/products“

xmlns:xsd=“http://www.w3.org/2001/XMLSchema”>….

<xsd:element name=“ProductCode" type=“ProductCodeType"/>…..

</xsd:schema>

The Target Namespace

XML Schemas often define a vocabulary of XML elements, attributes, and types, e.g. FIXML, FpML, ACORD, newsML, etc.

A Target Namespace (optional) is a new namespace that represents the vocabulary defined in an XML Schema.

<mpc:product xmlns:mpc=“http://www.mycompany/products“<mpc:ProductCode>457KF</mpc:ProductCode>

</mpc:product>

XML Schema

XML Document

42 © 2008 IBM Corporation

Agenda

What is XML ?

Well-formed XML documents

Namespaces

XPATH

XML Schema

What is XSL?

XML Parsers: DOM vs. SAX

Further Reading

22

43 © 2008 IBM Corporation

XSL = Extensible Stylesheet Language

Purpose: Transformation & formatting of XML documents

XSL = XSLT + XSLFO

– XSLT: language for transforming XML

– XSLFO: language for formatting XML

44 © 2008 IBM Corporation

XSL = Extensible Stylesheet Language

<dept bldg=“101”><employee id=“901”>

<name>John Doe</name><phone>408 555 1212</phone><office>344</office>

</employee></dept>

XSLStyle

Sheet 1

<emp name=“John Doe”><empNo>901</empNo><contact>

<phone>408 555 1212</phone><room>344</room>

</contact> </emp>

XSLStyle

Sheet 2

XSL(FO)Style

Sheet 3

John Doe;901;408 555 1212;344

23

45 © 2008 IBM Corporation

http://www.w3schools.com/http://www.w3schools.com/xml/http://www.w3schools.com/dtd/http://www.w3schools.com/schema/http://www.w3schools.com/xpath/http://www.w3schools.com/xsl/http://www.w3schools.com/xml/xml_namespaces.asp…

Many online tutorialsavailable….

Further Reading (XML Fundamentals)

46 © 2008 IBM Corporation

Summary

Well-formed vs. valid XML documents

Namespaces– Avoid naming collisions

– Define XML vocabularies

DTDs and XML Schema

– DTDs are good but XML Schemas are better

– XML Schemas support data types & namespaces

XPATH, XQuery, SQL/XML: – Search & retrieve XML

24

47 © 2008 IBM Corporation

Questions?

db2 =>

48 © 2008 IBM Corporation

IBM Software Group

Data Management – DB2 9.5 pureXML ®

Summer/Fall 2008

Data Management SolutionsInformation ManagementIBM Software Group

25

49 © 2008 IBM Corporation

IBM Software Group

Data Management SolutionsInformation ManagementIBM Software Group

XML Basics

50 © 2008 IBM Corporation

BACK UP

26

51 © 2008 IBM Corporation

Sample XML Document: Personnel data

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE personnelRec SYSTEM "prml.dtd"><!-- This is a comment --><personnelRec>

<person salary="26350.00" band="D"><name>

<family>Wallace</family> <given>Bob</given>

</name><email>[email protected]</email><dept>&d1</dept>

</person></personnelRec>

XML declaration

Document Type Definition

(DTD)

Document Type Declaration

Entity reference

Root Element

52 © 2008 IBM Corporation

document

ISBN title

first

url

book

author

version

last

publisher

comment

year

DocumentNode

ElementNode

AttributeNode

TextNode

CommentNode

Seven types of XML nodesDocument node Document node (1 per document)(1 per document)

Element nodesElement nodesText nodesText nodesAttribute nodesAttribute nodesNamespace nodesNamespace nodesProcessing instruction Processing instruction nodesnodesComment nodesComment nodes

<?xml version=”1.0” ?><book ISBN=”0 262 11170 5”>

<title>Genetic Programming</title><author>

<last>Koza</last><first>John</first>

</author><publisher year=”1992”>

The MIT Press</publisher><url>http://www.genetic.org</url>

</book><!-- comment at end -->

27

53 © 2008 IBM Corporation

Restricting String Types in XML Schema

<xsd:simpleType name=“ProductCodeType"><xsd:restriction base="xsd:string">

<xsd:pattern value="\d{3}[A-Z]{2}"/></xsd:restriction>

</xsd:simpleType>

<ProductCode>023ZQ</ProductCode>

<xsd:element name=“ProductCode" type=“ProductCodeType"/>

“Our product codes consist of 3 digits followed by 2 uppercase characters between A and Z….”

<ProductCode>457KF</ProductCode>

<ProductCode>91PA</ProductCode>

54 © 2008 IBM Corporation

XQuery Data Model & Expressions

Every instance (value) of the data model is an ordered sequence of 0 or more items

XQuery expressions take one instance of the XQuery data model & transform it into another instance of the data model

Every XML doc is an instance of the data model, not vice versa!

XQuery result can be an XML document, but not necessarily! Can be a sequence of >1 item.

XMLDocuments

XQueryData Model

XMLDocuments

XQueryData Model

XQuery

(items = nodes, documents, atomic values)