Title: Document Type Definition
1Tutorial 02
2Contents
- The Cyber Shop Problem
- Solution
3The Cyber Shop Problem
- The head office of Cyber Shop sends the
information about its products to the branch
offices. - The products details must be store in a
consistent format at all branches. - Restrictions must be placed on the kind of data
that can be saved in the data store to ensure
uniformity and consistency of information. - The products sold by Cyber Shop are organized
into two categories, toys and books. - The product details comprise the name of the
product, a brief description about it, the price
of the product, and the quantity available in
stock. - Every product is uniquely indentified by a
product ID.
4Solution
- Analysis and Design
- Implementation
- Viewing data on a browser
51. Analysis and Design
- 1.1 Identifying the elements required for
storing structured data - 1.2 Identifying the attributes
61.1 Identifying the elements required for storing
structured data
Element Description
PRODUCTDATA Indicates that data specific to various products is being stored in the document. Acts as the root element for all other elements.
PRODUCT Represents the details (product name, description, price, and quantity) for each product.
PRODUCTNAME Represents the name of each product.
DESCRIPTION Represents the description of each product.
PRICE Represents the price of each product.
QUANTITY Represents the quantity of each product.
71.2 Identifying the attributes
- The unique identification number is an intangible
and abstract property, which can be used to
retrieve the details about a particular product.
Therefore, PRODUCTID can be defined as an
attribute of the PRODUCT element. - Category of product classifies a product as a
book or toy. So CATEGORY can also be defined as
an attribute of the PRODUCT element.
Attribute Description
PRODUCTID Represents a unique identification value for each product. It must be specified for every product.
CATEGORY Represents the category of a product and specifies whether a product is a TOY or BOOK.
82. Implementation
- 2.1 Declaring Elements
- 2.2 Storing Elements
92.1 Declaring Elements
- 2.1.1 Creating a new DTD file
- 2.1.2 Declaring the root element
- 2.1.3 Declaring the parent element
- 2.1.4 Declaring the child elements
- 2.1.5 Declaring the attributes
102.1.1 Creating a new DTD file
- Open XML Spy gt File gt New gt Choose DTD gt OK
112.1.2 Declaring the root element
- The symbol means that there can be multiple
PRODUCT element.
122.1.3 Declaring the parent element
- The PRODUCT element will have 4 child elements
PRODUCTNAME, DESCRIPTION, PRICE, QUANTITY.
132.1.4 Declaring the child elements
- The data type of each element is PCDATA, it
means Parsable Character Data and is used to
represent character content.
142.1.5 Declaring the attributes
- The attribute type REQUIRED is used when the
value for that attribute must be specified each
time the element is used. - Save the file as products.dtd.
152.2 Storing Elements
- 2.2.1 Creating a new XML file
- 2.2.2 Inserting the DTD file into the XML file
- 2.2.3 Inserting data
162.2.1 Creating a new XML file
- Create a new XML file and save it as products.xml
in the same folder with the DTD file.
172.2.2 Inserting the DTD file into the XML file
182.2.3 Inserting data
- Insert three products as below
193. Viewing data on a browser
- Open the XML file on a web browser to check again.
20Exercise
- The branches of Cyber Shop send information about
books sold by them to the head office. - The book details must be stored in a consistent
format. Restriction must be placed on the kind of
data that can be saved in the data store to
ensure uniformity and consistency of information.
- The details of books consist of the name of the
book, ISBN, first and last name of the author of
the book, the price, and the category of the
book. - The ISBN should be unique for each book. In
addition, you need to ensure that the book
category contains HISTORY, SCIENCE, or FICTION as
its valid. - Create a DTD for declaring the elements to be
used for storing book details in an XML document.
The XML file must have at least 3 stored books.
21References
- New Perspectives on Creating Web Pages with HTML
and XML (Patrick Carey Mary Kemper) - Course
Technology Publisher - Creating Cool Web Sites with HTML, XHTML and CSS
- Taylor, Dave, Wiley
22(No Transcript)