90 likes | 194 Views
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>…
E N D
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> XML, eXtensible Markup Language (1)
XML tree structure Root purchaseOrder items billTo comment @orderDate shipTo … item item state street @country @country street state … name name city city zip zip quantity comment @partNum shipDate USPrice productName 123 Maple Street 8 Oak Avenue Hurry, my lawn is going wild! PA US CA US 1999-05-21 148.95 Lawnmower Alice Smith 90952 Old Town Confirm this is electric 872-AA 1999-10-20 Mill Valley Robert Smith 95819 1
<?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 XML, eXtensible Markup Language (2)
<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 XML Schema
XML in document exchange <tag>...</tag> Standard database XML XML LineItem database table: <Product><ID>Lawnmower 872-AA</ID> </Product> <ProductName>Lawnmower </ProductName> <PartNumber>872-AA </PartNumber> LineItem database table:
Database and database schema Movie (movieName, releaseYear, director) Starred (movieName, actor) Movie: Starred: Example based on p. 5 of “Information Modeling and Relational Databases” by Terry Halpin, 2001
Questions 3.1 That completes the topic of XML, now for some questions: • What is one of the primary purposes of XML? • What is one of the primary purposes of XML Schema? • What do databases and XML have in common?
Answers 3.1 • What is one of the primary purposes of XML? • To exchange structured data • 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 • What do databases and XML have in common? • Structured information • Schemas • Constraints