XML Examples - PowerPoint PPT Presentation

About This Presentation
Title:

XML Examples

Description:

XML Examples. CSC 436 Fall 2005. Slides to be used in ... addr 1234 Huron Street /addr addr Rome, OH 98765 /addr tel (321) 786 2543 /tel ... – PowerPoint PPT presentation

Number of Views:15
Avg rating:3.0/5.0
Slides: 18
Provided by: lisadi4
Category:
Tags: xml | examples | huron

less

Transcript and Presenter's Notes

Title: XML Examples


1
XML Examples
  • CSC 436 Fall 2005
  • Slides to be used in conjunction with class notes

2
Example Toy Store
ltxml version1.0 standaloneyesgt lttoystoregt
ltManufgt ltNamegtFischer-Pricelt/Namegt ltAddrgt2
Main Streetlt/Addrgt ltPhonegt401-555-3344lt/Phonegt
ltToygt ltNamegtFarm Houselt/Namegt ltNumgt0001lt/Nu
mgt ltPricegt14.00lt/Pricegt lt/Toygt ltToygt ltNa
megtTrucklt/Namegt ltNumgt0002lt/Numgt ltPricegt12.00
lt/Pricegt lt/Toygt lt/Manufgt ltManufgt
lt/Manufgt
3
Example An Address Book
  • ltpersongt
  • ltnamegt MacNiel, John lt/namegt
  • ltgreetgt Dr. John MacNiel lt/greetgt
  • ltaddrgt1234 Huron Street lt/addrgt
  • ltaddrgt Rome, OH 98765 lt/addrgt
  • lttelgt (321) 786 2543 lt/telgt
  • ltfaxgt (321) 786 2543 lt/faxgt
  • lttelgt (321) 786 2543 lt/telgt
  • ltemailgt jm_at_abc.com lt/emailgt
  • lt/persongt

Exactly one name
At most one greeting
As many address lines as needed (in order)
Mixed telephones and faxes
As many as needed
4
A DTD for the address book
  • lt!DOCTYPE addressbook
  • lt!ELEMENT addressbook (person)gt
  • lt!ELEMENT person
  • (name, greet?, address, (fax tel),
    email)gt
  • lt!ELEMENT name (PCDATA)gt
  • lt!ELEMENT greet (PCDATA)gt
  • lt!ELEMENT address (PCDATA)gt
  • lt!ELEMENT tel (PCDATA)gt
  • lt!ELEMENT fax (PCDATA)gt
  • lt!ELEMENT email (PCDATA)gt
  • gt

5
Example Project Database

6
Two DTDs for the Project DB
lt!DOCTYPE db lt!ELEMENT db
(projects,employees)gt lt!ELEMENT projects
(project)gt lt!ELEMENT employees (employee)gt
lt!ELEMENT project (title, budget,
managedBy)gt lt!ELEMENT employee (name, ssn,
age)gt ... gt

lt!DOCTYPE db lt!ELEMENT db (project
employee)gt lt!ELEMENT project (title,
budget, managedBy)gt lt!ELEMENT employee (name,
ssn, age)gt ... gt
7
Specifying ID and IDREF attributes
  • lt!DOCTYPE family
  • lt!ELEMENT family (person)gt
  • lt!ELEMENT person (name)gt
  • lt!ELEMENT name (PCDATA)gt
  • lt!ATTLIST person
  • id ID REQUIRED
  • mother IDREF IMPLIED
  • father IDREF IMPLIED
  • children IDREFS IMPLIEDgt
  • gt

8
Some conforming data
  • ltfamilygt
  • ltperson id"jane" mother"mary"
    father"john"gt
  • ltnamegt Jane Doe lt/namegt
  • lt/persongt
  • ltperson id"john" children"jane jack"gt
  • ltnamegt John Doe lt/namegt
  • lt/persongt
  • ltperson id"mary" children"jane jack"gt
  • ltnamegt Mary Doe lt/namegt
  • lt/persongt
  • ltperson id"jack" mothermary"
    father"john"gt
  • ltnamegt Jack Doe lt/namegt
  • lt/persongt
  • lt/familygt

9
An alternative specification
  • lt!DOCTYPE family
  • lt!ELEMENT family (person)gt
  • lt!ELEMENT person (mother?, father?, children,
    name)gt
  • lt!ATTLIST person id ID REQUIREDgt
  • lt!ELEMENT name (PCDATA)gt
  • lt!ELEMENT mother EMPTYgt
  • lt!ATTLIST mother idref IDREF REQUIREDgt
  • lt!ELEMENT father EMPTYgt
  • lt!ATTLIST father idref IDREF REQUIREDgt
  • lt!ELEMENT children EMPTYgt
  • lt!ATTLIST children idrefs IDREFS REQUIREDgt
  • gt

10
The revised data
  • ltfamilygt
  • ltperson id "janegt
  • ltnamegt Jane Doe lt/namegt
  • ltmother idref "marygtlt/mothergt
  • ltfather idref "john"gtlt/fathergt
  • lt/persongt
  • ltperson id "johngt
  • ltnamegt John Doe lt/namegt
  • ltchildren idrefs "jane jack"gt lt/childrengt
  • lt/persongt
  • ...
  • lt/familygt

11
Bank DTD
  • lt!DOCTYPE bank
  • lt!ELEMENT bank ( ( account customer
    depositor))gt
  • lt!ELEMENT account (account-number branch-name
    balance)gt
  • lt! ELEMENT customer(customer-name
    customer-street

    customer-city)gt
  • lt! ELEMENT depositor (customer-name
    account-number)gt
  • lt! ELEMENT account-number (PCDATA)gt
  • lt! ELEMENT branch-name (PCDATA)gt
  • lt! ELEMENT balance(PCDATA)gt
  • lt! ELEMENT customer-name(PCDATA)gt
  • lt! ELEMENT customer-street(PCDATA)gt
  • lt! ELEMENT customer-city(PCDATA)gt
  • gt

12
Bank DTD with Attributes
  • Bank DTD with ID and IDREF attribute types.
  • lt!DOCTYPE bank-2
  • lt!ELEMENT account (branch, balance)gt
  • lt!ATTLIST account
  • account-number ID
    REQUIRED
  • owners IDREFS
    REQUIREDgt
  • lt!ELEMENT customer(customer-name,
    customer-street,

  • customer-city)gt
  • lt!ATTLIST customer
  • customer-id ID
    REQUIRED
  • accounts IDREFS
    REQUIREDgt
  • declarations for branch, balance,
    customer-name,
    customer-street and customer-citygt

13
XML data with ID and IDREF attributes
  • ltbank-2gt
  • ltaccount account-numberA-401 ownersC100
    C102gt
  • ltbranch-namegt Downtown lt/branch-namegt
  • ltbranchgt500 lt/balancegt
  • lt/accountgt
  • ltcustomer customer-idC100 accountsA-401gt
  • ltcustomer-namegtJoelt/customer-namegt
  • ltcustomer-streetgtMonroelt/customer-street
    gt
  • ltcustomer-citygtMadisonlt/customer-citygt
  • lt/customergt
  • ltcustomer customer-idC102 accountsA-401
    A-402gt
  • ltcustomer-namegt Marylt/customer-namegt
  • ltcustomer-streetgt Erinlt/customer-streetgt
  • ltcustomer-citygt Newark lt/customer-citygt
  • lt/customergt
  • lt/bank-2gt

14
XML Schema Version of Bank DTD
  • ltxsdschema xmlnsxsdhttp//www.w3.org/2001/XMLSc
    hemagt
  • ltxsdelement namebank typeBankType/gt
  • ltxsdelement nameaccountgtltxsdcomplexTypegt
    ltxsdsequencegt ltxsdelement
    nameaccount-number typexsdstring/gt
    ltxsdelement namebranch-name
    typexsdstring/gt ltxsdelement
    namebalance typexsddecimal/gt
    lt/xsdsquencegtlt/xsdcomplexTypegt
  • lt/xsdelementgt
  • .. definitions of customer and depositor .
  • ltxsdcomplexType nameBankTypegtltxsdsquencegt
  • ltxsdelement refaccount minOccurs0
    maxOccursunbounded/gt
  • ltxsdelement refcustomer minOccurs0
    maxOccursunbounded/gt
  • ltxsdelement refdepositor minOccurs0
    maxOccursunbounded/gt
  • lt/xsdsequencegt
  • lt/xsdcomplexTypegt
  • lt/xsdschemagt

15
Toy ER Diagram
16
Hierarchy with Toy as Root
MSRP
NAME
AGE_GRP
TOY_NUM
SOLD_YTD
TOY
1
IN_STOCK
1
PHONE
ADDRESS
1
CUST_NUM
MAN_ID
N
MANUF
CUSTOMER
CONTACT
NAME
NUM_CHILD
1
ADDRESS
LOCATION
NAME
NAME
EMAIL
MAN_TIME
DATE_ORD
QUANTITY
LNAME
FNAME
DATE_DELIV
N
CHILD
BDATE
NAME
17
Toy XML Schema
ltxsdschema xmlnsxsdhttp//www.w3.org/2001/XMLSc
hemagt ltxsdelement nametoy typeToyType/gt ltxs
delement namemanufgtltxsdcomplexTypegt
ltxsdsequencegt ltxsdelement
namephone typexsdstring/gt
ltxsdelement nameman_id
typexsdstring/gt ltxsdelement
nameman_time typexsddecimal/gt
lt/xsdsquencegtlt/xsdcomplexTypegt lt/xsdelement
namegt ltxsdelement namecustomergt
lt/xsdelement namegt ltxsdcomplexType
nameToyTypegtltxsdsquencegt ltxsdelement
refmanuf minOccurs1 maxOccurs1/gt ltxsd
element refcustomer minOccurs0
maxOccursunbounded/gt lt/xsdsequencegt lt/xsd
complexTypegt lt/xsdschemagt
Write a Comment
User Comments (0)
About PowerShow.com