Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
DTD – Validating XML Documents Atul Kahate [email_address]
XML – A Quick Refresher
Exercise <ul><li>Create an XML document to store student information in the following format: </li></ul><ul><ul><li>Roll N...
Exercise <ul><li>We have a book titled  Web Technologies . Create an XML document that stores information about this book ...
Exercise <ul><li>Create an XML document to store employee information in the following format: </li></ul><ul><ul><li>Emplo...
XML Naming rules <ul><li>Should contain at least one letter: a-z or A-Z. </li></ul><ul><li>Can start with an alphabet or u...
Exercise <ul><li>Identify valid and invalid element names from the list below </li></ul><ul><ul><li><Project05> </li></ul>...
Some XML Terminology <ul><li>DTD </li></ul><ul><li>Elements </li></ul><ul><li>Attributes </li></ul><ul><li>Entities </li><...
Terminology Snapshot <?xml version=&quot;1.0&quot;?> <?xml-stylesheet type=&quot;text/xsl&quot; href=&quot;books_list.xsl&...
Document Type Definition (DTD)
Document Type Definition (DTD) <ul><li>Describes the components and guidelines in an XML document </li></ul><ul><li>Lists ...
DTD Example <ul><li><?xml version=“1.0” standalone=“yes”?> </li></ul><ul><li><!DOCTYPE EMPLOYEE [ </li></ul><ul><li><!ELEM...
Simple XML Example <ul><li><?xml version=“1.0”?> </li></ul><ul><li><message> </li></ul><ul><li><header> </li></ul><ul><li>...
DTD for this XML Example <ul><li><!ELEMENT message (header, body, signature)> </li></ul><ul><li><!ELEMENT header (date, fr...
Elements <ul><li>Used to organize information in an XML document </li></ul><ul><li>Similar to HTML elements (e.g. <P> <P>)...
Attributes <ul><li>Part of the element tag </li></ul><ul><li>Provide additional information about elements </li></ul><ul><...
DTD Types
Types of DTD <ul><li>External </li></ul><ul><ul><li>DTD and XML document are physically different documents </li></ul></ul...
External DTD <ul><li>Declaration inside an XML document </li></ul><ul><ul><li><!DOCTYPE book SYSTEM  http://www.example.co...
Example of External DTD <ul><li>Addressbook.xml </li></ul><ul><li><? xml   version =&quot;1.0&quot;?> </li></ul><ul><li><!...
Internal DTD <ul><li>Example </li></ul><ul><ul><li><?xml version=&quot;1.0&quot;?> </li></ul></ul><ul><ul><li><!DOCTYPE EX...
Which DTD Type to Use? <ul><li>External DTDs  </li></ul><ul><ul><li>Allow sharing of one DTD among many XML documents </li...
Standalone XML Documents <ul><li>Do not have any external DTD </li></ul><ul><li>May have an internal DTD </li></ul><ul><li...
Main Keywords used in DTD <ul><li>ELEMENT </li></ul><ul><ul><li>Describes XML element type name and its permissible child ...
Declaring Elements in a DTD
Element markup End tag Content Start tag Name At the end of an element, the closing tag </email > In the middle of an elem...
Element Markup – Note <ul><li>The element name in the start tag and the end tag must match </li></ul><ul><li>e.g. the foll...
ELEMENT Declarations in a DTD – 1 <ul><li>ELEMENT tags are used to describe XML elements in a DTD document </li></ul><ul><...
ELEMENT Declarations in a DTD – 2 <ul><li>content_category </li></ul><ul><ul><li>Five types </li></ul></ul><ul><ul><ul><li...
ELEMENT Declarations in a DTD – 3 <ul><li>ANY and EMPTY elements </li></ul><ul><ul><li>Follow the first form of declaratio...
ELEMENT Declarations in a DTD – 4 <ul><li>ANY and EMPTY elements  … contd … </li></ul><ul><ul><li>EMPTY – Cannot have text...
ELEMENT Declarations in a DTD – 5 <ul><li>Other categories </li></ul><ul><ul><li>Element, Mixed, or PCDATA are used </li><...
ELEMENT Declarations in a DTD – 6 <ul><li>Content models </li></ul><ul><ul><li>Text only </li></ul></ul><ul><ul><ul><li><!...
Sequence and Choice Lists – Another Example <ul><li>Choice Example </li></ul><ul><ul><li><!ELEMENT color (red | yellow | g...
ELEMENT Declarations in a DTD – 7 <ul><li>Text only (PCDATA) content </li></ul><ul><ul><li>Only text data is allowed in th...
ELEMENT Declarations in a DTD – 8 <ul><li>Element only content </li></ul><ul><ul><li>Can contain child elements, but no te...
ELEMENT Declarations in a DTD – 9 <ul><li>Mixed content </li></ul><ul><ul><li>Allows child elements or text </li></ul></ul...
Specifying Cardinality <ul><li>Used to specify how often an element or an element group can repeat or be omitted </li></ul...
Examples <ul><li><!ELEMENT PersonName </li></ul><ul><li>( </li></ul><ul><li>(Mr | Ms | Dr)?, FirstName, MiddleName*, LastN...
Corresponding XML data <ul><li><PersonName> </li></ul><ul><li><Mr /> </li></ul><ul><li><FirstName>Sachin</FirstName> </li>...
Exercise <ul><li>For the following XML document, create a DTD </li></ul><ul><li><?xml version=&quot;1.0&quot;?> </li></ul>...
Exercise Solution: DTD  <ul><li><!ELEMENT ADDRESSBOOK (CONTACT)> </li></ul><ul><li><!ELEMENT CONTACT (NAME, ADDRESS, CITY,...
Exercises – 1 <ul><li>We want to keep the following information regarding cricket scores. Suggest a DTD structure. </li></...
Exercises – 2 <ul><li>A college wants to maintain the following information about its students. Design a DTD. </li></ul><u...
Exercises – 3 <ul><li>Create a DTD for this XML: </li></ul><ul><li><?xml version=&quot;1.0&quot;?> </li></ul><ul><li>< ord...
Entities
Entities <ul><li>Unit of data </li></ul><ul><li>Can contain binary data, images, textual information, etc </li></ul><ul><l...
Entity Example <ul><li>DTD </li></ul><ul><li><!ELEMENT list (name*)> </li></ul><ul><li><!ELEMENT name (#PCDATA)> </li></ul...
Pre-defined Entities <ul><li>Available as a default </li></ul><ul><ul><li>amp: ampersand (&) </li></ul></ul><ul><ul><li>ap...
Attributes
Usage of Attributes <ul><li>Example without attributes </li></ul><ul><ul><li><Person> </li></ul></ul><ul><ul><ul><li><Firs...
Specifying an Attribute Attribute value end ‘ Attribute value start ‘ Value of the attribute Value Start tag close delimit...
Attribute Declarations <ul><li>Used to describe the attributes inside an element </li></ul><ul><li>Syntax: <!ATTLIST eleme...
Example Containing Entities and an Attribute <ul><li><?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> </li></ul>...
Declaring Multiple Attributes <ul><li><?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> </li></ul><ul><li><!DOCTY...
Attribute Defaults <ul><li>We can specify if an attribute is mandatory </li></ul>Attribute Default Description #REQUIRED M...
Attributes - #REQUIRED <ul><li>DTD </li></ul><ul><ul><li><!ATTLIST Employee Height CDATA #REQUIRED> </li></ul></ul><ul><li...
Attributes - #IMPLIED <ul><li>DTD </li></ul><ul><ul><li><!ATTLIST Employee Height CDATA #IMPLIED> </li></ul></ul><ul><li>V...
Attributes - #FIXED <ul><li>DTD </li></ul><ul><ul><li><!ELEMENT Employee (#PCDATA)> </li></ul></ul><ul><ul><li><!ATTLIST E...
Attributes – Default Values <ul><li>DTD </li></ul><ul><ul><li><!ELEMENT Employee (#PCDATA)> </li></ul></ul><ul><ul><li><!A...
Important Attribute Types <ul><li>CDATA – Character data (Simple text string) </li></ul><ul><li>Enumerated values – One fr...
CDATA Attribute Type <ul><li>Strings of characters </li></ul><ul><li>Any attribute that does not have anything specified i...
Enumerated Attribute Type <ul><li>Lists of possible vales </li></ul><ul><li>Example </li></ul><ul><ul><li><!ELEMENT fruit>...
Exercise <ul><li>Create a DTD for the following XML example: </li></ul><ul><li><?xml version = &quot;1.0&quot;?> </li></ul...
Solution <ul><li><!ELEMENT letter (contact+, salutation, paragraph+, closing, signature)> </li></ul><ul><li><!ELEMENT cont...
Case Study – Book information <ul><li>LIBRARY.DTD file describes the document </li></ul>ISBN number ISBN Scale of 1-5 RATI...
Case Study – Elements <ul><li><!ELEMENT book> </li></ul><ul><li><!ELEMENT title> </li></ul><ul><li><!ELEMENT author> </li>...
Case Study – Attributes <ul><li><!ATTLIST cover TYPE (HARDBACK | PAPERBACK) “PAPERBACK” #REQUIRED> </li></ul><ul><li><!ATT...
Case Study – Modified Elements Declaration (Nesting) <ul><li><!ELEMENT book (title, author, publisher, cover, category, is...
Case Study –  Let us put it all together <ul><li><?xml version=&quot;1.0&quot; standalone=&quot;yes&quot;?> </li></ul><ul>...
Thank you! Any Questions?
Upcoming SlideShare
Loading in …5
×

2 dtd - validating xml documents

3,991 views

Published on

DTD-XML

Published in: Education, Technology
  • Be the first to comment

2 dtd - validating xml documents

  1. 1. DTD – Validating XML Documents Atul Kahate [email_address]
  2. 2. XML – A Quick Refresher
  3. 3. Exercise <ul><li>Create an XML document to store student information in the following format: </li></ul><ul><ul><li>Roll Number </li></ul></ul><ul><ul><li>Name </li></ul></ul><ul><ul><li>Marks </li></ul></ul><ul><ul><ul><li>Web Technologies </li></ul></ul></ul><ul><ul><ul><li>XML </li></ul></ul></ul><ul><ul><ul><li>J2EE </li></ul></ul></ul><ul><ul><ul><li>Network Programming </li></ul></ul></ul><ul><ul><li>Rank </li></ul></ul>
  4. 4. Exercise <ul><li>We have a book titled Web Technologies . Create an XML document that stores information about this book in the following format: </li></ul><ul><ul><li>Name: Web Technologies </li></ul></ul><ul><ul><li>Part (1-3) </li></ul></ul><ul><ul><ul><li>Chapters (Chapter 1-6) </li></ul></ul></ul><ul><ul><ul><ul><li>Sections (Section 1-3) </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Summary </li></ul></ul></ul></ul>
  5. 5. Exercise <ul><li>Create an XML document to store employee information in the following format: </li></ul><ul><ul><li>Employee Number </li></ul></ul><ul><ul><li>Name </li></ul></ul><ul><ul><li>Department </li></ul></ul><ul><ul><li>Manager Name </li></ul></ul><ul><ul><li>Projects assigned </li></ul></ul><ul><ul><ul><li>Project 1 </li></ul></ul></ul><ul><ul><ul><li>Project 2 </li></ul></ul></ul><ul><ul><ul><li>Project 3 </li></ul></ul></ul><ul><ul><li>Designation </li></ul></ul>
  6. 6. XML Naming rules <ul><li>Should contain at least one letter: a-z or A-Z. </li></ul><ul><li>Can start with an alphabet or underscore. </li></ul><ul><li>Can contain letters, digits, hyphens, underscores, full stops. </li></ul><ul><li>Comments: Enclose in <!-- and --> tags. </li></ul><ul><ul><li>e.g. <!– This is a comment --> </li></ul></ul>
  7. 7. Exercise <ul><li>Identify valid and invalid element names from the list below </li></ul><ul><ul><li><Project05> </li></ul></ul><ul><ul><li><PROJECT05> </li></ul></ul><ul><ul><li><Project.05> </li></ul></ul><ul><ul><li><_05Project> </li></ul></ul><ul><ul><li><project05> </li></ul></ul><ul><ul><li><project_05> </li></ul></ul><ul><li>Identify valid and invalid element names from the list below </li></ul><ul><ul><li><Project=05> </li></ul></ul><ul><ul><li><PROJECT:05> </li></ul></ul><ul><ul><li><Project 5> </li></ul></ul><ul><ul><li><Project%05> </li></ul></ul><ul><ul><li><05project> </li></ul></ul><ul><ul><li><.project.05> </li></ul></ul>
  8. 8. Some XML Terminology <ul><li>DTD </li></ul><ul><li>Elements </li></ul><ul><li>Attributes </li></ul><ul><li>Entities </li></ul><ul><li>Markup </li></ul>
  9. 9. Terminology Snapshot <?xml version=&quot;1.0&quot;?> <?xml-stylesheet type=&quot;text/xsl&quot; href=&quot;books_list.xsl&quot;?> <BOOKS> <BOOK pubyear=&quot;1929&quot;> <BOOK_TITLE>Look Homeward, Angel</BOOK_TITLE> <AUTHOR>Wolfe, Thomas</AUTHOR> </BOOK> <BOOK pubyear=&quot;1973&quot;> <BOOK_TITLE>Gravity's Rainbow</BOOK_TITLE> <AUTHOR>Pynchon, Thomas</AUTHOR> </BOOK> <BOOK pubyear=&quot;1977&quot;> <BOOK_TITLE>Cards as Weapons</BOOK_TITLE> <AUTHOR>Jay, Ricky</AUTHOR> </BOOK> <BOOK pubyear=&quot;2001&quot;> <BOOK_TITLE>Computer Networks</BOOK_TITLE> <AUTHOR>Tanenbaum, Andrew</AUTHOR> </BOOK> </BOOKS> XML tag Root element Element name Element value End element indicator Start element indicator Attribute name Attribute Value
  10. 10. Document Type Definition (DTD)
  11. 11. Document Type Definition (DTD) <ul><li>Describes the components and guidelines in an XML document </li></ul><ul><li>Lists </li></ul><ul><ul><li>Elements </li></ul></ul><ul><ul><li>Attributes and their possible values </li></ul></ul><ul><ul><li>Entities </li></ul></ul><ul><ul><li>Interaction of all of the above </li></ul></ul><ul><li>“Rule book” for an XML document </li></ul>
  12. 12. DTD Example <ul><li><?xml version=“1.0” standalone=“yes”?> </li></ul><ul><li><!DOCTYPE EMPLOYEE [ </li></ul><ul><li><!ELEMENT EMPLOYEE (ORG, NAME, DEPT, SALARY)> </li></ul><ul><li><!ELEMENT ORG (#PCDATA)> </li></ul><ul><li><!ELEMENT NAME (#PCDATA)> </li></ul><ul><li><!ELEMENT DEPT (#PCDATA)> </li></ul><ul><li><!ELEMENT SALARY (#PCDATA)> </li></ul><ul><li>]> </li></ul><ul><li><EMPLOYEE> </li></ul><ul><li><ORG>test </ORG> </li></ul><ul><li><NAME>Parag</NAME> </li></ul><ul><li><DEPT>J2EE</DEPT> </li></ul><ul><li><SALARY>10000</SALARY> </li></ul><ul><li></EMPLOYEE> </li></ul>
  13. 13. Simple XML Example <ul><li><?xml version=“1.0”?> </li></ul><ul><li><message> </li></ul><ul><li><header> </li></ul><ul><li><date> 25 September 2004 </date> </li></ul><ul><li><from> Me </from> </li></ul><ul><li><to> You </to> </li></ul><ul><li><subject> Test message </subject> </li></ul><ul><li></header> </li></ul><ul><li><body> Hello World </li></ul><ul><li></body> </li></ul><ul><li><signature> XYZ company </signature> </li></ul><ul><li></message> </li></ul>
  14. 14. DTD for this XML Example <ul><li><!ELEMENT message (header, body, signature)> </li></ul><ul><li><!ELEMENT header (date, from, to, subject) > </li></ul>
  15. 15. Elements <ul><li>Used to organize information in an XML document </li></ul><ul><li>Similar to HTML elements (e.g. <P> <P>) </li></ul><ul><li>Every XML document must have exactly one root element </li></ul><ul><li>Empty elements are shown by using <empty_element/> </li></ul>
  16. 16. Attributes <ul><li>Part of the element tag </li></ul><ul><li>Provide additional information about elements </li></ul><ul><li>Optional </li></ul><ul><li>Can be specified only in the element start tag </li></ul>
  17. 17. DTD Types
  18. 18. Types of DTD <ul><li>External </li></ul><ul><ul><li>DTD and XML document are physically different documents </li></ul></ul><ul><ul><li>More common for professional documents </li></ul></ul><ul><li>Internal </li></ul><ul><ul><li>DTD is declared inside the XML document </li></ul></ul><ul><ul><li>Useful for simple documents </li></ul></ul>
  19. 19. External DTD <ul><li>Declaration inside an XML document </li></ul><ul><ul><li><!DOCTYPE book SYSTEM http://www.example.com/dtd/book.dtd > </li></ul></ul><ul><ul><li>DTD declaration types </li></ul></ul><ul><ul><ul><li>SYSTEM – Specifies the URL from where the parser can obtain the actual DTD </li></ul></ul></ul><ul><ul><ul><li>PUBLIC – Does not specify a particular location for the DTD </li></ul></ul></ul>
  20. 20. Example of External DTD <ul><li>Addressbook.xml </li></ul><ul><li><? xml version =&quot;1.0&quot;?> </li></ul><ul><li><! DOCTYPE DOCUMENT SYSTEM &quot;addressbook.dtd&quot;> </li></ul><ul><li>< ADDRESSBOOK > </li></ul><ul><li>< CONTACT > </li></ul><ul><li>< NAME > Name 1 </ NAME > </li></ul><ul><li>< ADDRESS > Address 1 </ ADDRESS > </li></ul><ul><li>< CITY > City 1 </ CITY > </li></ul><ul><li>< PIN > Pin 1 </ PIN > </li></ul><ul><li>< PHONE > Phone 1 </ PHONE > </li></ul><ul><li></ CONTACT > </li></ul><ul><li></ ADDRESSBOOK > </li></ul><ul><li>Addressbook.dtd </li></ul><ul><li><! ELEMENT ADDRESSBOOK ( CONTACT) > </li></ul><ul><li><! ELEMENT CONTACT ( NAME, ADDRESS, CITY, PIN, PHONE) > </li></ul><ul><li><! ELEMENT NAME (#PCDATA)> </li></ul><ul><li><! ELEMENT ADDRESS (#PCDATA)> </li></ul><ul><li><! ELEMENT CITY (#PCDATA)> </li></ul><ul><li><! ELEMENT PIN (#PCDATA)> </li></ul><ul><li><! ELEMENT PHONE (#PCDATA)> </li></ul>
  21. 21. Internal DTD <ul><li>Example </li></ul><ul><ul><li><?xml version=&quot;1.0&quot;?> </li></ul></ul><ul><ul><li><!DOCTYPE EXAMPLE[ </li></ul></ul><ul><ul><li><!ELEMENT EXAMPLE (#PCDATA)> </li></ul></ul><ul><ul><li>> </li></ul></ul><ul><ul><li><EXAMPLE> Insert the comment: </EXAMPLE> </li></ul></ul>
  22. 22. Which DTD Type to Use? <ul><li>External DTDs </li></ul><ul><ul><li>Allow sharing of one DTD among many XML documents </li></ul></ul><ul><ul><li>Allow keeping the structure (DTD) and data (XML) separate </li></ul></ul><ul><ul><li>Updates can be centralized </li></ul></ul><ul><ul><li>Unnecessary duplications can be avoided </li></ul></ul><ul><li>Internal DTDs </li></ul><ul><ul><li>Simpler to try out and test at first </li></ul></ul>
  23. 23. Standalone XML Documents <ul><li>Do not have any external DTD </li></ul><ul><li>May have an internal DTD </li></ul><ul><li>Use of standalone keyword </li></ul><ul><ul><li><?XML version=“1.0” standalone=“yes”?> </li></ul></ul><ul><ul><li>… </li></ul></ul><ul><li>Use of the standalone keyword is optional </li></ul>
  24. 24. Main Keywords used in DTD <ul><li>ELEMENT </li></ul><ul><ul><li>Describes XML element type name and its permissible child elements </li></ul></ul><ul><li>ATTLIST </li></ul><ul><ul><li>Declares XML element attribute names, plus permissible/default values </li></ul></ul><ul><li>ENTITY </li></ul><ul><ul><li>Declares special character references, text macros, or repetitive content </li></ul></ul>
  25. 25. Declaring Elements in a DTD
  26. 26. Element markup End tag Content Start tag Name At the end of an element, the closing tag </email > In the middle of an element, its content Meeting At the start of an element, the opening tag < email > Description Symbol
  27. 27. Element Markup – Note <ul><li>The element name in the start tag and the end tag must match </li></ul><ul><li>e.g. the following is wrong </li></ul><ul><ul><li><simple.text> This is wrong! </simple.Text> </li></ul></ul>
  28. 28. ELEMENT Declarations in a DTD – 1 <ul><li>ELEMENT tags are used to describe XML elements in a DTD document </li></ul><ul><li>The ELEMENT declaration can have one of the following two forms </li></ul><ul><ul><li><!ELEMENT name content_category > </li></ul></ul><ul><ul><li><!ELEMENT name (content_model) > </li></ul></ul><ul><ul><li>content_category and content_model specify what kind of content can appear inside a given XML element </li></ul></ul>
  29. 29. ELEMENT Declarations in a DTD – 2 <ul><li>content_category </li></ul><ul><ul><li>Five types </li></ul></ul><ul><ul><ul><li>Any – Any well-formed XML data </li></ul></ul></ul><ul><ul><ul><li>None (or Empty) – Cannot contain text or child elements, but can contain attributes </li></ul></ul></ul><ul><ul><ul><li>Text only – Can contain text, but no child elements </li></ul></ul></ul><ul><ul><ul><li>Element only - Can contain child elements, but no text </li></ul></ul></ul><ul><ul><ul><li>Mixed – Can contain a mixture of child elements and text </li></ul></ul></ul><ul><ul><li>All these categories allow declarations of attributes by using the ATTLIST tag </li></ul></ul>
  30. 30. ELEMENT Declarations in a DTD – 3 <ul><li>ANY and EMPTY elements </li></ul><ul><ul><li>Follow the first form of declaration, i.e. </li></ul></ul><ul><ul><ul><li><!ELEMENT name content_cateogry> </li></ul></ul></ul><ul><ul><li>ANY – Allows anything well-formed </li></ul></ul><ul><ul><ul><li>Example DTD declaration </li></ul></ul></ul><ul><ul><ul><ul><li><!ELEMENT AnythingAllowed ANY > </li></ul></ul></ul></ul><ul><ul><ul><li>Corresponding XML </li></ul></ul></ul><ul><ul><ul><ul><li><? xml version =&quot;1.0&quot; encoding =&quot;utf-8&quot; ?> </li></ul></ul></ul></ul><ul><ul><ul><ul><li>< AnythingAllowed > </li></ul></ul></ul></ul><ul><ul><ul><ul><li>< AChildElement >Hello</ AChildElement > </li></ul></ul></ul></ul><ul><ul><ul><ul><li>< AnotherChild > </li></ul></ul></ul></ul><ul><ul><ul><ul><li>< ChildWithinChild >test</ ChildWithinChild > </li></ul></ul></ul></ul><ul><ul><ul><ul><li></ AnotherChild > </li></ul></ul></ul></ul><ul><ul><ul><ul><li></ AnythingAllowed > </li></ul></ul></ul></ul><ul><ul><ul><li>Or this </li></ul></ul></ul><ul><ul><ul><ul><li><? xml version =&quot;1.0&quot; encoding =&quot;utf-8&quot; ?> </li></ul></ul></ul></ul><ul><ul><ul><ul><li>< AnythingAllowed / > </li></ul></ul></ul></ul>
  31. 31. ELEMENT Declarations in a DTD – 4 <ul><li>ANY and EMPTY elements … contd … </li></ul><ul><ul><li>EMPTY – Cannot have text or sub-elements, but can contain attributes </li></ul></ul><ul><ul><li>Example DTD declarations </li></ul></ul><ul><ul><ul><li><!ELEMENT employee EMPTY> </li></ul></ul></ul><ul><ul><ul><li><!ELEMENT building EMPTY> </li></ul></ul></ul><ul><ul><li>Corresponding XML elements </li></ul></ul><ul><ul><ul><li><employee></employee> </li></ul></ul></ul><ul><ul><ul><li><employee stillinservice = “true”/> </li></ul></ul></ul><ul><ul><ul><li><building name = “Main center”></building> </li></ul></ul></ul>
  32. 32. ELEMENT Declarations in a DTD – 5 <ul><li>Other categories </li></ul><ul><ul><li>Element, Mixed, or PCDATA are used </li></ul></ul><ul><ul><li>Syntax: </li></ul></ul><ul><ul><ul><li><!ELEMENT name ( content_model ) cardinality > </li></ul></ul></ul><ul><ul><li>Content models </li></ul></ul><ul><ul><ul><li>Text only, Element only, or mixed </li></ul></ul></ul><ul><ul><ul><li>Examples of each type follow </li></ul></ul></ul><ul><ul><li>No content model is needed for ANY or EMPTY categories </li></ul></ul>
  33. 33. ELEMENT Declarations in a DTD – 6 <ul><li>Content models </li></ul><ul><ul><li>Text only </li></ul></ul><ul><ul><ul><li><!ELEMENT name (#PCDATA) > </li></ul></ul></ul><ul><ul><li>Element only </li></ul></ul><ul><ul><ul><li><!ELEMENT name ((child1, child2) | (child3, child4)) > </li></ul></ul></ul><ul><ul><li>Mixed </li></ul></ul><ul><ul><ul><li><!ELEMENT name (#PCDATA | child1 | child2)* > </li></ul></ul></ul><ul><ul><li>Two kinds of lists can appear within content models </li></ul></ul><ul><ul><ul><li>Sequence lists : Child elements must appear in the specified order, using a comma to separate the element names as shown above </li></ul></ul></ul><ul><ul><ul><li>Choice lists : List of mutually exclusive child elements, separated by the pipe symbol as shown above </li></ul></ul></ul>
  34. 34. Sequence and Choice Lists – Another Example <ul><li>Choice Example </li></ul><ul><ul><li><!ELEMENT color (red | yellow | green)> </li></ul></ul><ul><ul><li>Specifies that: </li></ul></ul><ul><ul><ul><li>The color element must contain a red element, a yellow element, or a green element </li></ul></ul></ul><ul><ul><ul><li>Only one of these options can be chosen </li></ul></ul></ul><ul><ul><li>e.g. My favorite color is <color> <red> </red> </color> and not so favorite color is <color> <yellow> </yellow> </color>. </li></ul></ul><ul><li>Sequence and choice example: </li></ul><ul><ul><ul><li><! ELEMENT PersonName </li></ul></ul></ul><ul><ul><ul><li>( </li></ul></ul></ul><ul><ul><ul><li>(Mr | Ms | Dr), FirstName, MiddleName, LastName) </li></ul></ul></ul><ul><ul><ul><li>) </li></ul></ul></ul><ul><ul><ul><li>> </li></ul></ul></ul>
  35. 35. ELEMENT Declarations in a DTD – 7 <ul><li>Text only (PCDATA) content </li></ul><ul><ul><li>Only text data is allowed in the XML content </li></ul></ul><ul><ul><li>DTD specifies this with the #PCDATA keyword </li></ul></ul><ul><ul><li>Example </li></ul></ul><ul><ul><ul><li>DTD </li></ul></ul></ul><ul><ul><ul><ul><li><!ELEMENT name (#PCDATA) > </li></ul></ul></ul></ul><ul><ul><ul><li>XML </li></ul></ul></ul><ul><ul><ul><ul><li><name>Atul Kahate</name> </li></ul></ul></ul></ul>
  36. 36. ELEMENT Declarations in a DTD – 8 <ul><li>Element only content </li></ul><ul><ul><li>Can contain child elements, but no text </li></ul></ul><ul><ul><li>Example </li></ul></ul><ul><ul><ul><li>DTD </li></ul></ul></ul><ul><ul><ul><ul><li><!ELEMENT name (first, last) > </li></ul></ul></ul></ul><ul><ul><ul><li>XML </li></ul></ul></ul><ul><ul><ul><ul><li><name> </li></ul></ul></ul></ul><ul><ul><ul><ul><ul><li><first>Atul</first> </li></ul></ul></ul></ul></ul><ul><ul><ul><ul><ul><li></last>Kahate</last> </li></ul></ul></ul></ul></ul><ul><ul><ul><ul><li></name> </li></ul></ul></ul></ul><ul><ul><ul><li>The element name must contain exactly two child elements first and last , and they must appear exactly once, in the specified sequence </li></ul></ul></ul>
  37. 37. ELEMENT Declarations in a DTD – 9 <ul><li>Mixed content </li></ul><ul><ul><li>Allows child elements or text </li></ul></ul><ul><ul><li>Example </li></ul></ul><ul><ul><ul><li>DTD </li></ul></ul></ul><ul><ul><ul><ul><li><!ELEMENT name (#PCDATA | (first, last) > </li></ul></ul></ul></ul><ul><ul><ul><li>Allowed XMLs </li></ul></ul></ul><ul><ul><ul><ul><li><name>Atul Kahate</name> OR </li></ul></ul></ul></ul><ul><ul><ul><ul><li><name> </li></ul></ul></ul></ul><ul><ul><ul><ul><ul><li><first>Atul</first> </li></ul></ul></ul></ul></ul><ul><ul><ul><ul><ul><li><last>Kahate</last> </li></ul></ul></ul></ul></ul><ul><ul><ul><ul><li></name> </li></ul></ul></ul></ul>
  38. 38. Specifying Cardinality <ul><li>Used to specify how often an element or an element group can repeat or be omitted </li></ul><ul><li>? specifies a zero or one occurrence </li></ul><ul><ul><li>e.g. <!ELEMENT testing (one, two?, three)> </li></ul></ul><ul><ul><li>Means that two can occur only once or not at all inside the testing element </li></ul></ul><ul><li>* specifies zero or more times occurrence </li></ul><ul><ul><li>e.g. <!ELEMENT match (result, round*)> </li></ul></ul><ul><ul><li>Means that round can occur any number of times or not at all inside the match element </li></ul></ul><ul><li>+ specifies at least one or more occurrence </li></ul><ul><ul><li>e.g. <!ELEMENT match (result, round+)> </li></ul></ul><ul><ul><li>Means that round can occur at least once or more inside the match element </li></ul></ul>
  39. 39. Examples <ul><li><!ELEMENT PersonName </li></ul><ul><li>( </li></ul><ul><li>(Mr | Ms | Dr)?, FirstName, MiddleName*, LastName) </li></ul><ul><li>) </li></ul><ul><li>> </li></ul><ul><li><!ELEMENT PersonName </li></ul><ul><li>( </li></ul><ul><li>SingleName | </li></ul><ul><li>((Mr | Ms | Dr)?, FirstName, MiddleName*, LastName)) </li></ul><ul><li>) </li></ul><ul><li>> </li></ul>
  40. 40. Corresponding XML data <ul><li><PersonName> </li></ul><ul><li><Mr /> </li></ul><ul><li><FirstName>Sachin</FirstName> </li></ul><ul><li><LastName>Tendulkar</LastName> </li></ul><ul><li></PersonName> </li></ul><ul><li><PersonName> </li></ul><ul><li><FirstName>Sachin</FirstName> </li></ul><ul><li><LastName>Tendulkar</LastName> </li></ul><ul><li></PersonName> </li></ul><ul><li><PersonName> </li></ul><ul><li><SingleName>Tendulkar</SingleName> </li></ul><ul><li></PersonName> </li></ul>
  41. 41. Exercise <ul><li>For the following XML document, create a DTD </li></ul><ul><li><?xml version=&quot;1.0&quot;?> </li></ul><ul><li><ADDRESSBOOK> </li></ul><ul><li><CONTACT> </li></ul><ul><li><NAME> Name 1 </NAME> </li></ul><ul><li><ADDRESS> Address 1 </ADDRESS> </li></ul><ul><li><CITY> City 1 </CITY> </li></ul><ul><li><PIN> Pin 1 </PIN> </li></ul><ul><li><PHONE> Phone 1 </PHONE> </li></ul><ul><li></CONTACT> </li></ul><ul><li></ADDRESSBOOK> </li></ul>
  42. 42. Exercise Solution: DTD <ul><li><!ELEMENT ADDRESSBOOK (CONTACT)> </li></ul><ul><li><!ELEMENT CONTACT (NAME, ADDRESS, CITY, PIN, PHONE)> </li></ul><ul><li><!ELEMENT NAME (#PCDATA)> </li></ul><ul><li><!ELEMENT ADDRESS (#PCDATA)> </li></ul><ul><li><!ELEMENT CITY (#PCDATA)> </li></ul><ul><li><!ELEMENT PIN (#PCDATA)> </li></ul><ul><li><!ELEMENT PHONE (#PCDATA)> </li></ul>
  43. 43. Exercises – 1 <ul><li>We want to keep the following information regarding cricket scores. Suggest a DTD structure. </li></ul><ul><ul><li>Batting Team </li></ul></ul><ul><ul><li>Opposition Team </li></ul></ul><ul><ul><li>Innings (1 or 2) </li></ul></ul><ul><ul><li>Batting position (1 to 11) </li></ul></ul><ul><ul><li>Batsman Name </li></ul></ul><ul><ul><li>How Out? (e.g. caught Hayden, or not out) </li></ul></ul><ul><ul><li>Bowler (e.g. McGrath, or not applicable) </li></ul></ul><ul><ul><li>Runs scored </li></ul></ul>
  44. 44. Exercises – 2 <ul><li>A college wants to maintain the following information about its students. Design a DTD. </li></ul><ul><ul><li>Roll number of student </li></ul></ul><ul><ul><li>Student name (Composed of first, middle, and last names; or as a single name without any split) </li></ul></ul><ul><ul><li>Trimester Number </li></ul></ul><ul><ul><li>Subject </li></ul></ul><ul><ul><li>Type (Compulsory or Elective) </li></ul></ul><ul><ul><li>Maximum Marks </li></ul></ul><ul><ul><li>Marks Obtained </li></ul></ul><ul><ul><li>Total Maximum Marks </li></ul></ul><ul><ul><li>Total Marks Obtained </li></ul></ul><ul><ul><li>Percentage </li></ul></ul><ul><ul><li>Result </li></ul></ul><ul><ul><li>Rank </li></ul></ul>
  45. 45. Exercises – 3 <ul><li>Create a DTD for this XML: </li></ul><ul><li><?xml version=&quot;1.0&quot;?> </li></ul><ul><li>< order > </li></ul><ul><li>< items > </li></ul><ul><li>< item > </li></ul><ul><li>< item_code > A001 </ item_code > </li></ul><ul><li>< item_name > Book </ item_name > </li></ul><ul><li>< item_quantity > 2 </ item_quantity > </li></ul><ul><li>< item_rate > 100 </ item_rate > </li></ul><ul><li></ item > </li></ul><ul><li>< item > </li></ul><ul><li>< item_code > B001 </ item_code > </li></ul><ul><li>< item_name > Watch </ item_name > </li></ul><ul><li>< item_quantity > 3 </ item_quantity > </li></ul><ul><li>< item_rate > 75 </ item_rate > </li></ul><ul><li></ item > </li></ul><ul><li></ items > </li></ul><ul><li>< contact > </li></ul><ul><li>< customer_code > G6171612 </ customer_code > </li></ul><ul><li>< customer_name > test test </ customer_name > </li></ul><ul><li>< customer_address > </li></ul><ul><li>< address_1 > 43 Navi Peth </ address_1 > </li></ul><ul><li>< address_2 > Main building </ address_2 > </li></ul><ul><li>< city > Pune </ city > </li></ul><ul><li>< state /> </li></ul><ul><li>< country > India </ country > </li></ul><ul><li>< pin > 411001 </ pin > </li></ul><ul><li>< phone_details > </li></ul><ul><li>< home_landline > 25530833 </ home_landline > </li></ul><ul><li>< work > 22981011 </ work > </li></ul><ul><li>< mobile > 98111-32111 </ mobile > </li></ul><ul><li></ phone_details > </li></ul><ul><li></ customer_address > </li></ul><ul><li></ contact > </li></ul><ul><li>< payment_details > </li></ul><ul><li>< payment_method > credit card </ payment_method > </li></ul><ul><li>< card_number > 191921000102101188 </ card_number > </li></ul><ul><li>< brand > visa </ brand > </li></ul><ul><li>< expiry_date > 02-11 </ expiry_date > </li></ul><ul><li>< cheque_number /> </li></ul><ul><li>< cheque_issuing_bank /> </li></ul><ul><li>< amount > 500 </ amount > </li></ul><ul><li></ payment_details > </li></ul><ul><li></ order > </li></ul>
  46. 46. Entities
  47. 47. Entities <ul><li>Unit of data </li></ul><ul><li>Can contain binary data, images, textual information, etc </li></ul><ul><li>Included inside an XML document with the & symbol </li></ul><ul><li>Generally contain </li></ul><ul><ul><li>Frequently used phrases </li></ul></ul><ul><ul><li>Text strings </li></ul></ul><ul><ul><li>Chunks of text </li></ul></ul>
  48. 48. Entity Example <ul><li>DTD </li></ul><ul><li><!ELEMENT list (name*)> </li></ul><ul><li><!ELEMENT name (#PCDATA)> </li></ul><ul><li><!ENTITY prof &quot;Professor&quot;> </li></ul><ul><li>XML </li></ul><ul><li><?xml version=&quot;1.0&quot;?> </li></ul><ul><li><!DOCTYPE list SYSTEM &quot;professor.dtd&quot;> </li></ul><ul><li><list> </li></ul><ul><li><name>&prof; Douglas Comer</name> </li></ul><ul><li><name>&prof; Andrew Tanenbaum</name> </li></ul><ul><li></list> </li></ul>
  49. 49. Pre-defined Entities <ul><li>Available as a default </li></ul><ul><ul><li>amp: ampersand (&) </li></ul></ul><ul><ul><li>apos: apostrophe (‘) </li></ul></ul><ul><ul><li>gt: greater than (>) </li></ul></ul><ul><ul><li>lt: less than (<) </li></ul></ul><ul><ul><li>quot: quotation mark (“) </li></ul></ul><ul><li>Using the default entities </li></ul><ul><ul><li>Please make sure that your offer is &gt; $500 </li></ul></ul><ul><ul><li>Please make sure that your offer is > $500 </li></ul></ul>
  50. 50. Attributes
  51. 51. Usage of Attributes <ul><li>Example without attributes </li></ul><ul><ul><li><Person> </li></ul></ul><ul><ul><ul><li><FirstName>Maithili</FirstName> </li></ul></ul></ul><ul><ul><ul><li><LastName>Shetty</LastName> </li></ul></ul></ul><ul><ul><ul><li><Department>Software</Department> </li></ul></ul></ul><ul><ul><li></Person> </li></ul></ul><ul><li>Same example, with all child elements changed to attributes </li></ul><ul><ul><li><Person FirstName=“Maithili” LastName=“Shetty” Department=“Software” /> </li></ul></ul>
  52. 52. Specifying an Attribute Attribute value end ‘ Attribute value start ‘ Value of the attribute Value Start tag close delimiter > Value indicator = Attribute name attribute.name Element name element.name Start tag open delimiter < Description Symbol
  53. 53. Attribute Declarations <ul><li>Used to describe the attributes inside an element </li></ul><ul><li>Syntax: <!ATTLIST element.name attribute.definitions> </li></ul><ul><li>Significance </li></ul><ul><ul><li>Declares the names of the allowed attributes </li></ul></ul><ul><ul><li>States the type of each attribute </li></ul></ul><ul><ul><li>Makes it possible to specify a default value for each attribute </li></ul></ul><ul><li>Each attribute declaration is as follows: </li></ul><ul><ul><li>attribute.name attribute.type </li></ul></ul>
  54. 54. Example Containing Entities and an Attribute <ul><li><?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> </li></ul><ul><li><!DOCTYPE Invoice [ </li></ul><ul><li><!ENTITY copy &quot;©&quot;> </li></ul><ul><li><!ENTITY Vendor &quot;i-flex solutions limited&quot;> </li></ul><ul><li><!ENTITY Disclaimer &quot;No warranty! &copy; 2007 &Vendor;&quot;> </li></ul><ul><li><!ENTITY char_A &quot;A&quot;> </li></ul><ul><li><!ELEMENT Invoice (Notice*)> </li></ul><ul><li><!ATTLIST Invoice </li></ul><ul><li>name CDATA #REQUIRED </li></ul><ul><li>> </li></ul><ul><li><!ELEMENT Notice (#PCDATA)> </li></ul><ul><li>]> </li></ul><ul><li>< Invoice name =&quot; &Vendor; &quot;> </li></ul><ul><li>< Notice > &Disclaimer; </ Notice > </li></ul><ul><li>< Notice > And here is &char_A; </ Notice > </li></ul><ul><li></ Invoice > </li></ul>
  55. 55. Declaring Multiple Attributes <ul><li><?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> </li></ul><ul><li><!DOCTYPE PersonName [ </li></ul><ul><li><!ELEMENT PersonName EMPTY> </li></ul><ul><li><!ATTLIST PersonName </li></ul><ul><li>title CDATA #REQUIRED </li></ul><ul><li>first CDATA #REQUIRED </li></ul><ul><li>middle CDATA #REQUIRED </li></ul><ul><li>last CDATA #REQUIRED </li></ul><ul><li>> </li></ul><ul><li>]> </li></ul><ul><li>< PersonName title =&quot; Mr &quot; first =&quot; test &quot; middle =&quot; test &quot; last =&quot; test &quot;/> </li></ul>
  56. 56. Attribute Defaults <ul><li>We can specify if an attribute is mandatory </li></ul>Attribute Default Description #REQUIRED Must appear #IMPLIED Optional #FIXED Optional, but if appears, must have the default value Default value without any keyword Optional, but if appears, can have any value conforming to its data type
  57. 57. Attributes - #REQUIRED <ul><li>DTD </li></ul><ul><ul><li><!ATTLIST Employee Height CDATA #REQUIRED> </li></ul></ul><ul><li>Invalid XML </li></ul><ul><ul><li><Employee>Hiten</Employee> </li></ul></ul><ul><li>Valid XML </li></ul><ul><ul><li><Employee Height=“165”>Hiten</Employee> </li></ul></ul>
  58. 58. Attributes - #IMPLIED <ul><li>DTD </li></ul><ul><ul><li><!ATTLIST Employee Height CDATA #IMPLIED> </li></ul></ul><ul><li>Valid XML </li></ul><ul><ul><li><Employee>Hiten</Employee> </li></ul></ul><ul><li>Valid XML </li></ul><ul><ul><li><Employee Height=“165”>Hiten</Employee> </li></ul></ul>
  59. 59. Attributes - #FIXED <ul><li>DTD </li></ul><ul><ul><li><!ELEMENT Employee (#PCDATA)> </li></ul></ul><ul><ul><li><!ATTLIST Employee Height CDATA #FIXED “160”> </li></ul></ul><ul><li>Invalid XML </li></ul><ul><ul><li><Employee Height=“165”>Hiten</Employee> </li></ul></ul><ul><li>Valid XML </li></ul><ul><ul><li><Employee Height=“160”>Hiten</Employee> </li></ul></ul><ul><li>Valid XML </li></ul><ul><ul><li><Employee>Hiten</Employee> </li></ul></ul>
  60. 60. Attributes – Default Values <ul><li>DTD </li></ul><ul><ul><li><!ELEMENT Employee (#PCDATA)> </li></ul></ul><ul><ul><li><!ATTLIST Employee Height CDATA “160”> </li></ul></ul><ul><li>Valid XML </li></ul><ul><ul><li><Employee Height=“165”>Hiten</Employee> </li></ul></ul><ul><li>Valid XML </li></ul><ul><ul><li><Employee Height=“160”>Hiten</Employee> </li></ul></ul><ul><li>Valid XML </li></ul><ul><ul><li><Employee>Hiten</Employee> </li></ul></ul>
  61. 61. Important Attribute Types <ul><li>CDATA – Character data (Simple text string) </li></ul><ul><li>Enumerated values – One from a list of values </li></ul>
  62. 62. CDATA Attribute Type <ul><li>Strings of characters </li></ul><ul><li>Any attribute that does not have anything specified is defaulted to string </li></ul><ul><li>Example </li></ul><ul><ul><li><!ATTLIST book owner CDATA>  DTD </li></ul></ul><ul><ul><li><book owner=“British library”>  XML </li></ul></ul>
  63. 63. Enumerated Attribute Type <ul><li>Lists of possible vales </li></ul><ul><li>Example </li></ul><ul><ul><li><!ELEMENT fruit> </li></ul></ul><ul><ul><li><!ATTLIST fruit COLOR (RED | GREEN | PINK) “RED”> </li></ul></ul><ul><ul><ul><li>RED is the default value </li></ul></ul></ul>
  64. 64. Exercise <ul><li>Create a DTD for the following XML example: </li></ul><ul><li><?xml version = &quot;1.0&quot;?> </li></ul><ul><li><!DOCTYPE letter SYSTEM &quot;letter.dtd&quot;> </li></ul><ul><li><letter> </li></ul><ul><li><contact type = &quot;sender&quot;> </li></ul><ul><li><name>Nitin Pathak</name> </li></ul><ul><li><address>PO Box 1230</address> </li></ul><ul><li><address>Nigdi Post Office</address> </li></ul><ul><li><city>Pune</city> </li></ul><ul><li><pin>411001</pin> </li></ul><ul><li><state>Maharashtra</state> </li></ul><ul><li><flag gender = &quot;M&quot; /> </li></ul><ul><li></contact> </li></ul><ul><li><contact type = &quot;receiver&quot;> </li></ul><ul><li><name>Leena Mohan</name> </li></ul><ul><li><address>PO Box 6171</address> </li></ul><ul><li><address>Thane Post Office</address> </li></ul><ul><li><city>Thane</city> </li></ul><ul><li><pin>400602</pin> </li></ul><ul><li><state>Maharashtra</state> </li></ul><ul><li><flag gender = &quot;F&quot; /> </li></ul><ul><li></contact> </li></ul><ul><li><salutation>Dear madam:</salutation> </li></ul><ul><li><paragraph>We are pleased to inform you that you have been selected for the position of assistant programmer</paragraph> </li></ul><ul><li><paragraph>Please confirm your acceptance via a return letter</paragraph> </li></ul><ul><li><closing>Sincerely,</closing> </li></ul><ul><li><signature>Nitin Pathak - General Manager</signature> </li></ul><ul><li></letter> </li></ul>
  65. 65. Solution <ul><li><!ELEMENT letter (contact+, salutation, paragraph+, closing, signature)> </li></ul><ul><li><!ELEMENT contact (name, address+, city, pin, state, flag)> </li></ul><ul><li><!ELEMENT salutation (#PCDATA)> </li></ul><ul><li><!ELEMENT paragraph (#PCDATA)> </li></ul><ul><li><!ELEMENT closing (#PCDATA)> </li></ul><ul><li><!ELEMENT signature (#PCDATA)> </li></ul><ul><li><!ELEMENT name (#PCDATA)> </li></ul><ul><li><!ELEMENT address (#PCDATA)> </li></ul><ul><li><!ELEMENT city (#PCDATA)> </li></ul><ul><li><!ELEMENT pin (#PCDATA)> </li></ul><ul><li><!ELEMENT state (#PCDATA)> </li></ul><ul><li><!ELEMENT flag EMPTY> </li></ul><ul><li><!ATTLIST contact type CDATA #IMPLIED> </li></ul><ul><li><!ATTLIST flag gender (M | F) &quot;M&quot;> </li></ul>
  66. 66. Case Study – Book information <ul><li>LIBRARY.DTD file describes the document </li></ul>ISBN number ISBN Scale of 1-5 RATING Comments COMMENTS Fiction, Fantasy, Sci-fi, etc CATEGORY Hardback or paperback COVER Publisher of the book PUBLISHER Author of the book AUTHOR Describes a book’s title TITLE Identifies a book record BOOK Description Element
  67. 67. Case Study – Elements <ul><li><!ELEMENT book> </li></ul><ul><li><!ELEMENT title> </li></ul><ul><li><!ELEMENT author> </li></ul><ul><li><!ELEMENT publisher> </li></ul><ul><li><!ELEMENT cover EMPTY> </li></ul><ul><li><!ELEMENT category EMPTY> </li></ul><ul><li><!ELEMENT isbn> </li></ul><ul><li><!ELEMENT rating EMPTY> </li></ul><ul><li><!ELEMENT comments> </li></ul>
  68. 68. Case Study – Attributes <ul><li><!ATTLIST cover TYPE (HARDBACK | PAPERBACK) “PAPERBACK” #REQUIRED> </li></ul><ul><li><!ATTLIST category CLASS (FICTION | FANTASY | SCIFI | MYSTERY | HORROR | NONFICTION | HISTORICAL | BIOGRAPHY) “FICTION” #REQUIRED> </li></ul><ul><li><!ATTLIST rating NUMBER (1 | 2 | 3 | 4 | 5) “3” #REQUIRED> </li></ul>
  69. 69. Case Study – Modified Elements Declaration (Nesting) <ul><li><!ELEMENT book (title, author, publisher, cover, category, isbn, rating, comments?)> </li></ul><ul><li><!ELEMENT title (#PCDATA)> </li></ul><ul><li><!ELEMENT author (#PCDATA)> </li></ul><ul><li><!ELEMENT publisher (#PCDATA)> </li></ul><ul><li><!ELEMENT cover EMPTY> </li></ul><ul><li><!ELEMENT category EMPTY> </li></ul><ul><li><!ELEMENT isbn (#PCDATA)> </li></ul><ul><li><!ELEMENT rating EMPTY> </li></ul><ul><li><!ELEMENT comments (#PCDATA)> </li></ul>
  70. 70. Case Study – Let us put it all together <ul><li><?xml version=&quot;1.0&quot; standalone=&quot;yes&quot;?> </li></ul><ul><li><!DOCTYPE BOOK[ </li></ul><ul><li><!ELEMENT book (title, author, publisher, cover, category, isbn, rating, comments?)> </li></ul><ul><li><!ELEMENT title (#PCDATA)> </li></ul><ul><li><!ELEMENT author (#PCDATA)> </li></ul><ul><li><!ELEMENT publisher (#PCDATA)> </li></ul><ul><li><!ELEMENT cover EMPTY> </li></ul><ul><li><!ATTLIST cover type (HARDBACK | PAPERBACK) &quot;PAPERBACK&quot;> </li></ul><ul><li><!ELEMENT category EMPTY> </li></ul><ul><li><!ATTLIST category type (FICTION | FANTASY | SCIFI | MYSTERY | HORROR | NONFICTION | </li></ul><ul><li>HISTORICAL | BIOGRAPHY) &quot;FICTION&quot;> </li></ul><ul><li><!ELEMENT isbn (#PCDATA)> </li></ul><ul><li><!ELEMENT rating EMPTY> </li></ul><ul><li><!ATTLIST rating type (1 | 2 | 3 | 4 | 5) &quot;3&quot;> </li></ul><ul><li><!ELEMENT comments (#PCDATA)> </li></ul><ul><li>]> </li></ul><ul><li><book> </li></ul><ul><li><title>Computer Networks</title> </li></ul><ul><li><author>Andrew Tanenbaum</author> </li></ul><ul><li><publisher>Pearson Edcation</publisher> </li></ul><ul><li><cover type=&quot;PAPERBACK&quot;></cover> </li></ul><ul><li><category></category> </li></ul><ul><li><isbn>0-07-066789-X</isbn> </li></ul><ul><li><rating type=&quot;5&quot;></rating> </li></ul><ul><li><comments> Easily the best of the best!</comments> </li></ul><ul><li></book> </li></ul>
  71. 71. Thank you! Any Questions?

×