Unit 2: Introduction to XML and DTD

1 / 38
About This Presentation
Title:

Unit 2: Introduction to XML and DTD

Description:

What can XML be used for? Separate data from presentation. Don't store data in HTML ... heading Cars for Sale /heading make Audi 80 /make engine 1800 cc /engine ... – PowerPoint PPT presentation

Number of Views:55
Avg rating:3.0/5.0
Slides: 39
Provided by: scottf9

less

Transcript and Presenter's Notes

Title: Unit 2: Introduction to XML and DTD


1
Unit 2 Introduction to XML and DTD
Instructor This unit is a review of XML and DTD.
Depending on the XML expertise of this class you
can skip or cover in detail. Encourage the
students to use it as reference material.
  • Building J2EE Applications in SilverStream

2
Section Objectives
  • Introduction to XML
  • Introduction to DTD

3
What is XML?
  • XML is a markup language that describes how data
    should be represented in a data file or I/O
    stream
  • Tags identify each element within the document
  • Self-describing
  • Works with other technologies to
  • Process data
  • Display data

4
What can XML be used for?
  • Separate data from presentation
  • Dont store data in HTML
  • Exchange data between incompatible systems
  • B2BTransactions
  • Store data
  • Instead of using text files
  • Preference files

5
J2EE and XML
  • XML is used by assemblers to describe the
    components
  • XML is used by deployers to specify the
    environment specific parameters
  • You can use an XML parser to integrate XML into
    your applications
  • SilverStream ships with the Xerces parser from
    the Apache Group

6
XML Documents
  • Header
  • XMLDeclares the document is an XML document and
    the version of XML that the document is using.
  • Document TypeDocument follows rules defined in a
    document type definition file (optional).
  • Body
  • XML tags to describe the data

7
Introducing XML
Instructor This slide and the next slide should
be discussed together. You may need to flip back
and forth between the two.
7
8
Introducing XML
Instructor This slide and the previous slide
should be discussed together. You may need to
flip back and forth between the two.
XML in IE5 browser
8
9
Structure of XML Document
Root 0
A child has only ONE parent Child 0.1.2 for
example has parent 0.1
9
10
Structure of XML Document
Book
Chapter
Section
Chapter Heading
Paragraph
Section Heading
Entries
Text
Figure
10
11
XML Elements
  • Opening tag
  • Content
  • Closing tag
  • Empty Element
  • XML is Case Sensitive!

11
12
XML Attributes
  • Element can have 0 or more
  • Values must be in quotes
  • Associate data with element

12
13
Well Formed XML
  • There must be a single root element
  • All elements must be properly nested
  • Element tags must match (lttaggtlt/taggt)
  • Empty element may have a single tag definition
    (lttag/gt)
  • Valid names start with alphabetic or a _
    (underscore) followed by any combination of
    letters, digits, hyphens, full stops or colons.
    Colons have a special meaning in allowing a name
    to be made unique through namespaces
  • There must be no white space characters (space,
    tab or new line characters)
  • The content between tags must not contain
    explicitly the following characters lt gt

13
14
Other XML Elements and References
  • CDATA
  • Processing Instructions
  • Comments

14
15
Other XML Elements and References
  • XML Declaration
  • Version
  • External DTD
  • Character encoding

15
16
Other XML Elements and References
  • Entities
  • Character References
  • Elements or Attributes
  • White space

16
17
XML Declaration
  • Remember the XML declaration
  • Alerts whoever is processing the file that it
    contains XML data

lt?xml version1.0?gt
18
Section Objectives
  • Introduction to XML
  • Introduction to DTD

19
XML Document Types
  • Well Formed XML Documents
  • Document conforms to the rules discussed
    previously
  • Valid XML Documents
  • Well Formed document that follow rules defined
    in a Document Type Definition (DTD)

20
Introduction to DTD
  • Structured Declarations
  • Well formed XML prior discussion
  • Valid XML current discussion
  • Do not conform to XML syntax
  • Knowing the DTD allows you to create valid XML
    documents

The main purpose of this section is to teach the
student how to read and understand a DTD not to
write their own. So the topic should not be
covered in depth and the student should be
instructed to use it as a reference.
20
21
Advantages of DTD
  • Obeys DTD it is valid and well formed
  • Specification known by developer
  • Reliable Communication between applications
  • Specify default values

21
22
XML Document Structure
22
23
The Basic Declaration
lt!DOCTYPE root_name . declarations of
elements, attributes and entities . gt
lt!DOCTYPE root_name SYSTEM locationgt
23
24
The Basic Declaration
lt!DOCTYPE rootname lt!ELEMENT rootname
gt lt!ELEMENT gt lt!ELEMENT gt lt!ATTLIST
gt lt!ATTLIST gt lt!ATTLIST gt lt!ENTITY
gt lt!ENTITY gt lt!NOTATION gt lt!NOTATION
gt etc. etc. gt
24
25
Declaring Elements
  • Syntax
  • Sequence
  • Selection

25
26
Declaring Elements
  • Optional
  • Iteration

26
27
Content Definitions
  • Elements
  • PCDATA
  • EMPTY
  • ANY

27
28
Entities and Entity Declarations
  • Standard Entities
  • General Entities
  • Character Entities
  • Escaping Characters
  • Parameter Entities

28
29
Defining Attributes
lt!ATTLIST element_name attribute_name
attribute type default values/requirements gt
ltbook price "12.45" currency "GBP"gtlt/bookgt
29
30
Attribute Requirements
  • REQUIRED
  • FIXED
  • IMPLIED

30
31
Attribute Types
  • CDATA
  • Enumerated Types
  • ID and IDREF

31
32
Attribute Types
  • NMTOKEN
  • lt!ATTLIST book date_in NMTOKEN IMPLIEDgt
  •  
  • ltbook date_in "12-09-1999"gtlt/bookgt
  • lt!ATTLIST book owners NMTOKENS REQUIREDgt
  •  
  • ltbook owners "Shakespeare Bacon"gtlt/book

32
33
Attribute Types
  • ENTITY
  • lt!ENTITY fig5.jpg SYSTEM "E\XML Course\fig
    5.0.jpg" NDATA jpggt
  • ltfigure image "fig5.jpg"/gt
  • lt!ELEMENT figure EMPTYgt
  • lt!ATTLIST figure image ENTITY REQUIREDgt
  • lt!ENTITY fig5.jpg SYSTEM "E\XML Course\fig
    5.0.jpg" NDATA jpggt

33
34
Attribute Types
  • NOTATION
  • lt!NOTATION jpg SYSTEM "D\Program
    Files\Plus!\MicrosoftInternet\iexplore.exe"gt

34
35
Normalisation and White Space
  • Quotes Stripped
  • Entities Replaced
  • xmlspace

35
36
Sample DTD
lt!ELEMENT poem-collection (poem)gt lt!ELEMENT
poem(author,description?,references,
line,(date-createddate-received))gt lt!ATTLIST
poem type computergt lt!ATTLIST poem subtype
not applicablegt
37
DTDs and J2EE
  • All J2EE implementations create deployment
    descriptors based on DTDs created by Sun
    Microsystems.
  • SilverStream has created DTDs for deployment
    plans, as well as some options for its
    command-line utilities.

38
Demo of J2EE DTD and XML
Instructor Use the Web Application DTD file
in SILVERSTREAM_HOME\Resources\DTDCatalog\web-a
pp_2_2.dtd And the SilverBooks web.xml file in
SILVERSTREAM_HOME \samples\SilverBooks\src\silv
erbooks\docroot\web-inf\web.xml Have the students
open the files in a text editor or even using IE
and discuss how the DTD requirements define what
must appear in the XML file.
  • Review of the Web Application DTD and web.xml for
    SilverBooks
Write a Comment
User Comments (0)