Title: Unit 2: Introduction to XML and DTD
1Unit 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
2Section Objectives
- Introduction to XML
- Introduction to DTD
3What 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
4What 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
5J2EE 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
6XML 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
7Introducing XML
Instructor This slide and the next slide should
be discussed together. You may need to flip back
and forth between the two.
7
8Introducing 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
9Structure of XML Document
Root 0
A child has only ONE parent Child 0.1.2 for
example has parent 0.1
9
10Structure of XML Document
Book
Chapter
Section
Chapter Heading
Paragraph
Section Heading
Entries
Text
Figure
10
11XML Elements
- Opening tag
- Content
- Closing tag
- Empty Element
- XML is Case Sensitive!
11
12XML Attributes
- Element can have 0 or more
- Values must be in quotes
- Associate data with element
12
13Well 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
14Other XML Elements and References
- CDATA
- Processing Instructions
- Comments
14
15Other XML Elements and References
- XML Declaration
- Version
- External DTD
- Character encoding
15
16Other XML Elements and References
- Entities
- Character References
- Elements or Attributes
- White space
16
17XML Declaration
- Remember the XML declaration
- Alerts whoever is processing the file that it
contains XML data
lt?xml version1.0?gt
18Section Objectives
- Introduction to XML
- Introduction to DTD
19XML 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)
20Introduction 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
21Advantages of DTD
- Obeys DTD it is valid and well formed
- Specification known by developer
- Reliable Communication between applications
- Specify default values
21
22XML Document Structure
22
23The Basic Declaration
lt!DOCTYPE root_name . declarations of
elements, attributes and entities . gt
lt!DOCTYPE root_name SYSTEM locationgt
23
24The 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
25Declaring Elements
- Syntax
- Sequence
- Selection
25
26Declaring Elements
26
27Content Definitions
- Elements
- PCDATA
- EMPTY
- ANY
27
28Entities and Entity Declarations
- Standard Entities
- General Entities
- Character Entities
- Escaping Characters
- Parameter Entities
28
29Defining Attributes
lt!ATTLIST element_name attribute_name
attribute type default values/requirements gt
ltbook price "12.45" currency "GBP"gtlt/bookgt
29
30Attribute Requirements
30
31Attribute Types
- CDATA
- Enumerated Types
- ID and IDREF
31
32Attribute 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
33Attribute 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
34Attribute Types
- NOTATION
- lt!NOTATION jpg SYSTEM "D\Program
Files\Plus!\MicrosoftInternet\iexplore.exe"gt
34
35Normalisation and White Space
- Quotes Stripped
- Entities Replaced
- xmlspace
35
36Sample 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
37DTDs 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.
38Demo 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