1 © 2005-2006 The ATHENA Consortium. XML, eXtensible Markup Language (1) The format for structured...

9
1 © 2005-2006 The ATHENA Consortium. XML, eXtensible Markup Language (1) The format for structured information exchange. Primary structuring is containment and sequence. A valid XML document is a tree <?xml version="1.0"?> <purchaseOrder orderDate="1999-10-20"> <shipTo country="US"> <name>Alice Smith</name> <street>123 Maple Street</street>… </shipTo> <billTo country="US"> <name>Robert Smith</name> … </billTo> <comment>Hurry, my lawn is going wild! </comment> <items> <item partNum="872-AA"> <productName>Lawnmower </productName> <quantity>1</quantity> <USPrice>148.95</USPrice> <comment>Confirm this is electric</comment> </item> <item partNum="926-AA">… </items> </purchaseOrder>

Transcript of 1 © 2005-2006 The ATHENA Consortium. XML, eXtensible Markup Language (1) The format for structured...

Page 1: 1 © 2005-2006 The ATHENA Consortium. XML, eXtensible Markup Language (1) The format for structured information exchange. –Primary structuring is containment.

1© 2005-2006 The ATHENA Consortium.

XML, eXtensible Markup Language (1)

• The format for structured information exchange.– Primary structuring is

containment and sequence.

– A valid XML document is a tree

<?xml version="1.0"?><purchaseOrder orderDate="1999-10-20">

<shipTo country="US"> <name>Alice Smith</name> <street>123 Maple Street</street>…</shipTo><billTo country="US"> <name>Robert Smith</name> …</billTo><comment>Hurry, my lawn is going wild! </comment><items> <item partNum="872-AA"> <productName>Lawnmower </productName> <quantity>1</quantity> <USPrice>148.95</USPrice> <comment>Confirm this is

electric</comment> </item>

<item partNum="926-AA">…</items>

</purchaseOrder>

Page 2: 1 © 2005-2006 The ATHENA Consortium. XML, eXtensible Markup Language (1) The format for structured information exchange. –Primary structuring is containment.

2© 2005-2006 The ATHENA Consortium.

XML tree structure

Root

purchaseOrder

@orderDate

1999-10-20

shipToitemscomment

name

@country street state

city zip

billTo

name

@country street state

city zip

Mill Valley

123 Maple Street CA

Alice Smith

US

90952 Old Town

8 Oak Avenue

PA

Robert Smith

US

95819

Hurry, my lawn is going wild!

item

productName

@partNum quantity

USPrice

148.95

1

Lawnmower

872-AA

comment

Confirm this is electric

shipDate

1999-05-21

item

Page 3: 1 © 2005-2006 The ATHENA Consortium. XML, eXtensible Markup Language (1) The format for structured information exchange. –Primary structuring is containment.

3© 2005-2006 The ATHENA Consortium.

XML document

Page 4: 1 © 2005-2006 The ATHENA Consortium. XML, eXtensible Markup Language (1) The format for structured information exchange. –Primary structuring is containment.

4© 2005-2006 The ATHENA Consortium.

XML, eXtensible Markup Language (2)

• <?xml version="1.0"?> <purchaseOrder orderDate="1999-10-20"> <shipTo country="US"> <name>Alice Smith</name> <street>123 Maple Street</street>… </shipTo> <billTo country="US"> <name>Robert Smith</name> … </billTo> <comment>Hurry, my lawn is going wild!</comment> <items> <item partNum="872-AA"> <productName>Lawnmower </productName> <quantity>1</quantity> <USPrice>148.95</USPrice> <comment>Confirm this is electric </comment> </item> <item partNum="926-AA">… </items> </purchaseOrder>

• The format for structured information exchange.– Primary structuring is containment

and sequence.– A valid XML document is a tree

• Extensible – anyone can “coin” markup tags

• Is an application of SGML, the Structured Markup Language– a standard for marking-up documents

• Can be edited with any text editor

Page 5: 1 © 2005-2006 The ATHENA Consortium. XML, eXtensible Markup Language (1) The format for structured information exchange. –Primary structuring is containment.

5© 2005-2006 The ATHENA Consortium.

XML Schema

• <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:element name="purchaseOrder" type="PurchaseOrderType"/>

<xsd:element name="comment" type="xsd:string"/>

<xsd:complexType name="PurchaseOrderType"> <xsd:sequence> <xsd:element name="shipTo" type="USAddress"/> <xsd:element name="billTo" type="USAddress"/> <xsd:element ref="comment" minOccurs="0"/> <xsd:element name="items" type="Items"/> </xsd:sequence> <xsd:attribute name="orderDate" type="xsd:date"/> </xsd:complexType> ….

</xsd:schema>

• Defines a class of documents– Allowed structure,

content and constraints– An XML document can

be an instance of the schema class

• Uses XML syntax– Can use XML tools to

process it• Has a large set of pre-

defined simple data-types that can be extended.

• Instances can be validated against the schema

Page 6: 1 © 2005-2006 The ATHENA Consortium. XML, eXtensible Markup Language (1) The format for structured information exchange. –Primary structuring is containment.

6© 2005-2006 The ATHENA Consortium.

XML in document exchange

Standard

<ProductName> Lawnmower </ProductName>

<PartNumber>872-AA </PartNumber>

<Product><ID>

Lawnmower 872-AA </ID> </Product>

<tag>...</tag>

LineItem database table:LineItem database table:

LineItem database table:LineItem database table:

database

database

XMLXML XMLXML

Page 7: 1 © 2005-2006 The ATHENA Consortium. XML, eXtensible Markup Language (1) The format for structured information exchange. –Primary structuring is containment.

7© 2005-2006 The ATHENA Consortium.

Database and database schema

movieName releaseYear director

Annie Hall 1977 Woody Allen

Dr. Strangelove 1964 Stanley Kubrick

movieName actor

Annie Hall Woody Allen

Annie Hall Diane Keaton

Dr. Strangelove Peter Sellers

Movie:Movie:

Starred:Starred:

Movie (movieName, releaseYear, director)Movie (movieName, releaseYear, director)

Starred (movieName, actor)Starred (movieName, actor)

Example based on p. 5 of “Information Modeling and Relational Databases” by

Terry Halpin, 2001

Example based on p. 5 of “Information Modeling and Relational Databases” by

Terry Halpin, 2001

Page 8: 1 © 2005-2006 The ATHENA Consortium. XML, eXtensible Markup Language (1) The format for structured information exchange. –Primary structuring is containment.

8© 2005-2006 The ATHENA Consortium.

Questions 3.1

1. What is one of the primary purposes of XML?

2. What is one of the primary purposes of XML Schema?

3. What do databases and XML have in common?

That completes the topic of XML, now for some questions:

Page 9: 1 © 2005-2006 The ATHENA Consortium. XML, eXtensible Markup Language (1) The format for structured information exchange. –Primary structuring is containment.

9© 2005-2006 The ATHENA Consortium.

Answers 3.1

1. What is one of the primary purposes of XML?– To exchange structured data

2. What is one of the primary purposes of XML Schema?– To define a class of documents– To validate an XML document as an instance of the class

3. What do databases and XML have in common?– Structured information– Schemas– Constraints