25
MIS 315 Bsharah An Introduction to XML 1 MIS 315 - Bsharah

MIS 315 Bsharah An Introduction to XML 1MIS 315 - Bsharah

Embed Size (px)

Citation preview

MIS 315 Bsharah

1MIS 315 - Bsharah

An Introduction to XML

2MIS 315 - Bsharah

XML-1.0 Definition

• EXtensible Markup Language - XML

• Meta-Markup Language to describe information– Hierarchical Structure with a Tag Based Syntax for data

descriptions– Elements and attributes define vocabulary semantics

• Text based tagged record format– Tags bracket and describe record– Record can be any text (word, sentence, paragraph, etc.)– Start and end tags for each record

• Includes robust architecture components for utilization– http://www.w3.org/TR/2000/REC-xml-20001006

3MIS 315 - Bsharah

Key Driver for XML Adoption isImproved Business Flexibility

• Today’s extended enterprise is virtual– Boundaries are a moving target– New partnerships focus on E-Business business transactions– Communications typically over public internet

• Loosely coupled business relationships are defined– Enable rapid integration of new relationships– Remove requirements for “fixed” IT infrastructure

• dedicated communication links• “hardwired” system interfaces

• Internet protocols (XML/HTTP) emerging as de facto e-business standards– pervasive, worldwide acceptance– rapidly evolving to meet wide range of needs

XML Meets Business Needs for Enterprise Web Application Development

UserCustomer

Public Internet

XML/HTTP

Internet BusinessEnterprise

BusinessEnterprise

Firew

allWebService

AppServer

DataServer

User

Firew

all WebService

AppServer

DataServer

User

Slide: 4MIS 315 - Bsharah

5MIS 315 - Bsharah

XML is a Meta-Language for Defining Information

• Document (information) is defined by:– Declaration: identifies XML version and schema information– Comments: describes the document– Elements: define records of document, metadata – Attributes: identify values for elements

• Document (information) is constrained by XML architecture components:– Schemas: describes what a document may contain

• DTDs: document type definition; the document structure– Namespaces: allows use of multiple data sources in single file

6MIS 315 - Bsharah

Benefits of XML

• Facilitates development of flexible Web Applications– Data integration and transformation from disparate sources– Data separated from presentation– Multiple views of the same data

• Enables more usable applications– Describes data content, not just interface– Supports automated processing for searches, applications, EDI

• Widely supported for ease of implementation– Open standard; multiple programming languages– Human and machine interpretable– Uses common Web infrastructure and industry products

7MIS 315 - Bsharah

Where Did XML Come From?

• XML is a much simplified form of Standard Generalized Markup Language (SGML)– SGML (focused on exchange of complex document formats)– W3C standard for document exchange– Supported by commercial authoring and viewing tools

• Internet needed easier to use markup language– more robust than HTML– easier to use; less complicated than SGML– usable in browser, HTTP, internet environment

• XML result is a W3C recommendation– defines XML syntax– identifies related components for extension

8MIS 315 - Bsharah

Who “Owns” XML?

• XML technology standard - http://www.w3c.org – Internet related standards body– manages variety of Internet standards

• HTTP• XML

• XML domain specific standards - for example, Automotive– define common “document” definitions for industry information– AIAG: http://www.aiag.org/projects/pp423.html– STEP: http://www.stepml.org/– OAG: http://www.openapplications.org/xml/loadform.htm– etc.

• XML enterprise specific definitions – recommended only when external standards are not available– common registry for enterprise use / re-use

9MIS 315 - Bsharah

XML Document

Document

Prolog

Body

Epilog

<?xml version = “1.0” standalone=“no”?><!-comment and processing instructions allowed here-><!DOCTYPE books SYSTEM http://myserver.com/books.dtd><!-comment and processing instructions allowed here->

<books> <book category = “reference”>

<author>Raj Birla</author><title>The XML Story</title>

</book> <book category = “fiction”>

<author>Raj Birla</author><title>The XML Story</title>

</book></books>

<!-comment and processing instructions allowed here->

Document Root

Element Root

Books

Book

category

Author

Title

10MIS 315 - Bsharah

Constructing a DTD

• Step 1 – Declare the XML Document– The XML declaration is the first line in every XML

document.– The entire line is a processing instruction that is enclosed

within the processing instruction delimiters, <? and ?>. – <?xml version="1.0" standalone=“yes” ?>

• Step 2 – Refer to a DTD– The document type declaration must precede the first start

tag in an XML document.– Starts with the !DOCTYPE keyword and either contains a

complete internal DTD subset or refers to a separate external DTD.

11MIS 315 - Bsharah

Constructing a DTD

• Step 2 – Refer to a DTD (con’t)

Internal Declaration– <!DOCTYPE pet_store [… ]>

External Declaration– <!DOCTYPE show_po_006 SYSTEM "011_show_po_006.dtd">

– For an external DTD, the uniform resource identifier (URI) can be either an absolute address or a relative address.• Absolute address example:

http://ecommerce.org/schema/011showpo006.dtd

• Relative address example:schema/011showpo006.dtd

12MIS 315 - Bsharah

Constructing a DTD

• Step 3 – Define the Root Element and Its Child Elements

– <!ELEMENT pet_store (purchases?) >– <!ELEMENT purchases (creature*, feed*) >– <!ELEMENT creature (creature_type, species)+ >– <!ELEMENT creature_type (#PCDATA) >– <!ELEMENT species (#PCDATA) >– <!ELEMENT feed (daily_feed, daily_feed_quantity)+ >– <!ELEMENT daily_feed (#PCDATA) >– <!ELEMENT daily_feed_quantity (#PCDATA) >

pet_store (root)

purchasescreature

feed

creature_typespecies

daily_feeddaily_feed_quantity

13MIS 315 - Bsharah

Constructing a DTD

• Step 4 – Specify Element Occurrences and Order

– {?} Indicates that an element can occur once, but does not have to occur at all.

– {*} Indicates that an element can occur an unlimited number of times.

– {+} Indicates that an element must occur one or more times.– {,} Indicates the exact order in which the elements appear; a

sequence list.– {|} Indicates that element data can occur in any order; choice list.

Example:– <?xml version="1.0" standalone="yes" ?> – <!DOCTYPE pet_store [ …– <!ELEMENT purchases (creature*, feed*)> ]>

14MIS 315 - Bsharah

Constructing a DTD

• Step 5 – Specify Attribute Lists and Default Values– Set Attribute Types

• CDATA = character data, string type• ID = tokenized type, unique identification value• IDREF, IDREFS = tokenized type, cross reference to one or more ID values• ENTITY, ENTITIES = tokenized type, refers to one or more pre-defined

entities• NMTOKEN, NMTOKENS = tokenized type, refers to one or more name

tokens• NOTATION, enumerated NOTATION = refers to one or more values

specified by a notation declaration

– Specify If Attribute Is Required or Optional• #REQUIRED = attribute must appear in every instance of the element• #IMPLIED = attribute may optionally appear on an instance of the element• #FIXED plus default value = must always have default value• Default Value = if attribute does not appear, the default value is assumed, if

the attribute appears it may have another value.

15MIS 315 - Bsharah

Constructing a DTD

• Step 5 – Specify Attribute Lists and Default Values (con’t)

– <!ATTLIST pet_store storeID ID #IMPLIEDstore_name CDATA #FIXED “Rick’s Pets”>

– <!ATTLIST purchases customer_name CDATA #IMPLIED SSN ID #REQUIRED>

16MIS 315 - Bsharah

Constructing a DTD

• Step 6 – Define and Declare Entities

– Syntax: <!ENTITY Entity_Name “Entity_Definition” >– For an externally sourced set of replacement content, precede

“Entity_Definition” with a SYSTEM | PUBLIC keyword• SYSTEM = local server or network• PUBLIC = a public resource

– Examples:– <!ENTITY copyright “© Rick’s XML Company, Inc., 2001”>

– <!ENTITY chapter2 SYSTEM “chap2ver003.doc”>

17MIS 315 - Bsharah

Constructing a DTD

• Step 7 – Define lists and tables

– List definition is through two ELEMENT declarations <!ELEMENT listname (listitem+)> <!ELEMENT listitem (#PCDATA)>

– Table definition is through three ELEMENT Declarations <!ELEMENT table (row+)> <!ELEMENT row (cell+)> <!ELEMENT cell (#PCDATA)>

Or– <!ELEMENT table (col+)>

<!ELEMENT col (cell+)> <!ELEMENT cell (#PCDATA)>

DTD Example for oldjoke

<!DOCTYPE oldjoke [ Start of oldjoke DTD<!ELEMENT oldjoke DTD ELEMENT declaration for oldjoke

(burns+, allen, applause?)> defines allowed subelement names for oldjoke<!ELEMENT burns defines subelement: burns

(#PCDATA | quote)*> allowed burns content is: PCDATA or quote

<!ELEMENT allen defines subelement: allen(#PCDATA | quote)*> allowed allen content is: PCDATA or quote

<!ELEMENT quote defines subelement:quote(#PCDATA)*> allowed quote content is PCDATA

<!ELEMENT applause EMPTY> defines subelement: applause as EMPTY] identifies the end of oldjoke DTD

Special Syntax Notes: Allowed operators are: Optional (?), one-or-more (+), and zero-or-more (*) (B | C | (D, E)) defines allowed values group of B or C or sequence D, E

Slide: 18MIS 315 - Bsharah

19MIS 315 - Bsharah

Constructing a Valid XML Document

• Step 1 – Plan and Prepare

– To build a valid XML Document, you must completely understand its DTD.

– Test the DTD for correctness, syntax and semantics

• Step 1a – Declare XML Characteristics– The XML declaration is the first line in every XML Document.

• <?xml version="1.0" standalone=“yes” ?>

• Step 1b – Set Document Type and Associated DTD– Internal

• <!DOCTYPE pet_store [… ]>– External

• <!DOCTYPE show_po_006 SYSTEM "011_show_po_006.dtd">

20MIS 315 - Bsharah

Constructing a Valid XML Document

• Step 2 – Insert Elements based on the DTD and Add Attributes and attribute values.

• Example: <pet_store store_ID="11218976" > <purchases customer_ID="334343"> <creature> <creature_type>llama</creature_type> <species>Vicuna</species> </creature> …

DTD

<?xml version="1.0"> <!DOCTYPE pet_store [<!ELEMENT pet_store (purchases?) ><!ATTLIST pet_store storeID ID #IMPLIED><!ELEMENT purchases (creature*, feed*) ><!ATTLIST purchases customer_ID CDATA #IMPLIED ><!ELEMENT creature (creature_type, species)+ ><!ELEMENT creature_type (#PCDATA) ><!ELEMENT species (#PCDATA) >…]>

DTD

<?xml version="1.0"> <!DOCTYPE pet_store [<!ELEMENT pet_store (purchases?) ><!ATTLIST pet_store storeID ID #IMPLIED><!ELEMENT purchases (creature*, feed*) ><!ATTLIST purchases customer_ID CDATA #IMPLIED ><!ELEMENT creature (creature_type, species)+ ><!ELEMENT creature_type (#PCDATA) ><!ELEMENT species (#PCDATA) >…]>

21MIS 315 - Bsharah

Constructing a Valid XML Document

• Step 3 – Insert Entities

<?xml version="1.0" standalone="yes" ?> <!DOCTYPE pet_store [<!ELEMENT purchases (weather?,creature*, feed*) ><!ENTITY Storewthr SYSTEM

“rick/weather/current/wthr.xml”> …]><SalesReport> <title>Store Sales</title> &Storewthr; …</SalesReport>

<weather> <temp>55-60</temp> <precip>Rain</precip></weather>

wthr.xml

Note: Previously created file, storedat network node: rick/weather/current.

22MIS 315 - Bsharah

ENTITY Creation(Using ENTITY as an attribute type)

• Three Steps– Declare the ENTITY(s) for use with the attribute.– Declare an attribute of type ENTITY for the element– Create an instance of the element type in the document, providing the

attribute and an entity name as the value.

• Example:– <!ELEMENT VacationDetail (#PCDATA)>– <!ATTLIST VacationDetail pictures ENTITIES #IMPLIED>– <!ENTITY familyphoto SYSTEM “mydocs\Trips\July2000.jpg”>– <!ENTITY familyphoto2 SYSTEM “mydocs\Trips\July2000b.jpg”>– . . . – <VacationDetail pictures=“familyphoto familyphoto2”>Family trip

4th of July…– </VacationDetail>

Constructing a Valid XML Document

• Step 4 – Build Lists and Tables<register>Rick’s Account

<label><cell>Date</cell>

<cell>Vendor</cell> <cell>Amount</cell> <cell>Description</cell> </label> <check> <cell>1/2/2001</cell> <cell>Phone Company</cell> <cell>$43.75</cell> <cell>Monthly statement</cell> </check></register>

MIS 315 - Bsharah

Slide: 23

DTD for register table<!ELEMENT register (label|check)+><!ELEMENT (label|check) (cell+)><!ELEMENT cell (#PCDATA)>

DTD for register table<!ELEMENT register (label|check)+><!ELEMENT (label|check) (cell+)><!ELEMENT cell (#PCDATA)>

Simple XML Example

<?xml version="1.0"?> XML Declaration statement; uses version 1.0<oldjoke> XML Document root element, start-tag: oldjoke <burns> Subelement start-tag: burns; content of element: oldjoke Say First part of content of element: burns <quote> Subelement of burns, start-tag: quote goodnight, Content of element: quote </quote> End-tag of element: quote Gracie.Additional content of element: burns </burns> End-tag of element: burns <allen> New subelement of oldjoke, start-tag: allen <quote> Subelement of allen, start-tag: quote Goodnight, Gracie. Content of element: quote </quote> End-tag of element: quote </allen> End-tag of element: allen <applause/> Empty Element Tag: applause (special case of syntax)</oldjoke> End-tag for root element: oldjoke

MIS 315 - Bsharah

Slide: 24

Complete Document for Pet Store Example

<?xml version="1.0" standalone="yes" ?> <!DOCTYPE pet_store [<!ELEMENT pet_store (purchases?) ><!ATTLIST pet_store storeID ID #IMPLIED><!ELEMENT purchases (creature*, feed*) ><!ATTLIST purchases customer_ID CDATA #IMPLIED ><!ELEMENT creature (creature_type, species)+ ><!ELEMENT creature_type (#PCDATA) ><!ELEMENT species (#PCDATA) ><!ELEMENT feed (daily_feed, daily_feed_quantity)+ ><!ELEMENT daily_feed (#PCDATA) ><!ELEMENT daily_feed_quantity (#PCDATA) >]><pet_store store_ID="11218976" > <purchases customer_ID="334343"> <creature> <creature_type>llama</creature_type> <species>Vicuna</species> </creature> <feed> <daily_feed>Ruminant Grain Feed</daily_feed> <daily_feed_quantity>2</daily_feed_quantity> </feed> </purchases></pet_store>

<?xml version="1.0" standalone="yes" ?> <!DOCTYPE pet_store [<!ELEMENT pet_store (purchases?) ><!ATTLIST pet_store storeID ID #IMPLIED><!ELEMENT purchases (creature*, feed*) ><!ATTLIST purchases customer_ID CDATA #IMPLIED ><!ELEMENT creature (creature_type, species)+ ><!ELEMENT creature_type (#PCDATA) ><!ELEMENT species (#PCDATA) ><!ELEMENT feed (daily_feed, daily_feed_quantity)+ ><!ELEMENT daily_feed (#PCDATA) ><!ELEMENT daily_feed_quantity (#PCDATA) >]><pet_store store_ID="11218976" > <purchases customer_ID="334343"> <creature> <creature_type>llama</creature_type> <species>Vicuna</species> </creature> <feed> <daily_feed>Ruminant Grain Feed</daily_feed> <daily_feed_quantity>2</daily_feed_quantity> </feed> </purchases></pet_store>

Slide: 25MIS 315 - Bsharah