CS1655 Recitation 5 - PowerPoint PPT Presentation

1 / 21
About This Presentation
Title:

CS1655 Recitation 5

Description:

XML allows developers to write their own Document Type Definitions ... ELEMENT element-name category ! ELEMENT element-name (element-content) ... – PowerPoint PPT presentation

Number of Views:29
Avg rating:3.0/5.0
Slides: 22
Provided by: Am69
Category:

less

Transcript and Presenter's Notes

Title: CS1655 Recitation 5


1
CS1655 - Recitation 5
  • Andreea Munteanu
  • andreea_at_cs.pitt.edu

2
Overview
  • Introduction to XML
  • DTD
  • Example

3
Why XML? HTML not enough?
  • Need to do more fancy stuff
  • Make the logical structure of documents more
    explicit
  • eXtensible Markup Language
  • Data are identified using tags (identifiers
    enclosed in angle brackets lt...gt)

4
XML
  • Collectively, the tags are known as markup
  • XML tags tell you what the data means, rather
    than how to display it

5
XML example
  • lt?xml version"1.0" encoding"ISO-8859-1"?gt
  • ltauthorsgt
  • ltnamegt
  • ltfirstnamegt Jon lt/firstnamegt
  • lt/lastnamegt Patrick lt/lastnamegt
  • lt/namegt
  • ltnamegt
  • ltfirstnamegt Andrew lt/firstnamegt
  • lt/lastnamegt Moore lt/lastnamegt
  • lt/namegt
  • lt/authorsgt

6
XML versus relational
  • Relational structured
  • XML semi-structured
  • Plain text file unstructured

7
How does XML work?
  • XML allows developers to write their own Document
    Type Definitions
  • DTD markup languages rule book
  • Why need DTD?
  • Common format for XML documents
  • Consequence
  • If you want to use a certain tag must be defined
    in the DTD

8
Key concepts in XML
XML Content
XML Parser
Application
DTD Rules
9
DTD example
  • lt!ELEMENT authors (name)gt
  • lt!ELEMENT name (firstname, lastname)gt
  • lt!ELEMENT firstname (PCDATA)gt
  • lt!ELEMENT lastname (PCDATA)gt

10
XML and DTD
  • lt?xml version"1.0" encoding"ISO-8859-1"?gt
  • lt!DOCTYPE authors SYSTEM authors.dtdgt
  • ltauthorsgt
  • ltnamegt
  • ltfirstnamegt Jon lt/firstnamegt
  • lt/lastnamegt Patrick lt/lastnamegt
  • lt/namegt
  • ltnamegt
  • ltfirstnamegt Andrew lt/firstnamegt
  • lt/lastnamegt Moore lt/lastnamegt
  • lt/namegt
  • lt/authorsgt

11
XML and DTD
  • lt?xml version"1.0" encoding"ISO-8859-1"?gt
  • ltDOCTYPE authors
  • lt!ELEMENT authors (name)gt
  • lt!ELEMENT name (firstname, lastname)gt
  • lt!ELEMENT firstname (PCDATA)gt
  • lt!ELEMENT lastname (PCDATA)gt
  • gt
  • ltauthorsgt
  • ltnamegt
  • ltfirstnamegt Jon lt/firstnamegt
  • lt/lastnamegt Patrick lt/lastnamegt
  • lt/namegt
  • lt/authorsgt

12
Elements
  • Everything from (including )the elements start
    tag to (including) the elements end tag
  • Content
  • Elements
  • ltnamegt ltfirstnamegtJonlt/firstnamegtlt/namegt
  • Simple or text
  • ltfirstnamegt Jon lt/firstnamegt

13
Elements
  • Content (continue)
  • Mixed
  • ltchaptergt XML tutorial
  • ltparagt Introduction to XMLlt/paragt
  • ltparagt Description lt/paragt
  • lt/chaptergt
  • Empty (no information)
  • ltproduct id111 typebookgtlt/productgt
  • Attributes
  • Id with value 111 and type with value
    book

14
Attributes
  • Elements can have attributes in the start tag
  • Attributes values must always be enclosed in
    simple or double quotes
  • ltchapter date03/18/05gt
  • lttitlegt Introduction to XML lt/titlegt
  • ltcontentgt lt/contentgt
  • lt/chaptergt

15
Attributes
  • Not used very much
  • Cannot contain multiple values
  • Cannot describe structures
  • More difficult to implement by program code
  • Attributes values are not easy to test against
    DTD

16
DTD
  • XML documents may contain
  • Elements
  • Tags
  • Attributes
  • PCDATA (Parsed Character Data)
  • CDATA (Character Data)
  • This one will NOT be parsed by a parser. Tags
    inside the text will not be treated as markup and
    entities will not be expanded.

17
DTD
  • XML documents may contain
  • Entities
  • Variables used to define common text.
  • lt means lt
  • gt means gt
  • amp means
  • quot means

18
DTD Elements
  • lt! ELEMENT element-name categorygt
  • lt! ELEMENT element-name (element-content)gt
  • lt! ELEMENT element-name EMPTYgt
  • lt! ELEMENT element-name (PCDATA)gt
  • lt! ELEMENT element-name (ANY)gt
  • lt! ELEMENT element-name (child-element-name,
    child-element-name, )gt

19
DTD Elements
  • lt! ELEMENT element-name (child-element-name)gt
  • Appear at least once.
  • lt! ELEMENT element-name (child-element-name)gt
  • Appear zero or more times.
  • lt! ELEMENT element-name (child-element-name?)gt
  • Appear zero or one time.
  • lt! ELEMENT element-name (child-element-name1
    child-element-name2)gt
  • One of the two appears.

20
DTD Attributes
  • ltATTLIST element-name attribute-name
    attribute-type default-valuegt
  • lt!ATTLIST payment type CDATA checkgt
  • XML ltpayment typecheck/gt

21
DTD Attribute Type
  • CDATA
  • Value is character data.
  • (en1en2..)
  • Value must be one of the enumerated list.
  • ID
  • Values is a unique ID.
  • IDREF
  • Value is ID of another element.
  • NMTOKEN
  • Value is a valid XML name.
Write a Comment
User Comments (0)
About PowerShow.com