xml [Uyumluluk Modu]bekirdizdaroglu.com/ceng/Downloads/xml.pdf · Title: Microsoft PowerPoint - xml...

44
XML Document Type Definitions Document Type Definitions XML Schema 1

Transcript of xml [Uyumluluk Modu]bekirdizdaroglu.com/ceng/Downloads/xml.pdf · Title: Microsoft PowerPoint - xml...

Page 1: xml [Uyumluluk Modu]bekirdizdaroglu.com/ceng/Downloads/xml.pdf · Title: Microsoft PowerPoint - xml [Uyumluluk Modu] Author: Toshiba Created Date: 11/24/2008 5:58:41 PM

XML

Document Type DefinitionsDocument Type DefinitionsXML Schema

1

Page 2: xml [Uyumluluk Modu]bekirdizdaroglu.com/ceng/Downloads/xml.pdf · Title: Microsoft PowerPoint - xml [Uyumluluk Modu] Author: Toshiba Created Date: 11/24/2008 5:58:41 PM

Well-Formed and Valid XML

Well-Formed XML allows you to invent your own tags.Valid XML conforms to a certain DTDValid XML conforms to a certain DTD.

2

Page 3: xml [Uyumluluk Modu]bekirdizdaroglu.com/ceng/Downloads/xml.pdf · Title: Microsoft PowerPoint - xml [Uyumluluk Modu] Author: Toshiba Created Date: 11/24/2008 5:58:41 PM

Well-Formed XML

Start the document with a declaration, d d b ? l ?surrounded by <?xml … ?> .

Normal declaration is:<?xml version = ”1.0” standalone = ”yes” ?>standalone yes ?>

“standalone” = “no DTD provided.”Balance of document is a root tagBalance of document is a root tagsurrounding nested tags.

3

Page 4: xml [Uyumluluk Modu]bekirdizdaroglu.com/ceng/Downloads/xml.pdf · Title: Microsoft PowerPoint - xml [Uyumluluk Modu] Author: Toshiba Created Date: 11/24/2008 5:58:41 PM

Tags

Tags are normally matched pairs, as <FOO> … </FOO>.Unmatched tags also allowed asUnmatched tags also allowed, as <FOO/>T b d bi ilTags may be nested arbitrarily.XML tags are case-sensitive.XML tags are case sensitive.

4

Page 5: xml [Uyumluluk Modu]bekirdizdaroglu.com/ceng/Downloads/xml.pdf · Title: Microsoft PowerPoint - xml [Uyumluluk Modu] Author: Toshiba Created Date: 11/24/2008 5:58:41 PM

Example: Well-Formed XML

<?xml version = “1.0” standalone = “yes” ?><BARS>

A NAMEsubelement<BARS>

<BAR><NAME>Joe’s Bar</NAME><LEMONADE><NAME>Bud</NAME><LEMONADE><NAME>Bud</NAME>

<PRICE>2.50</PRICE></LEMONADE><LEMONADE><NAME>Miller</NAME>Root tag <LEMONADE><NAME>Miller</NAME>

<PRICE>3.00</PRICE></LEMONADE></BAR> A LEMONADE

Root tag

/<BAR> …

</BARS>

A LEMONADEsubelement

Tags surroundinga LEMONADE element

5

Page 6: xml [Uyumluluk Modu]bekirdizdaroglu.com/ceng/Downloads/xml.pdf · Title: Microsoft PowerPoint - xml [Uyumluluk Modu] Author: Toshiba Created Date: 11/24/2008 5:58:41 PM

DTD Structure

<!DOCTYPE <root tag> [<!ELEMENT <name>(<components>)>

more elements. . . more elements . . .]>

6

Page 7: xml [Uyumluluk Modu]bekirdizdaroglu.com/ceng/Downloads/xml.pdf · Title: Microsoft PowerPoint - xml [Uyumluluk Modu] Author: Toshiba Created Date: 11/24/2008 5:58:41 PM

DTD Elements

The description of an element consists of its name (tag), and a parenthesized description of any nested tags.p y g

Includes order of subtags and their multiplicitymultiplicity.

Leaves (text elements) have #PCDATA (P d Ch t DATA ) i l f(Parsed Character DATA ) in place of nested tags.

7

Page 8: xml [Uyumluluk Modu]bekirdizdaroglu.com/ceng/Downloads/xml.pdf · Title: Microsoft PowerPoint - xml [Uyumluluk Modu] Author: Toshiba Created Date: 11/24/2008 5:58:41 PM

Example: DTD

<!DOCTYPE BARS [A BARS object haszero or more BAR’snested within

<!ELEMENT BARS (BAR*)><!ELEMENT BAR (NAME, LEMONADE+)>

nested within.

( , )<!ELEMENT NAME (#PCDATA)><!ELEMENT LEMONADE (NAME PRICE)><!ELEMENT LEMONADE (NAME, PRICE)><!ELEMENT PRICE (#PCDATA)>

A LEMONADE has a]>

A BAR has one

A LEMONADE has aNAME and aPRICE.

NAME and PRICEare text.

8

A BAR has oneNAME and oneor more LEMONADE subobjects.

Page 9: xml [Uyumluluk Modu]bekirdizdaroglu.com/ceng/Downloads/xml.pdf · Title: Microsoft PowerPoint - xml [Uyumluluk Modu] Author: Toshiba Created Date: 11/24/2008 5:58:41 PM

Element Descriptions

Subtags must appear in order shown.A tag may be followed by a symbol to indicate its multiplicityindicate its multiplicity.

* = zero or more.+ = one or more.? = zero or one.

Symbol | can connect alternative sequences of tags

9

sequences of tags.

Page 10: xml [Uyumluluk Modu]bekirdizdaroglu.com/ceng/Downloads/xml.pdf · Title: Microsoft PowerPoint - xml [Uyumluluk Modu] Author: Toshiba Created Date: 11/24/2008 5:58:41 PM

Example: Element Description

A name is an optional title (e.g., “Prof.”), a first name, and a last name, in that order, or it is an IP address:,

<!ELEMENT NAME (( ) |(TITLE?, FIRST, LAST) | IPADDR

)>)

10

Page 11: xml [Uyumluluk Modu]bekirdizdaroglu.com/ceng/Downloads/xml.pdf · Title: Microsoft PowerPoint - xml [Uyumluluk Modu] Author: Toshiba Created Date: 11/24/2008 5:58:41 PM

Use of DTD’s

1. Set standalone = “no”.2. Either:

a) Include the DTD as a preamble of thea) Include the DTD as a preamble of the XML document, or

b) Follow DOCTYPE and the <root tag> byb) Follow DOCTYPE and the <root tag> by SYSTEM and a path to the file where the DTD can be foundDTD can be found.

11

Page 12: xml [Uyumluluk Modu]bekirdizdaroglu.com/ceng/Downloads/xml.pdf · Title: Microsoft PowerPoint - xml [Uyumluluk Modu] Author: Toshiba Created Date: 11/24/2008 5:58:41 PM

E l ( )Example: (a)<?xml version = “1.0” standalone = “no” ?><!DOCTYPE BARS [

<!ELEMENT BARS (BAR*)>The DTD<!ELEMENT BAR (NAME, LEMONADE+)>

<!ELEMENT NAME (#PCDATA)><!ELEMENT LEMONADE (NAME, PRICE)>

The DTD

Th d t( , )

<!ELEMENT PRICE (#PCDATA)>]><BARS>

The document

<BARS><BAR><NAME>Joe’s Bar</NAME>

<LEMONADE><NAME>Bud</NAME> <PRICE>2.50</PRICE></LEMONADE><PRICE>2.50</PRICE></LEMONADE>

<LEMONADE><NAME>Miller</NAME> <PRICE>3.00</PRICE></LEMONADE></BAR>

12

/BAR <BAR> …

</BARS>

Page 13: xml [Uyumluluk Modu]bekirdizdaroglu.com/ceng/Downloads/xml.pdf · Title: Microsoft PowerPoint - xml [Uyumluluk Modu] Author: Toshiba Created Date: 11/24/2008 5:58:41 PM

Example: (b)

Assume the BARS DTD is in file bar.dtd.<?xml version “1 0” standalone “no” ?><?xml version = 1.0 standalone = no ?><!DOCTYPE BARS SYSTEM ”bar.dtd”><BARS> Get the DTD

<BAR><NAME>Joe’s Bar</NAME><LEMONADE><NAME>Bud</NAME>

<PRICE>2 50</PRICE></LEMONADE>

from the filebar.dtd

<PRICE>2.50</PRICE></LEMONADE><LEMONADE><NAME>Miller</NAME>

<PRICE>3.00</PRICE></LEMONADE></BAR><BAR> …

</BARS>

13

</BARS>

Page 14: xml [Uyumluluk Modu]bekirdizdaroglu.com/ceng/Downloads/xml.pdf · Title: Microsoft PowerPoint - xml [Uyumluluk Modu] Author: Toshiba Created Date: 11/24/2008 5:58:41 PM

Attributes

Opening tags in XML can have attributes.In a DTDIn a DTD,

<!ATTLIST E . . . >declares attributes for element E, along with its datatype.with its datatype.

14

Page 15: xml [Uyumluluk Modu]bekirdizdaroglu.com/ceng/Downloads/xml.pdf · Title: Microsoft PowerPoint - xml [Uyumluluk Modu] Author: Toshiba Created Date: 11/24/2008 5:58:41 PM

Example: Attributes

Bars can have an attribute kind, a character string describing the bar.

<!ELEMENT BAR (NAME, LEMONADE*)><!ELEMENT BAR (NAME, LEMONADE )><!ATTLIST BAR kind CDATA

##IMPLIED>Character stringt ttype; no tags

Attribute is optionalopposite: #REQUIRED

15

Page 16: xml [Uyumluluk Modu]bekirdizdaroglu.com/ceng/Downloads/xml.pdf · Title: Microsoft PowerPoint - xml [Uyumluluk Modu] Author: Toshiba Created Date: 11/24/2008 5:58:41 PM

Example: Attribute Use

In a document that allows BAR tags, we might see:

<BAR kind = ”sushi”><NAME>Homma’s</NAME><LEMONADE><NAME>Sapporo</NAME><LEMONADE><NAME>Sapporo</NAME>

<PRICE>5 00</PRICE></LEMONADE><PRICE>5.00</PRICE></LEMONADE>...

16</BAR>

Page 17: xml [Uyumluluk Modu]bekirdizdaroglu.com/ceng/Downloads/xml.pdf · Title: Microsoft PowerPoint - xml [Uyumluluk Modu] Author: Toshiba Created Date: 11/24/2008 5:58:41 PM

ID’s and IDREF’s

Attributes can be pointers from one object to another.

Compare to HTML’s NAME = ”foo” andCompare to HTML s NAME foo and HREF = ”#foo”.

Allows the structure of an XMLAllows the structure of an XML document to be a general graph, rather th j t tthan just a tree.

17

Page 18: xml [Uyumluluk Modu]bekirdizdaroglu.com/ceng/Downloads/xml.pdf · Title: Microsoft PowerPoint - xml [Uyumluluk Modu] Author: Toshiba Created Date: 11/24/2008 5:58:41 PM

Creating ID’s

Give an element E an attribute A of type ID.When using tag <E > in an XMLWhen using tag <E > in an XML document, give its attribute A a unique valuevalue.Example:p

<E A = ”xyz”>

18

Page 19: xml [Uyumluluk Modu]bekirdizdaroglu.com/ceng/Downloads/xml.pdf · Title: Microsoft PowerPoint - xml [Uyumluluk Modu] Author: Toshiba Created Date: 11/24/2008 5:58:41 PM

Creating IDREF’s

To allow elements of type F to refer to another element with an ID attribute, give F an attribute of type IDREF.g ypOr, let the attribute have type IDREFS, so the F element can refer to anyso the F -element can refer to any number of other elements.

19

Page 20: xml [Uyumluluk Modu]bekirdizdaroglu.com/ceng/Downloads/xml.pdf · Title: Microsoft PowerPoint - xml [Uyumluluk Modu] Author: Toshiba Created Date: 11/24/2008 5:58:41 PM

Example: ID’s and IDREF’s

A new BARS DTD includes both BAR and LEMONADE b l tLEMONADE subelements.BARS and LEMONADES have ID attributes name.BARS have SELLS subelements, consisting of , ga number (the price of one lemonade) and an IDREF theLemonade leading to that glemonade.LEMONADES have attribute soldBy, which is

20

LEMONADES have attribute soldBy, which is an IDREFS leading to all the bars that sell it.

Page 21: xml [Uyumluluk Modu]bekirdizdaroglu.com/ceng/Downloads/xml.pdf · Title: Microsoft PowerPoint - xml [Uyumluluk Modu] Author: Toshiba Created Date: 11/24/2008 5:58:41 PM

The DTD Bar elements have nameThe DTD!DOCTYPE BARS [

as an ID attribute andhave one or moreSELLS subelements.<!DOCTYPE BARS [

<!ELEMENT BARS (BAR*, LEMONADE*)><!ELEMENT BAR (SELLS+)>

SELLS elements

SELLS subelements.

<!ELEMENT BAR (SELLS+)><!ATTLIST BAR name ID #REQUIRED>

<!ELEMENT SELLS (#PCDATA)>

have a number(the price) andone reference<!ELEMENT SELLS (#PCDATA)>

<!ATTLIST SELLS theLemonade IDREF #REQUIRED><!ELEMENT LEMONADE EMPTY>

to a lemonade.

<!ELEMENT LEMONADE EMPTY><!ATTLIST LEMONADE name ID #REQUIRED><!ATTLIST LEMONADE soldBy IDREFS #IMPLIED>y

]>Lemonade elements have an ID attribute called name,and a soldBy attribute that is a set of Bar names

Explainedt

21

and a soldBy attribute that is a set of Bar names.next

Page 22: xml [Uyumluluk Modu]bekirdizdaroglu.com/ceng/Downloads/xml.pdf · Title: Microsoft PowerPoint - xml [Uyumluluk Modu] Author: Toshiba Created Date: 11/24/2008 5:58:41 PM

Example: A Document

<BARS><BAR name = ”JoesBar”>

<SELLS theLemonade = ”Bud”>2.50</SELLS>/<SELLS theLemonade = ”Miller”>3.00</SELLS>

</BAR></BAR> …<LEMONADE name = ”Bud” soldBy = ”JoesBar

SuesBar …” /> …</BARS>

22

/

Page 23: xml [Uyumluluk Modu]bekirdizdaroglu.com/ceng/Downloads/xml.pdf · Title: Microsoft PowerPoint - xml [Uyumluluk Modu] Author: Toshiba Created Date: 11/24/2008 5:58:41 PM

Empty Elements

We can do all the work of an element in its attributes.

Like LEMONADE in previous example.Like LEMONADE in previous example.

Another example: SELLS elements could have attribute i rather thancould have attribute price rather than a value that is a price.

23

Page 24: xml [Uyumluluk Modu]bekirdizdaroglu.com/ceng/Downloads/xml.pdf · Title: Microsoft PowerPoint - xml [Uyumluluk Modu] Author: Toshiba Created Date: 11/24/2008 5:58:41 PM

Example: Empty Element

In the DTD, declare:<!ELEMENT SELLS EMPTY>

<!ATTLIST SELLS h d IDREF #REQUIRED><!ATTLIST SELLS theLemonade IDREF #REQUIRED><!ATTLIST SELLS price CDATA #REQUIRED>Example use:

<SELLS theLemonade ”Bud” price ”2 50” /><SELLS theLemonade = ”Bud” price = ”2.50” />

Note exception to24

Note exception to“matching tags” rule

Page 25: xml [Uyumluluk Modu]bekirdizdaroglu.com/ceng/Downloads/xml.pdf · Title: Microsoft PowerPoint - xml [Uyumluluk Modu] Author: Toshiba Created Date: 11/24/2008 5:58:41 PM

XML Schema

A more powerful way to describe the structure of XML documents.XML-Schema declarations areXML Schema declarations are themselves XML documents.

Th d ib “ l t ” d th thiThey describe “elements” and the things doing the describing are also “elements.”

25

Page 26: xml [Uyumluluk Modu]bekirdizdaroglu.com/ceng/Downloads/xml.pdf · Title: Microsoft PowerPoint - xml [Uyumluluk Modu] Author: Toshiba Created Date: 11/24/2008 5:58:41 PM

Structure of an XML SchemaStructure of an XML-Schema DocumentDocument

<? xml version = … ?><xs:schema xmlns:xs =”http://www w3 org/2001/XMLschema”>http://www.w3.org/2001/XMLschema >

. . .

</xs:schema> Defines ”xs” to be thenamespace described inpthe URL shown. Any stringin place of ”xs” is OK.

So uses of ”xs” within theschema element refer to

26tags from this namespace.

Page 27: xml [Uyumluluk Modu]bekirdizdaroglu.com/ceng/Downloads/xml.pdf · Title: Microsoft PowerPoint - xml [Uyumluluk Modu] Author: Toshiba Created Date: 11/24/2008 5:58:41 PM

The xs:element Element

Has attributes:1. name = the tag-name of the element

being defined.g2. type = the type of the element.

Could be an XML-Schema type e gCould be an XML Schema type, e.g., xs:string.Or the name of a type defined in theOr the name of a type defined in the document itself.

27

Page 28: xml [Uyumluluk Modu]bekirdizdaroglu.com/ceng/Downloads/xml.pdf · Title: Microsoft PowerPoint - xml [Uyumluluk Modu] Author: Toshiba Created Date: 11/24/2008 5:58:41 PM

Example: xs:element

<xs:element name = ”NAME”type = ”xs:string” />

Describes elements such asDescribes elements such as<NAME>Joe’s Bar</NAME>

28

Page 29: xml [Uyumluluk Modu]bekirdizdaroglu.com/ceng/Downloads/xml.pdf · Title: Microsoft PowerPoint - xml [Uyumluluk Modu] Author: Toshiba Created Date: 11/24/2008 5:58:41 PM

C l TComplex Types

To describe elements that consist of subelements we use xs:complexTypesubelements, we use xs:complexType.

Attribute name gives a name to the type.

Typical subelement of a complex type is xs:sequence, which itself has a sequence q , qof xs:element subelements.

Use minOccurs and maxOccurs attributes toUse minOccurs and maxOccurs attributes to control the number of occurrences of an xs:element

29

xs:element.

Page 30: xml [Uyumluluk Modu]bekirdizdaroglu.com/ceng/Downloads/xml.pdf · Title: Microsoft PowerPoint - xml [Uyumluluk Modu] Author: Toshiba Created Date: 11/24/2008 5:58:41 PM

Example: a Type for dLemonades

<xs:complexType name ”lemonadeType”><xs:complexType name = ”lemonadeType”><xs:sequence> Exactly one<xs:element name = ”NAME”type = ”xs:string”

occurrence

minOccurs = ”1” maxOccurs = ”1” /><xs:element name = ”PRICE”type = ”xs:float” minOccurs = ”0” maxOccurs = ”1” />/

</xs:sequence></xs:complexType>

Like ? ina DTD

30

</xs:complexType> a DTD

Page 31: xml [Uyumluluk Modu]bekirdizdaroglu.com/ceng/Downloads/xml.pdf · Title: Microsoft PowerPoint - xml [Uyumluluk Modu] Author: Toshiba Created Date: 11/24/2008 5:58:41 PM

An Element of TypeAn Element of Type lemonadeTypelemonadeType

<xxx><NAME>Bud</NAME><PRICE>2 50</PRICE><PRICE>2.50</PRICE>

</xxx>

We don’t know thename of the elementof this type.

31

Page 32: xml [Uyumluluk Modu]bekirdizdaroglu.com/ceng/Downloads/xml.pdf · Title: Microsoft PowerPoint - xml [Uyumluluk Modu] Author: Toshiba Created Date: 11/24/2008 5:58:41 PM

Example: a Type for BarsExample: a Type for Bars

<xs:complexType name ”barType”><xs:complexType name = ”barType”><xs:sequence><xs:element name = ”NAME”type = ”xs:string”minOccurs = ”1” maxOccurs = ”1” />

<xs:element name = ”LEMONADE”type = ”lemonadeType” minOccurs = ”0” maxOccurs =

”unbounded” /></xs:sequence>

Like * ina DTD

32

/ q</xs:complexType>

a DTD

Page 33: xml [Uyumluluk Modu]bekirdizdaroglu.com/ceng/Downloads/xml.pdf · Title: Microsoft PowerPoint - xml [Uyumluluk Modu] Author: Toshiba Created Date: 11/24/2008 5:58:41 PM

xs:attribute

xs:attribute elements can be used within a complex type to indicate attributes of elements of that type.ypattributes of xs:attribute:

d t f l tname and type as for xs.element.use = ”required” or ”optional”.

33

Page 34: xml [Uyumluluk Modu]bekirdizdaroglu.com/ceng/Downloads/xml.pdf · Title: Microsoft PowerPoint - xml [Uyumluluk Modu] Author: Toshiba Created Date: 11/24/2008 5:58:41 PM

Example: xs:attribute

<xs:complexType name = ”l d T ”>”lemonadeType”><xs:attribute name = ”name”

type = ”xs:string”use = ”required” />use = required />

<xs:attribute name = ”price”type = ”xs:float” use = ”optional” />

34

use optional /</xs:complexType>

Page 35: xml [Uyumluluk Modu]bekirdizdaroglu.com/ceng/Downloads/xml.pdf · Title: Microsoft PowerPoint - xml [Uyumluluk Modu] Author: Toshiba Created Date: 11/24/2008 5:58:41 PM

An Element of This New TypeAn Element of This New Type lemonadeTypelemonadeType

<xxx name = ”Bud”price = ”2.50” />p ce .50 /

The element isWe still don’t know theelement name.

The element isempty, since thereare no declaredsubelements.

35

Page 36: xml [Uyumluluk Modu]bekirdizdaroglu.com/ceng/Downloads/xml.pdf · Title: Microsoft PowerPoint - xml [Uyumluluk Modu] Author: Toshiba Created Date: 11/24/2008 5:58:41 PM

Restricted Simple Types

xs:simpleType can describe enumerations and range-restricted base types.name is an attributename is an attributexs:restriction is a subelement.

36

Page 37: xml [Uyumluluk Modu]bekirdizdaroglu.com/ceng/Downloads/xml.pdf · Title: Microsoft PowerPoint - xml [Uyumluluk Modu] Author: Toshiba Created Date: 11/24/2008 5:58:41 PM

Restrictions

Attribute base gives the simple type to be restricted, e.g., xs:integer.xs:{min max}{Inclusive Exclusive} arexs:{min, max}{Inclusive, Exclusive} are four attributes that can give a lower or upper bound on a numerical rangeupper bound on a numerical range.xs:enumeration is a subelement with attribute value that allows enumerated types.

37

types.

Page 38: xml [Uyumluluk Modu]bekirdizdaroglu.com/ceng/Downloads/xml.pdf · Title: Microsoft PowerPoint - xml [Uyumluluk Modu] Author: Toshiba Created Date: 11/24/2008 5:58:41 PM

Example: license Attribute for BAR

<xs:simpleType name = ”license”><xs:restriction base = ”xs:string”><xs:enumeration value = ”Full” /><xs:enumeration value = ”Lemonade

only” />only /><xs:enumeration value = ”Sushi” />

</ t i ti ></xs:restriction></xs:simpleType>

38

Page 39: xml [Uyumluluk Modu]bekirdizdaroglu.com/ceng/Downloads/xml.pdf · Title: Microsoft PowerPoint - xml [Uyumluluk Modu] Author: Toshiba Created Date: 11/24/2008 5:58:41 PM

Example: Prices in Range [1,5)

<xs:simpleType name = ”price”><xs:restriction

base = ”xs:float”base = xs:floatminInclusive = ”1.00”maxExclusive = ”5.00” />

</xs:simpleType></xs:simpleType>

39

Page 40: xml [Uyumluluk Modu]bekirdizdaroglu.com/ceng/Downloads/xml.pdf · Title: Microsoft PowerPoint - xml [Uyumluluk Modu] Author: Toshiba Created Date: 11/24/2008 5:58:41 PM

Keys in XML Schema

An xs:element can have an xs:key subelement.Meaning: within this element, all subelements reached by a certain selector path will havereached by a certain selector path will have unique values for a certain combination of fieldsfields.Example: within one BAR element, the namepattribute of a LEMONADE element is unique.

40

Page 41: xml [Uyumluluk Modu]bekirdizdaroglu.com/ceng/Downloads/xml.pdf · Title: Microsoft PowerPoint - xml [Uyumluluk Modu] Author: Toshiba Created Date: 11/24/2008 5:58:41 PM

Example: KeyAnd @

<xs:element name = ”BAR” … >

And @indicatesan attribute

. . .<xs:key name = ”barKey”>

rather thana tag.y y

<xs:selector xpath = ”LEMONADE” /><xs:field xpath = ”@name” /><xs:field xpath = @name />

</xs:key>XPath is a query language

. . .</xs:element>

q y g gfor XML. All we need toknow here is that a pathi f t

41is a sequence of tagsseparated by /.

Page 42: xml [Uyumluluk Modu]bekirdizdaroglu.com/ceng/Downloads/xml.pdf · Title: Microsoft PowerPoint - xml [Uyumluluk Modu] Author: Toshiba Created Date: 11/24/2008 5:58:41 PM

Foreign Keys

An xs:keyref subelement within an xs:element says that within this element, certain values (defined by , ( yselector and field(s), as for keys) must appear as values of a certain keyappear as values of a certain key.

42

Page 43: xml [Uyumluluk Modu]bekirdizdaroglu.com/ceng/Downloads/xml.pdf · Title: Microsoft PowerPoint - xml [Uyumluluk Modu] Author: Toshiba Created Date: 11/24/2008 5:58:41 PM

Example: Foreign Key

Suppose that we have declared that subelement NAME of BAR is a key for BARS.

The name of the key is barKey.

We wish to declare DRINKER elementsWe wish to declare DRINKER elements that have FREQ subelements. An attribute bar of FREQ is a foreign key, referring to the NAME of a BAR.

43

g

Page 44: xml [Uyumluluk Modu]bekirdizdaroglu.com/ceng/Downloads/xml.pdf · Title: Microsoft PowerPoint - xml [Uyumluluk Modu] Author: Toshiba Created Date: 11/24/2008 5:58:41 PM

Example: Foreign Key in XMLExample: Foreign Key in XML SchemaSchema

<xs:element name = ”DRINKERS”. . .

<xs:keyref name = ”barRef”refers = ”barKey”<xs:selector xpath =

”DRINKER/FREQ” /><xs:field xpath = ”@bar” />

</xs:keyref></xs:element>

44

/