XML Lab Session - PowerPoint PPT Presentation

1 / 17
About This Presentation
Title:

XML Lab Session

Description:

The book 'Harry Potter and the half-blood prince', author J.K. Rowling, illustrator ... Schema Review. Schemas define the document's structure, i.e. ... – PowerPoint PPT presentation

Number of Views:48
Avg rating:3.0/5.0
Slides: 18
Provided by: home2
Category:
Tags: xml | and | blood | half | harry | lab | potter | prince | review | session | the

less

Transcript and Presenter's Notes

Title: XML Lab Session


1
XML Lab Session
  • Creating an XML document

2
Objective
  • How to write an XML document?
  • What are the important parts of an XML program?
  • What is root element?
  • What are empty elements?
  • DTD
  • XML Schema
  • Practice 1-5

3
Example
  • lt?xml version "1.0"?gt ltMy.pagegt ltheadgt lttitlegt
    My home page lt/titlegt ltheader source
    "imagehead.gif "/gt lt/headgt ltbodygt ltmain.titlegt
    Welcome to my home page lt/main.titlegt ltrule/gt ltt
    extgt ltparagt           SORRY! This page is still
    under construction. Visit this site
    soon. lt/paragt lt/textgt lt/bodygt ltfooter source
    imagefoot.gif "/gtlt/My.pagegt

4
Elements  i.e., from lttitlegt to lt/titlegt
  • In XML, an element normally consists of 3 things
  • a start tag.
  • content (either text or other elements ).
  • an end tag.
  • Ex lttitlegt My home page lt/titlegt 

5
Empty Elements i.e., lt rule/ gt  
  • Empty elements are a special case in XML. 
  • XML requires you to be much more explicit when
    dealing with empty elements.
  • To do so, there is a special empty tag close
    delimiter, /gt , as in the following
                                ltempty-element /gt
  • You can also use an end tag instead of the
    special empty tag close delimiter. The element
    declaration                      lt graphic
    source " image.gif "/gt    is therefore
    interchangeable with                     lt
    graphic source " image.gif "gt.............lt/
    graphicgt
  •  

6
Attributes i.e., ltheader source"imagehead.gif"/
gt 
  • Element tags can include one or more optional or
    mandatory attributes.
  • Attributes can only be specified in the element
    start tag.
  • The syntax for specifying an attribute is  
  • ltattribute.type.name  attribute.name
    "attribute.value" gt
  • lt fruit taste "sharp" gt

7
Important!
  • XML deals with multiple declaration of attributes
    in a unique manner. If an element appears once
    with one set of attributes and then appears again
    with a different set of attributes, the two sets
    of attributes are merged. 
  • The first declaration of an attribute for a
    particular element is the only one that counts,
    and any other declarations are ignored.

8
Practice 1
  • Using Notepad or other text editor create a XML
    document describing
  • The book Harry Potter and the half-blood
    prince, author J.K. Rowling, illustrator Mary
    Grandpre, year 2006, Paperback 652 pages,
    Publisher Scholastic Paperbacks
    Language English

9
Practice 2
  • Using Notepad or other text editor create a XML
    document describing an invoice. For example,
    include invoiceNumber, seller, customer, date,
    item0-itemN with quantity, type, price for each
    item

10
Practice 3
  • Using Notepad or other text editor create a XML
    document describing an ebay page of an item, in
    ex. a laptop, a phone, a music player, etc.

11
DTD Review
  • A DTD describes a model of the structure of the
    content of an XML document. 
  • This model says what elements must be present,
    which ones are optional what their attributes
    are, and how they can be structured with relation
    to each other. 
  • While HTML has only one DTD, XML allows you to
    create your own DTD's for your applications. This
    gives you complete control over the process of
    checking the content and structure of the XML
    documents created for that application. This
    checking process is called validation.

12
Simple XML DTD
  lt !DOCTYPE  DTDname options gt
13
Practice 4
  • Re-do Practice 2 using DTD
  • For reference, see Lecture12_XML_Structure_Present
    ation.ppt

14
Schema Review
  • Schemas define the document's structure, i.e.,
  • which elements are children of others. 
  • the order the child elements can appear. 
  • and the number of child elements. 
  • Schemas specify if an element is empty or if it
    can include text. 
  • Schemas can also specify default values for
    attributes. 
  • Schemas are more powerful and flexible than DTDs
    and use XML syntax. 
  • Schemas supports scope enabled definitions.
  • Schema standards are defined by the World Wide
    Web Consortium(W3C). The W3C site provides
    comprehensive reference of XML schemas. 

15
Simple XML XML Schema
16
Practice 5
  • Re-do Practice 3 using DTD
  • For reference, see Lecture12_XML_Structure_Present
    ation.ppt

17
Thank You
  • Source http//www.expertrating.com/courseware/XML
    Course/XML-Write-Xml-Document-3.asp
Write a Comment
User Comments (0)
About PowerShow.com