document type definitions (dtd) basic valid xml

34
DTD, by Dr. Khalil 1 Document Type Definitions (DTD) Basic Valid XML Dr. Awad Khalil Dr. Awad Khalil Computer Science Department Computer Science Department AUC AUC

Upload: harlan

Post on 05-Jan-2016

28 views

Category:

Documents


1 download

DESCRIPTION

Document Type Definitions (DTD) Basic Valid XML. Dr. Awad Khalil Computer Science Department AUC. Content. Why DTDs. How to write simple DTDs, and the benefits of using them. How to use DTDs. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Document Type Definitions (DTD) Basic Valid XML

DTD, by Dr. Khalil 1

Document Type Definitions(DTD)

Basic Valid XML

Dr. Awad KhalilDr. Awad Khalil

Computer Science DepartmentComputer Science Department

AUCAUC

Page 2: Document Type Definitions (DTD) Basic Valid XML

DTD, by Dr. Khalil 2

Content

Why DTDs.Why DTDs.

How to write simple DTDs, and the benefits How to write simple DTDs, and the benefits of using them.of using them.

How to use DTDs.How to use DTDs.

Page 3: Document Type Definitions (DTD) Basic Valid XML

DTD, by Dr. Khalil 3

Why Do We Need DTDs?

Well-formed XML data is XML data is guaranteed to use proper XML guaranteed to use proper XML syntax, and have the properly syntax, and have the properly nested (hierarchical) tree structure nested (hierarchical) tree structure that’s common to all XML data.that’s common to all XML data.

This may be sufficient information This may be sufficient information for relatively static internal for relatively static internal applications, particularly if the applications, particularly if the XML data is computer-generated XML data is computer-generated and computer-consumed.and computer-consumed.

The XML structural information The XML structural information and the logic to do this are usually and the logic to do this are usually hard-coded separately within the hard-coded separately within the sending and receiving sending and receiving applications, from a common applications, from a common specification. specification.

This can be an efficient, high-performance This can be an efficient, high-performance approach to handling XML data in certain approach to handling XML data in certain limited circumstances. For example, an limited circumstances. For example, an internal cooperate application might use internal cooperate application might use well-formed XML as a data transfer well-formed XML as a data transfer mechanism between two different database mechanism between two different database management systems (DBMSs). Using management systems (DBMSs). Using XML as a transfer syntax would decouple XML as a transfer syntax would decouple the two DBMSs from each other, so that the the two DBMSs from each other, so that the transfer could just as easily be directed to a transfer could just as easily be directed to a third DBMS without needing to create yet third DBMS without needing to create yet another point-to-point transfer program.another point-to-point transfer program.

However, when there’s no formal However, when there’s no formal description of the XML data, it’s difficult to description of the XML data, it’s difficult to describe or modify the structure of that data, describe or modify the structure of that data, since it’s structure and content constraints since it’s structure and content constraints are buried within the application code. Any are buried within the application code. Any changes to the data structure must be made changes to the data structure must be made simultaneously in both the sending and simultaneously in both the sending and receiving applications, and in the separate receiving applications, and in the separate technical documentation as well.technical documentation as well.

Page 4: Document Type Definitions (DTD) Basic Valid XML

DTD, by Dr. Khalil 4

XML Application Requirements

In addition to ensuring that XML data is simply In addition to ensuring that XML data is simply well-formed, most , most XML applications will also need to:XML applications will also need to: Describe document structure, preferably in a rigorous and formal Describe document structure, preferably in a rigorous and formal

manner.manner.

Communicate document structure to other applications and people.Communicate document structure to other applications and people.

Check that the required elements are present – and prompt the author Check that the required elements are present – and prompt the author for their inclusion if they aren’t.for their inclusion if they aren’t.

Check that no disallowed elements are included – and prevent the Check that no disallowed elements are included – and prevent the author from using them.author from using them.

Enforce element content, tree structure, and element attribute values.Enforce element content, tree structure, and element attribute values.

Provide default values for unspecified attribute values.Provide default values for unspecified attribute values.

Use standard document formats and data structures.Use standard document formats and data structures.

Page 5: Document Type Definitions (DTD) Basic Valid XML

DTD, by Dr. Khalil 5

One Solution – The Document Type Definitions

A solution to these requirements is based on separating the XML data A solution to these requirements is based on separating the XML data description from individual applications which allows all cooperating description from individual applications which allows all cooperating applications to share a single description of the data. This description applications to share a single description of the data. This description of data is known as the of data is known as the XML vocabulary..

A group of XML documents that share a common XML vocabulary is A group of XML documents that share a common XML vocabulary is known as a known as a document type, and each individual document that , and each individual document that conforms to a document type is a conforms to a document type is a document instance..

The XML 1.0 specification provides a standardized means of The XML 1.0 specification provides a standardized means of describing XML document types: the describing XML document types: the Document Type Definitions (DTD).

DTDs are XML documents which can either be incorporated within are XML documents which can either be incorporated within the XML document containing the data, or exist as a separate the XML document containing the data, or exist as a separate document. They define the rules that set out how a document should document. They define the rules that set out how a document should be structured, what elements should be included, what kind of data be structured, what elements should be included, what kind of data may be included and what default values to usemay be included and what default values to use..

Page 6: Document Type Definitions (DTD) Basic Valid XML

DTD, by Dr. Khalil 6

Valid XML Well-formed XML documents are those that comply with the basic syntax and XML documents are those that comply with the basic syntax and

structural rules of the XML 1.0 specifications. structural rules of the XML 1.0 specifications. Valid XML documents are well-formed documents that also comply with syntax, XML documents are well-formed documents that also comply with syntax,

structural, and other rules as defined in a DTD.structural, and other rules as defined in a DTD. Multiple documents and applications can share DTDs. Having a central Multiple documents and applications can share DTDs. Having a central

description of the XML data and a standardized validation method lets us move description of the XML data and a standardized validation method lets us move both data description and validation code out of numerous individual both data description and validation code out of numerous individual applications.applications.

The data description code becomes the DTD, and the validation code is already The data description code becomes the DTD, and the validation code is already present (and optimized) in the validating XML parser. This greatly simplifies our present (and optimized) in the validating XML parser. This greatly simplifies our application code, and thus improves both performance and reliability.application code, and thus improves both performance and reliability.

Valid XML is also preferable to simple well-formed XML for most document-Valid XML is also preferable to simple well-formed XML for most document-oriented data.Being able to define such rules will become more important as we oriented data.Being able to define such rules will become more important as we exchange , process, and display XML in a wider environment, such as in a B2B exchange , process, and display XML in a wider environment, such as in a B2B or e-commerce scenario.or e-commerce scenario.

Using DTDs will allow us not only to determine that XML documents follow the Using DTDs will allow us not only to determine that XML documents follow the syntax rules of the XML specification, but also that they follow our own rules syntax rules of the XML specification, but also that they follow our own rules regarding content and structure.regarding content and structure.

Page 7: Document Type Definitions (DTD) Basic Valid XML

DTD, by Dr. Khalil 7

Validating Parsers To ensure that an XML To ensure that an XML

document is not just document is not just well-formed, but valid, well-formed, but valid, as well:as well:

fxp http://www.http://www.informatikinformatik..uniuni-tier.de/~-tier.de/~neumannneumann//fxpfxp

Java Project X Tr2http://developer.java.sun.com/developer/products/http://developer.java.sun.com/developer/products/

xmlxml

MSXML “preview”http://msdn.microsoft.com/downloads/http://msdn.microsoft.com/downloads/

webtechnology/xml/msxml.aspwebtechnology/xml/msxml.asp

rxphttp://www.cogsci.ed.ac.uk/~richard/rxp.htmlhttp://www.cogsci.ed.ac.uk/~richard/rxp.html

STG Validatorhttp://www.stg.brown.edu/service/xmlvalidhttp://www.stg.brown.edu/service/xmlvalid

XJParserhttp://xdev.datachannel.com/downloads/xjparserhttp://xdev.datachannel.com/downloads/xjparser

XML4C / XML4Jhttp://www.alphaworks.ibm.com/formula/xmlhttp://www.alphaworks.ibm.com/formula/xml

XML for Java v2http://technet.oracle.com/tech/xml/parser_java2http://technet.oracle.com/tech/xml/parser_java2

Xerces-C++http://xml.apache.org/xerces-c/index.htmlhttp://xml.apache.org/xerces-c/index.html

Xerces-Jhttp://xml.apache.org/xerces-j/index.htmlhttp://xml.apache.org/xerces-j/index.html

Page 8: Document Type Definitions (DTD) Basic Valid XML

DTD, by Dr. Khalil 8

Sharing DTDs

Shared DTDs are a very powerful aspect of XMLShared DTDs are a very powerful aspect of XML

Shared DTDs are the basis for many XML vocabularies. Using a shared Shared DTDs are the basis for many XML vocabularies. Using a shared data description greatly simplifies the process of creating and data description greatly simplifies the process of creating and maintaining an XML vocabulary. It can also make any application code maintaining an XML vocabulary. It can also make any application code simpler, and thus more reliable and easier to maintain.simpler, and thus more reliable and easier to maintain.

With a shared DTD, there’s only one place where we need to make With a shared DTD, there’s only one place where we need to make modifications to the vocabulary’s data description, instead of three (the modifications to the vocabulary’s data description, instead of three (the specification, sending application, and receiving application).specification, sending application, and receiving application).

Having standardized XML vocabularies for common things (such as Having standardized XML vocabularies for common things (such as bibliographic information, for example) allows developers to reuse bibliographic information, for example) allows developers to reuse existing DTDs, saving the cost of developing custom DTDs.existing DTDs, saving the cost of developing custom DTDs.

Custom DTDs isolate their users and applications from others that might Custom DTDs isolate their users and applications from others that might otherwise be able to share commonly formatted documents and data.otherwise be able to share commonly formatted documents and data.

Shared DTDs are the foundation of XML data interchange and reuse.Shared DTDs are the foundation of XML data interchange and reuse.

Page 9: Document Type Definitions (DTD) Basic Valid XML

DTD, by Dr. Khalil 9

An Example – A Book Catalog

The BookCatalog DTD is an example The BookCatalog DTD is an example of a shared XML vocabulary that can of a shared XML vocabulary that can be used by a publisher to communicate be used by a publisher to communicate with its distributors, retailers, and other with its distributors, retailers, and other interested parties.interested parties.

An XML-aware browser will allow An XML-aware browser will allow users to learn about future publications, users to learn about future publications, read reviews of existing books, or even read reviews of existing books, or even order books directly from the catalog.order books directly from the catalog.

Why XML? A single common standard syntaxA single common standard syntax Easily shared vocabulariesEasily shared vocabularies Standard methods and tools for Standard methods and tools for

transforming datatransforming data Utilization of existing Internet Utilization of existing Internet

protocols such as HTTPprotocols such as HTTP

Why DTDs? Provide a formal and complete Provide a formal and complete

definition of an XML vocabularydefinition of an XML vocabulary Are sharable descriptions of the Are sharable descriptions of the

structure of an XML documentstructure of an XML document Are a way to validate specific Are a way to validate specific

instances of XML documents and instances of XML documents and constrain their contentconstrain their content

Are restricted to one DTD per Are restricted to one DTD per document instancedocument instance

Other Alternatives to DTDs XML-data XML-Data-Reduced XML Schemas – are well on their – are well on their

way to becoming a formal W3C way to becoming a formal W3C recommendationrecommendation

Page 10: Document Type Definitions (DTD) Basic Valid XML

DTD, by Dr. Khalil 10

The Basic BookCatalog Data Model Before we can create a DTD, we first need to develop a data model that Before we can create a DTD, we first need to develop a data model that

describes the BookCatalog vocabulary and its grammer:describes the BookCatalog vocabulary and its grammer: Catalog – – A document header describing the rest of the documentA document header describing the rest of the document Publisher – – Vendor of Books, employer of AuthorsVendor of Books, employer of Authors Author – – Creator of Books, employee of PublisherCreator of Books, employee of Publisher Book – – Creation of Author and PublisherCreation of Author and Publisher

Page 11: Document Type Definitions (DTD) Basic Valid XML

DTD, by Dr. Khalil 11

Basic BookCatalog Document (BookCatalogBasic.xml)<?xml version="1.0" encoding="UTF-8" standalone="yes"?><?xml version="1.0" encoding="UTF-8" standalone="yes"?><BookCatalog><BookCatalog> <Catalog><Catalog> <CatalogTitle>The Wrox BookCatalog ('Basic' version)</CatalogTitle><CatalogTitle>The Wrox BookCatalog ('Basic' version)</CatalogTitle> <CatalogDate>2000-05-23</CatalogDate><CatalogDate>2000-05-23</CatalogDate> </Catalog></Catalog> <Publisher><Publisher> <CorpName>Wrox Press Ltd.</CorpName><CorpName>Wrox Press Ltd.</CorpName> <Website>www.wrox.com</Website><Website>www.wrox.com</Website> <Address><Address> <Street>Arden House</Street><Street>Arden House</Street> <Street>1102 Warwick Road</Street><Street>1102 Warwick Road</Street> <Street>Acocks Green</Street><Street>Acocks Green</Street> <City>Birmingham</City><City>Birmingham</City> <Region>England</Region><Region>England</Region> <PostalCode>B27 6BH</PostalCode><PostalCode>B27 6BH</PostalCode> <Country>UK</Country><Country>UK</Country> </Address></Address> </Publisher></Publisher> <Publisher><Publisher> <CorpName>Wrox Press Inc.</CorpName><CorpName>Wrox Press Inc.</CorpName> <Website>www.wrox.com</Website><Website>www.wrox.com</Website> <Address><Address> <Street>29 S LaSalle St, Suite 520</Street><Street>29 S LaSalle St, Suite 520</Street> <City>Chicago</City><City>Chicago</City> <Region>IL</Region><Region>IL</Region> <Country>USA</Country><Country>USA</Country> <PostalCode>60603</PostalCode><PostalCode>60603</PostalCode> </Address></Address> </Publisher></Publisher>

<Book><Book> <ISBN>1-861003-11-0</ISBN><ISBN>1-861003-11-0</ISBN> <Title>Professional XML</Title><Title>Professional XML</Title> <Author>Didier Martin</Author><Author>Didier Martin</Author> <Author>Mark Birbeck</Author><Author>Mark Birbeck</Author> <Author>Michael Kay</Author><Author>Michael Kay</Author> <Author>Brian Loesgen</Author><Author>Brian Loesgen</Author> <Author>Jon Pinnock</Author><Author>Jon Pinnock</Author> <Author>Steven Livingstone</Author><Author>Steven Livingstone</Author> <Author>Peter Stark</Author><Author>Peter Stark</Author> <Author>Kevin Williams</Author><Author>Kevin Williams</Author> <Author>Richard Anderson</Author><Author>Richard Anderson</Author> <Author>Stephen Mohr</Author><Author>Stephen Mohr</Author> <Author>David Baliles</Author><Author>David Baliles</Author> <Author>Bruce Peat</Author><Author>Bruce Peat</Author> <Author>Nikola Ozu</Author><Author>Nikola Ozu</Author> <Editor>Jon Duckett</Editor><Editor>Jon Duckett</Editor> <Editor>Peter Jones</Editor><Editor>Peter Jones</Editor> <Editor>Karli Watson</Editor><Editor>Karli Watson</Editor> <Abstract>The complete practical encyclopedia for XML <Abstract>The complete practical encyclopedia for XML

today.</Abstract>today.</Abstract> <Pages>1169</Pages><Pages>1169</Pages> <Price>$49.99</Price><Price>$49.99</Price> <Subjects><Subjects> <Subject1>Internet</Subject1><Subject1>Internet</Subject1> <Subject2>Internet Programming</Subject2><Subject2>Internet Programming</Subject2> <Subject3>XML</Subject3><Subject3>XML</Subject3> </Subjects></Subjects> </Book></Book></BookCatalog></BookCatalog>

Page 12: Document Type Definitions (DTD) Basic Valid XML

DTD, by Dr. Khalil 12

Internal versus External DTDs

Only one DTD can be associated Only one DTD can be associated with a given XML document.with a given XML document.

The DTD may be divided into The DTD may be divided into two parts:two parts: The The internal subset – which – which

is the part of DTD included is the part of DTD included within the documentwithin the document

The The external subset – – which is the set of which is the set of declarations that are located declarations that are located in a separate document in a separate document (might be a database record (might be a database record or a or a .dtd file). file).

There’s no requirement that a DTD uses a There’s no requirement that a DTD uses a particular subset.particular subset.

A DTD might be contained entirely within A DTD might be contained entirely within the document (an internal subset), with no the document (an internal subset), with no external subset, or a document may external subset, or a document may simply refer to an external subset and simply refer to an external subset and contain no DTD declarations of its own.contain no DTD declarations of its own.

So, there are three possible forms of DTD:So, there are three possible forms of DTD: An internal subset DTDAn internal subset DTD An external subset DTDAn external subset DTD A combined DTD, using both the A combined DTD, using both the

internal and external subsetsinternal and external subsets

DTD declarations in the internal subset DTD declarations in the internal subset have priority over those in the external have priority over those in the external subset.subset.

Page 13: Document Type Definitions (DTD) Basic Valid XML

DTD, by Dr. Khalil 13

Associating a DTD with an XML document (DOCTYPE)

Each XML document can be Each XML document can be associated with one, and only one, associated with one, and only one, DTD using a single DTD using a single DOCTYPE declaration, via the following basic declaration, via the following basic structure:structure:

<!DOCTYPE document _element source location1 location2 [ internal subset of DTD ]>

Document_element – is the name of is the name of the document element. This name the document element. This name is required and connects the DTD is required and connects the DTD to the entire element tree:to the entire element tree:

<?xml version=“1.0” encoding=“UTF-8” standalone=“yes”>

<!DOCTYPE BookCatalog … >…<BookCatalog>…</BookCatalog>

DTDs are always associated with the DTDs are always associated with the document elementdocument element..

source – used to associate an external used to associate an external subset with a document, (subset with a document, (SYSTEM or or PUBLIC). In the following example, the ). In the following example, the parser will attempt to retrieve the DTD parser will attempt to retrieve the DTD from the specified URL AT Wrox’s from the specified URL AT Wrox’s website: website:

<!DOCTYPE BookCatalog SYSTEM “http://www.wrox.com/DTDs/BookCatalog.dtd>

A document residing on the same web server A document residing on the same web server as the DTD could also access the DTD as the DTD could also access the DTD directly:directly:

<!DOCTYPE BookCatalog SYSTEM “file://DTDs/BookCatalog.dtd” >

Using the Using the PUBLIC keyword allows keyword allows a non-specific reference to the DTD a non-specific reference to the DTD via a URI:via a URI:

<!DOCTYPE BookCatalog PUBLIC “PublishingConsorium/BookCatalog” >

<!DOCTYPE BookCatalog PUBLIC “PublishingConsorium/BookCatalog”“http://www.wrox.com/DTDs/BookCatalog.dtd>

Page 14: Document Type Definitions (DTD) Basic Valid XML

DTD, by Dr. Khalil 14

An Example – DOCTYPE Declaration (Linking a DTD to a Document)

1.1. Let’s create a simple DTD and Let’s create a simple DTD and demonstrate linking it to two demonstrate linking it to two different document instances. Let’s different document instances. Let’s stipulate that this DTD requires a stipulate that this DTD requires a conforming document to have exactly conforming document to have exactly three empty elements, named X, Y, three empty elements, named X, Y, Z, with the elements appearing in Z, with the elements appearing in XYZ order. We create the following XYZ order. We create the following BookCatalogTrivial.dtd:BookCatalogTrivial.dtd:

<!ELEMENT BookCatalog (X, Y, Z) >

<!ELEMENT X EMPTY >

<!ELEMENT Y EMPTY >

<!ELEMENT Z EMPTY >

2.2. Now, we create two example Now, we create two example documents:documents:

BookCatalogTrivial.xml:BookCatalogTrivial.xml:

<?xml version=“1.0” ?>

<!DOCTYPE BookCatalog SYSTEM “BookCatalogTrivial.dtd” >

<BookCatalog>

<X />

<Y />

<Z />

</BokkCatalog>

BookCatalogAbsentDTD.xml:BookCatalogAbsentDTD.xml:

<?xml version=“1.0” ?>

<!DOCTYPE BookCatalog SYSTEM “MissingDTD.dtd” >

<BookCatalog>

<X />

<Y />

<Z />

</BokkCatalog>

Page 15: Document Type Definitions (DTD) Basic Valid XML

DTD, by Dr. Khalil 15

Basic DTD Markup

DTD declarations are delimited with the XML tag delimiters <“<“ and “>”).DTD declarations are delimited with the XML tag delimiters <“<“ and “>”). All DTD declarations are indicated by the use of the exclamation mark (“!”) All DTD declarations are indicated by the use of the exclamation mark (“!”)

followed by a keyword, and its specific parameters:followed by a keyword, and its specific parameters:<!Keyword parameter1 parameter2 .. parameterN > There are four basic keywords used in DTD declarations:There are four basic keywords used in DTD declarations:

ELEMENT – – Declares an XML element type name ant its permissible Declares an XML element type name ant its permissible sub-elements (“children”).sub-elements (“children”).

ATTLIST – – Declares XML element attribute names, plus permissible Declares XML element attribute names, plus permissible and/or default attribute values.and/or default attribute values.

ENTITY – – Declares special character references, text macros (much like a Declares special character references, text macros (much like a C/C++ #define statement), and other repetitive content from external sources C/C++ #define statement), and other repetitive content from external sources (like a C/C++ #include).(like a C/C++ #include).

NOTATION – – Declares external non-XML content (for example, binary Declares external non-XML content (for example, binary image data) and the external application that handles that content.image data) and the external application that handles that content.

Page 16: Document Type Definitions (DTD) Basic Valid XML

DTD, by Dr. Khalil 16

Element Type (ELEMENT) Declarations Elements are described using the Elements are described using the element type

declaration, which can have one of two , which can have one of two different forms:different forms:

<!ELEMENT name category ><!ELEMENT name (content_model) > The The category ((content categorycontent category) and ) and

content_model ( (content modelcontent model) parameters ) parameters describe what kind of content (if any) may describe what kind of content (if any) may appear within elements of the given name.appear within elements of the given name.

There are five categories of element content:There are five categories of element content: ANY – – Elements type may contain any Elements type may contain any

well-formed XML data.well-formed XML data. EMPTY – – Element type may not contain Element type may not contain

any text or child elements – only element any text or child elements – only element attributes are permitted.attributes are permitted.

element – – Element type contains only Element type contains only child elements – no additional text is child elements – no additional text is permitted within the element type.permitted within the element type.

mixed – – Element type may contain text Element type may contain text and/or child elements.and/or child elements.

PCDATA – – Element type may contain text Element type may contain text (character data) only.(character data) only.

Examples:Examples:<!ELEMENT AnythingGoesInHere Any >

------------------------------------------------------

<!ELEMENT BR EMPTY >

<!ELEMENT EOF EMPTY >

<!ELEMENT PrserConfig EMPTY >

<!ELEMENT BrowserConfig EMPTY >

--------------------<ParserConfig valditate=“yes”

externalentity=“no” keepcomments=“no” />

<BrowserConfig showags=“yes” showcomments=“no” showPIs=“no” />

Page 17: Document Type Definitions (DTD) Basic Valid XML

DTD, by Dr. Khalil 17

Content Models Content models are used to describe Content models are used to describe

the structure and content of a given the structure and content of a given element type. This content may be:element type. This content may be: Character data (PCDATA)Character data (PCDATA) One or more child element types One or more child element types

(element-only content)(element-only content) A combination of the two (mixed A combination of the two (mixed

content)content)<!ELEMENT name ( ..content_model.. ) > The key difference between The key difference between element element

contentcontent and and mixed contentmixed content is the use is the use of the of the #PCDATA keyword. If present, keyword. If present, the content model is either the content model is either mixedmixed or or PCDATAPCDATA. The absence of this . The absence of this keyword indicates keyword indicates element-onlyelement-only content.content.

Examples:Examples:<name> Character data can include entity references (e.g. &amp;

or &lt;).</name>

<!ELEMENT name (#PCDATA) >-------------------------------------------------------<name> <a_child_element>Some element content

..</a_child_element> <another_child_element>...some other childish

content..</another_child_element> <a_third_element>...yet another child’s

content..</a_third_element></name>

<!ELEMENT name (a_child_element, another_child_element, a_third_element) >

Child elements may be constrained to appear in a Child elements may be constrained to appear in a specific sequence (specific sequence (sequence listsequence list).).

-------------------------------------------------------

<!ELEMENT name (#PCDATA, a_child_element, another_child_element, a_third_element) >

In a mixed content model, child elements are In a mixed content model, child elements are constrained to character data plus a simple list of constrained to character data plus a simple list of valid child element types, without any sequence or valid child element types, without any sequence or choice specifications.choice specifications.

Page 18: Document Type Definitions (DTD) Basic Valid XML

DTD, by Dr. Khalil 18

Content Models (Cont’d)

Consider the following DTD:Consider the following DTD:

<!ELEMENT PersonName (Title, FirstName, MiddleName, LastName, Suffix) >

<!ELEMENT Title (#PCDATA) ><!ELEMENT FirstName (#PCDATA) ><!ELEMENT MiddleName (#PCDATA) ><!ELEMENT LastName (#PCDATA) ><!ELEMENT Suffix (#PCDATA) >

A document instance that conforms to A document instance that conforms to this declaration:this declaration:

<PersonName> <Title>Mr</Title> <FirstName>John</FirstName> <MiddleName>Q</MiddleName> <LastName>Public</LastName> <Suffix></Suffix></PersonName>

We could use choice of specific empty We could use choice of specific empty elements to replace the two text-elements to replace the two text-containing elements:containing elements:

<!ELEMENT PersonName ( (Mr | Ms | Dr | Rev), FirstName, MiddleName, LastName, (Jr | Sr | III) ) >

<!ELEMENT Mr (#PCDATA) ><!ELEMENT Ms (#PCDATA) ><!ELEMENT Dr (#PCDATA) ><!ELEMENT Rev (#PCDATA) >

<!ELEMENT FirstName (#PCDATA) ><!ELEMENT MiddleName (#PCDATA) ><!ELEMENT LastName (#PCDATA) >

<!ELEMENT Jr EMPTY ><!ELEMENT Sr EMPTY ><!ELEMENT III EMPTY >

The conforming document instance would The conforming document instance would now becomeext-containing elements:now becomeext-containing elements:

<PersonName> <Mr/> <FirstName>John</FirstName> <MiddleName>Q</MiddleName> <LastName>Public</LastName> <Jr/></PersonName>

Page 19: Document Type Definitions (DTD) Basic Valid XML

DTD, by Dr. Khalil 19

Content Models (Cont’d)

Cardinality operators – define – define how many child elements may how many child elements may appear in a content model:appear in a content model: (none) – – The absence of a The absence of a

cardinality operator character cardinality operator character indicates that one, and only indicates that one, and only one, instance of the child one, instance of the child element is allowed (required).element is allowed (required).

? – Zero or one child element – Zero or one child element (optional singular element).(optional singular element).

* - Zero or more child elements - Zero or more child elements (optional elements).(optional elements).

+ - One or more child elements - One or more child elements (required elements)(required elements)

Consider the following DTDs:Consider the following DTDs:<!ELEMENT PersonName ( (Mr | Ms | Dr | Rev) ?, FirstName, MiddleName*,

LastName, (Jr | Sr | III) ?) >

<!ELEMENT PersonName ( SingleName | ( (Mr | Ms | Dr | Rev) ?, FirstName, MiddleName*, LastName, (Jr | Sr | III) ?) ) >

Here are some conforming instances:Here are some conforming instances:<PersonName>

<Mr />

<FirstName>John</FirstName>

<MiddleName>Q</MiddleName>

<MiddleName>P</MiddleName>

<LastName>Public</LastName>

<Jr />

</PersonName>

<PersonName>

<FirstName>Jane</FirstName>

<LastName>Doe</LastName>

</PersonName>

<PersonName>

<SingleName>Madonna</SingleName>

</PersonName>

Page 20: Document Type Definitions (DTD) Basic Valid XML

DTD, by Dr. Khalil 20

Content Models (Cont’d)

Consider the following DTDs:Consider the following DTDs:<!ELEMENT PersonName ( SingleName | ( (Mr | Ms | Dr |

Rev) ?, FirstName, MiddleName*, LastName, (Jr | Sr | III) ?) ) >

Here are some non-conforming Here are some non-conforming (“not valid”) instances:(“not valid”) instances:

<PersonName>

<LastName>Smith</LastName>

<FirstName>Bob</FirstName>

</PersonName>

<PersonName>

<Miss />

<FirstName>Jane</FirstName>

<LastName>Doe</LastName>

</PersonName>

<PersonName>

<SingleName>Madonna</SingleName>

<SingleName>Cicone</SingleName>

</PersonName>

Page 21: Document Type Definitions (DTD) Basic Valid XML

DTD, by Dr. Khalil 21

An Example – ELEMENT Declaration Consider the following Consider the following

BookCatalogBasic.dtd:BookCatalogBasic.dtd:<!-- ======= The BookCatalog DTD ('Basic'

version) ======= -->

<!ELEMENT BookCatalog (Catalog, Publisher+, Book*) >

<!-- <Catalog> section -->

<!ELEMENT Catalog (CatalogTitle, CatalogDate) >

<!ELEMENT CatalogTitle (#PCDATA) ><!ELEMENT CatalogDate (#PCDATA) >

<!-- <Publisher> section -->

<!ELEMENT Publisher (CorpName, Website*, Address) >

<!ELEMENT CorpName (#PCDATA) ><!ELEMENT Website (#PCDATA) >

<!ELEMENT Address (Street*, City, Region?, PostalCode?, Country) >

<!ELEMENT Street (#PCDATA) ><!ELEMENT City (#PCDATA) ><!ELEMENT Region (#PCDATA) ><!ELEMENT PostalCode (#PCDATA) ><!ELEMENT Country (#PCDATA) >

<!-- <Book> and <Author> section -->

<!ELEMENT Book (ISBN, Title, Author+, Editor*, Abstract?, Pages, Price, Subjects?) >

<!ELEMENT ISBN (#PCDATA) ><!ELEMENT Title (#PCDATA) ><!ELEMENT Author (#PCDATA) > <!-- Just a

placeholder for now --><!ELEMENT Editor (#PCDATA) > <!-- Ditto --><!ELEMENT Pages (#PCDATA) ><!ELEMENT Price (#PCDATA) >

<!ELEMENT Subjects (Subject, Subject?, Subject?) ><!ELEMENT Subject (#PCDATA) >

<!-- ======= END of BookCatalog DTD ======= -->

Page 22: Document Type Definitions (DTD) Basic Valid XML

DTD, by Dr. Khalil 22

An Example – ELEMENT Declaration (BookCatalogBasic.xml)

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><?xml version="1.0" encoding="UTF-8" standalone="yes"?><!DOCTYPE BookCatalog SYSTEM <!DOCTYPE BookCatalog SYSTEM

“BookCatalogBasic.dtd” >“BookCatalogBasic.dtd” ><BookCatalog><BookCatalog> <Catalog><Catalog> <CatalogTitle>The Wrox BookCatalog ('Basic' <CatalogTitle>The Wrox BookCatalog ('Basic'

version)</CatalogTitle>version)</CatalogTitle> <CatalogDate>2000-05-23</CatalogDate> </Catalog><CatalogDate>2000-05-23</CatalogDate> </Catalog> <Publisher><Publisher> <CorpName>Wrox Press Ltd.</CorpName><CorpName>Wrox Press Ltd.</CorpName> <Website>www.wrox.com</Website><Website>www.wrox.com</Website> <Address><Address> <Street>Arden House</Street><Street>Arden House</Street> <Street>1102 Warwick Road</Street><Street>1102 Warwick Road</Street> <Street>Acocks Green</Street><Street>Acocks Green</Street> <City>Birmingham</City><City>Birmingham</City> <Region>England</Region><Region>England</Region> <PostalCode>B27 6BH</PostalCode><PostalCode>B27 6BH</PostalCode> <Country>UK</Country><Country>UK</Country> </Address> </Publisher></Address> </Publisher> <Publisher><Publisher> <CorpName>Wrox Press Inc.</CorpName><CorpName>Wrox Press Inc.</CorpName> <Website>www.wrox.com</Website><Website>www.wrox.com</Website> <Address><Address> <Street>29 S LaSalle St, Suite 520</Street><Street>29 S LaSalle St, Suite 520</Street> <City>Chicago</City><City>Chicago</City> <Region>IL</Region><Region>IL</Region> <Country>USA</Country><Country>USA</Country> <PostalCode>60603</PostalCode><PostalCode>60603</PostalCode> </Address> </Publisher></Address> </Publisher>

<Book><Book> <ISBN>1-861003-11-0</ISBN><ISBN>1-861003-11-0</ISBN> <Title>Professional XML</Title><Title>Professional XML</Title> <Author>Didier Martin</Author><Author>Didier Martin</Author> <Author>Mark Birbeck</Author><Author>Mark Birbeck</Author> <Author>Michael Kay</Author><Author>Michael Kay</Author> <Author>Brian Loesgen</Author><Author>Brian Loesgen</Author> <Author>Jon Pinnock</Author><Author>Jon Pinnock</Author> <Author>Steven Livingstone</Author><Author>Steven Livingstone</Author> <Author>Peter Stark</Author><Author>Peter Stark</Author> <Author>Kevin Williams</Author><Author>Kevin Williams</Author> <Author>Richard Anderson</Author><Author>Richard Anderson</Author> <Author>Stephen Mohr</Author><Author>Stephen Mohr</Author> <Author>David Baliles</Author><Author>David Baliles</Author> <Author>Bruce Peat</Author><Author>Bruce Peat</Author> <Author>Nikola Ozu</Author><Author>Nikola Ozu</Author> <Editor>Jon Duckett</Editor><Editor>Jon Duckett</Editor> <Editor>Peter Jones</Editor><Editor>Peter Jones</Editor> <Editor>Karli Watson</Editor><Editor>Karli Watson</Editor> <Abstract>The complete practical encyclopedia for XML <Abstract>The complete practical encyclopedia for XML

today.</Abstract>today.</Abstract> <Pages>1169</Pages><Pages>1169</Pages> <Price>$49.99</Price><Price>$49.99</Price> <Subjects><Subjects> <Subject1>Internet</Subject1><Subject1>Internet</Subject1> <Subject2>Internet Programming</Subject2><Subject2>Internet Programming</Subject2> <Subject3>XML</Subject3><Subject3>XML</Subject3> </Subjects></Subjects> </Book></Book></BookCatalog></BookCatalog>

Page 23: Document Type Definitions (DTD) Basic Valid XML

DTD, by Dr. Khalil 23

Attribute (ATTLIST) Declarations

Element attributes are described Element attributes are described using the attribute-list declaration using the attribute-list declaration ((ATTLIST), with the standard ), with the standard syntax:syntax:

<!ATTLIST elementName attrName attrType attrDefault defaultValue >

Example:Example:<!ELEMENT Book EMPTY >

<!ATTLIST Book

isbn CDATA #REQUIRED

title CDATA #REQUIRED

author CDATA #REQUIRED

pages CDATA #IMPLIED

price CDATA #IMPLIED >

Attribute Types CDATA – Character data (simple data – Character data (simple data

string).string). Enumerated value(s) – Attribute value must Enumerated value(s) – Attribute value must

be one of a series that is explicitly defined in be one of a series that is explicitly defined in the DTD.the DTD.

ID – Attribute value is the unique identifier – Attribute value is the unique identifier for this element instance.for this element instance.

IDREF – A reference to the element with an – A reference to the element with an ID attribute that has the same value as that of ID attribute that has the same value as that of the IDREF.the IDREF.

IDREFS – A list of IDREFs delimited by – A list of IDREFs delimited by white space.white space.

NMTOKEN – A – A name tokenname token (a text string (a text string that conforms to the XML name rules, that conforms to the XML name rules, except that the first character of the name except that the first character of the name may be any valid name character).may be any valid name character).

ENTITY – The name of a pre-defined – The name of a pre-defined entityentity..

ENTITIES – A list of ENTITY names – A list of ENTITY names delimited by white space.delimited by white space.

NOTATION – Attribute value must be a – Attribute value must be a notation typenotation type that is explicitly declared that is explicitly declared elsewhere in the DTD.elsewhere in the DTD.

Page 24: Document Type Definitions (DTD) Basic Valid XML

DTD, by Dr. Khalil 24

ATTLIST - Examples A DTD:A DTD:<!ATTLIST AnElement its_attr CDATA #REQUIRED > A conforming instance:A conforming instance:<AnElement its_attr=“some text string”>

…</AnElement>

----------------------------------------- A DTD:A DTD:<!ELEMENT Person (PersonName, FirstName,

MiddleName, LastName, CorpName?, Email*, Biography?) >

<!ATTLIST Person perID ID #REQUIRED >

A conforming instance:A conforming instance: <Person perID=“JHN_Q_PBLC” > <PersonName honorific=“Mr” suffix=“Jr” > <FirstName>John</FirstName> <MiddleName>Q</MiddleName> <LastName>Public</LastName> </PersonName> <CorpName>Acme XML Writers</CorpName> <Email>[email protected]</Email> <Biography>John, Jr. is a swell fellow, son of John,

Sr.</Biography></Person>

A DTD:A DTD:<!ELEMENT PersonName (FirstName,

MiddleName, LastName) >

<!ATTLIST PersonName

honorific (Mr | Ms | Dr | Rev) #IMPLIED

suffix (Jr | Sr | III) #IMPLIED >

<!ELEMENT FirstName (#PCDATA) >

<!ELEMENT MiddleName (#PCDATA) >

<!ELEMENT LastName (#PCDATA) >

<!ELEMENT Suffix (#PCDATA) >

A conforming instance:A conforming instance:<PersonName honorific=“Mr” suffix=“Jr” >

<FirstName>John</FirstName>

<MiddleName>Q</MiddleName>

<LastName>Public</LastName>

</PersonName>

Page 25: Document Type Definitions (DTD) Basic Valid XML

DTD, by Dr. Khalil 25

ATTLIST (Cont’d)

The value of an ID attribute must The value of an ID attribute must be a legal XML name, unique be a legal XML name, unique within a document, and use the within a document, and use the #IMPLIED or #REQUIRED #IMPLIED or #REQUIRED default values. There may only be default values. There may only be on ID attribute for each element on ID attribute for each element type.type.

The value of an IDREF attribute The value of an IDREF attribute must be a legal XML name, and must be a legal XML name, and must match the value of an ID must match the value of an ID attribute within the same document. attribute within the same document. Multiple IDREFs to the same ID Multiple IDREFs to the same ID are permitted.are permitted.

Examples:Examples:<!ATTLIST Book author IDREF #REQUIRED >

<Book author=“JHN_Q_PBLC” .. >

------------------------------------------------------------

<!ATTLIST Book author IDREFs #REQUIRED >

<Book author=“JHN_Q_PBLC JN_D TW_PC” .. >

------------------------------------------------------------

Page 26: Document Type Definitions (DTD) Basic Valid XML

DTD, by Dr. Khalil 26

Attribute Defaults #REQUIRED – The attribute must – The attribute must

appear in every instance of the element.appear in every instance of the element.

#IMPLIED – The attribute is optional. – The attribute is optional.

#FIXED (plus default value) – The (plus default value) – The attribute may or may not appear in the attribute may or may not appear in the document. If the attribute does appear, it document. If the attribute does appear, it must must match the default value; if it must must match the default value; if it doesn’t appear, the parser may supply the doesn’t appear, the parser may supply the default value.default value.

#default value(s) – The attribute may – The attribute may or may not appear in the document. If the or may not appear in the document. If the attribute does appear, it may be any attribute does appear, it may be any value that matches those in the ATTLIST value that matches those in the ATTLIST declaration; if it doesn’t appear, the declaration; if it doesn’t appear, the parser may supply the default value.parser may supply the default value.

Page 27: Document Type Definitions (DTD) Basic Valid XML

DTD, by Dr. Khalil 27

An Example – BookCatalogExpanded.dtd

<!-- ======= The BookCatalog DTD ('Expanded' version) <!-- ======= The BookCatalog DTD ('Expanded' version) ======= -->======= -->

<!ELEMENT BookCatalog (Catalog, Publishers?, <!ELEMENT BookCatalog (Catalog, Publishers?, Persons?, Subjects?, Books?) >Persons?, Subjects?, Books?) >

<!-- Generic PCDATA element types section --><!-- Generic PCDATA element types section -->

<!ELEMENT Biography (#PCDATA) ><!ELEMENT Biography (#PCDATA) >

<!ELEMENT CorpName (#PCDATA) ><!ELEMENT CorpName (#PCDATA) >

<!ELEMENT Email (#PCDATA) ><!ELEMENT Email (#PCDATA) >

<!ELEMENT Website (#PCDATA) ><!ELEMENT Website (#PCDATA) >

<!-- <Catalog> section --><!-- <Catalog> section -->

<!ELEMENT Catalog (CatalogTitle, CatalogDate) ><!ELEMENT Catalog (CatalogTitle, CatalogDate) >

<!ELEMENT CatalogTitle (#PCDATA) ><!ELEMENT CatalogTitle (#PCDATA) >

<!ELEMENT CatalogDate (#PCDATA) ><!ELEMENT CatalogDate (#PCDATA) >

<!-- <Publishers> section --><!-- <Publishers> section -->

<!ELEMENT Publishers (Publisher+) ><!ELEMENT Publishers (Publisher+) >

<!ELEMENT Publisher (CorpName, Email*, Website*, <!ELEMENT Publisher (CorpName, Email*, Website*, Address, Imprints?, Levels?) >Address, Imprints?, Levels?) >

<!ATTLIST Publisher<!ATTLIST Publisher pubID ID #REQUIREDpubID ID #REQUIRED isbn CDATA "??????"isbn CDATA "??????">>

<!ELEMENT Address (Street*, City, Region?, PostalCode?, <!ELEMENT Address (Street*, City, Region?, PostalCode?, Country) >Country) >

<!ATTLIST Address hq (yes | no) "yes" ><!ATTLIST Address hq (yes | no) "yes" >

<!ELEMENT Street (#PCDATA) ><!ELEMENT Street (#PCDATA) ><!ELEMENT City (#PCDATA) ><!ELEMENT City (#PCDATA) ><!ELEMENT Region (#PCDATA) ><!ELEMENT Region (#PCDATA) ><!ELEMENT PostalCode (#PCDATA) ><!ELEMENT PostalCode (#PCDATA) ><!ELEMENT Country (#PCDATA) ><!ELEMENT Country (#PCDATA) >

<!ELEMENT Imprints (Imprint+) ><!ELEMENT Imprints (Imprint+) ><!ELEMENT Imprint (#PCDATA) ><!ELEMENT Imprint (#PCDATA) ><!ATTLIST Imprint imprintID ID #REQUIRED ><!ATTLIST Imprint imprintID ID #REQUIRED >

<!ELEMENT Levels (Level+) ><!ELEMENT Levels (Level+) ><!ELEMENT Level (#PCDATA) ><!ELEMENT Level (#PCDATA) ><!ATTLIST Level levelID ID #REQUIRED ><!ATTLIST Level levelID ID #REQUIRED >

Page 28: Document Type Definitions (DTD) Basic Valid XML

DTD, by Dr. Khalil 28

BookCatalogExpanded.dtd (Cont’d)<!-- <Persons> section --><!-- <Persons> section -->

<!ELEMENT Persons (Person*) ><!ELEMENT Persons (Person*) >

<!ELEMENT Person (PersonName, CorpName?, Email*, <!ELEMENT Person (PersonName, CorpName?, Email*, Address?, Biography?) >Address?, Biography?) >

<!ATTLIST Person<!ATTLIST Person perID ID #REQUIREDperID ID #REQUIRED role (AU | ED | AE | IL | RV | unknown) #REQUIREDrole (AU | ED | AE | IL | RV | unknown) #REQUIRED >>

<!ELEMENT PersonName (SingleName | (FirstName, <!ELEMENT PersonName (SingleName | (FirstName, MiddleName*, LastName)) >MiddleName*, LastName)) >

<!ATTLIST PersonName<!ATTLIST PersonName honorific (Mr. | Ms. | Dr. | Rev.) #IMPLIEDhonorific (Mr. | Ms. | Dr. | Rev.) #IMPLIED suffix (Jr. | Sr. | I | II | III | IV | V | VI | VII | VIII) #IMPLIEDsuffix (Jr. | Sr. | I | II | III | IV | V | VI | VII | VIII) #IMPLIED>>

<!ELEMENT FirstName (#PCDATA) ><!ELEMENT FirstName (#PCDATA) ><!ELEMENT MiddleName (#PCDATA) ><!ELEMENT MiddleName (#PCDATA) ><!ELEMENT LastName (#PCDATA) ><!ELEMENT LastName (#PCDATA) ><!ELEMENT SingleName (#PCDATA) ><!ELEMENT SingleName (#PCDATA) >

<!-- <Subjects> section --><!-- <Subjects> section -->

<!ELEMENT Subjects (Subject*) ><!ELEMENT Subjects (Subject*) ><!ELEMENT Subject (#PCDATA) ><!ELEMENT Subject (#PCDATA) ><!ATTLIST Subject subjectID ID #REQUIRED ><!ATTLIST Subject subjectID ID #REQUIRED >

<!-- <Books> section --><!-- <Books> section -->

<!ELEMENT Books (Book+) ><!ELEMENT Books (Book+) >

<!ELEMENT Book (Title, Abstract?, Prices?, SubjectRefs?) ><!ELEMENT Book (Title, Abstract?, Prices?, SubjectRefs?) ><!ATTLIST Book<!ATTLIST Book bookID ID #REQUIREDbookID ID #REQUIRED isbn CDATA #REQUIREDisbn CDATA #REQUIRED publisher IDREF #REQUIREDpublisher IDREF #REQUIRED authors IDREFS #REQUIREDauthors IDREFS #REQUIRED editors IDREFS #REQUIREDeditors IDREFS #REQUIRED imprint IDREF #IMPLIEDimprint IDREF #IMPLIED pubDate CDATA "2000"pubDate CDATA "2000" pages CDATA "????"pages CDATA "????" level IDREF #IMPLIEDlevel IDREF #IMPLIED >>

<!ELEMENT Title (#PCDATA) ><!ELEMENT Title (#PCDATA) >

<!ELEMENT Abstract (#PCDATA) ><!ELEMENT Abstract (#PCDATA) >

<!ELEMENT Prices (Price+) ><!ELEMENT Prices (Price+) ><!ELEMENT Price (#PCDATA) ><!ELEMENT Price (#PCDATA) ><!ATTLIST Price currency (USD | GBP | CDN) "USD" ><!ATTLIST Price currency (USD | GBP | CDN) "USD" >

<!ELEMENT SubjectRefs (SubjectRef, SubjectRef?, SubjectRef?)<!ELEMENT SubjectRefs (SubjectRef, SubjectRef?, SubjectRef?)>><!ELEMENT SubjectRef EMPTY ><!ELEMENT SubjectRef EMPTY ><!ATTLIST SubjectRef subject IDREF #REQUIRED ><!ATTLIST SubjectRef subject IDREF #REQUIRED >

<!-- ======= END of 'Expanded' BookCatalog DTD ======= --><!-- ======= END of 'Expanded' BookCatalog DTD ======= -->

Page 29: Document Type Definitions (DTD) Basic Valid XML

DTD, by Dr. Khalil 29

BookCatalogExpanded.xml

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<!DOCTYPE BookCatalog SYSTEM "BookCatalogExpanded.dtd" ><!DOCTYPE BookCatalog SYSTEM "BookCatalogExpanded.dtd" >

<BookCatalog><BookCatalog>

<Catalog><Catalog> <CatalogTitle>The Wrox BookCatalog ('Expanded' <CatalogTitle>The Wrox BookCatalog ('Expanded'

version)</CatalogTitle>version)</CatalogTitle> <CatalogDate>2000-05-23</CatalogDate><CatalogDate>2000-05-23</CatalogDate></Catalog></Catalog>

<Publishers><Publishers>

<Publisher pubID="WRX_PRS_LTD" isbn="861003"><Publisher pubID="WRX_PRS_LTD" isbn="861003"> <CorpName>Wrox Press Ltd.</CorpName><CorpName>Wrox Press Ltd.</CorpName> <Email>[email protected]</Email><Email>[email protected]</Email> <Website>www.wrox.com</Website><Website>www.wrox.com</Website> <Address><Address> <Street>Arden House</Street><Street>Arden House</Street> <Street>1102 Warwick Road</Street><Street>1102 Warwick Road</Street> <Street>Acocks Green</Street><Street>Acocks Green</Street> <City>Birmingham</City><City>Birmingham</City> <Region>England</Region><Region>England</Region> <PostalCode>B27 6BH</PostalCode><PostalCode>B27 6BH</PostalCode> <Country>UK</Country><Country>UK</Country> </Address></Address>

<Imprints><Imprints>

<Imprint imprintID="PRG2PRG">Programmer to <Imprint imprintID="PRG2PRG">Programmer to Programmer</Imprint>Programmer</Imprint>

</Imprints></Imprints>

<Levels><Levels>

<Level levelID="BEG">Beginning</Level><Level levelID="BEG">Beginning</Level>

<Level levelID="INS">Instant</Level><Level levelID="INS">Instant</Level>

<Level levelID="PRO">Professional</Level><Level levelID="PRO">Professional</Level>

</Levels></Levels>

</Publisher></Publisher>

<Publisher pubID="WRX_PRS_INC"><Publisher pubID="WRX_PRS_INC">

<CorpName>Wrox Press Inc.</CorpName><CorpName>Wrox Press Inc.</CorpName>

<Address hq="no"><Address hq="no">

<Street>29 S LaSalle St, Suite 520</Street><Street>29 S LaSalle St, Suite 520</Street>

<City>Chicago</City><City>Chicago</City>

<Region>IL</Region><Region>IL</Region>

<PostalCode>60603</PostalCode><PostalCode>60603</PostalCode>

<Country>USA</Country><Country>USA</Country>

</Address></Address>

</Publisher></Publisher>

</Publishers></Publishers>

Page 30: Document Type Definitions (DTD) Basic Valid XML

DTD, by Dr. Khalil 30

BookCatalogExpanded.xml (Cont’d)<Persons><Persons>

<Person perID="DDR_MRTN" role="AU"><Person perID="DDR_MRTN" role="AU"> <PersonName><PersonName> <FirstName>Didier</FirstName><FirstName>Didier</FirstName> <MiddleName>P</MiddleName><MiddleName>P</MiddleName> <MiddleName>H</MiddleName><MiddleName>H</MiddleName> <LastName>Martin</LastName><LastName>Martin</LastName> </PersonName></PersonName> <CorpName>Talva Corp.</CorpName><CorpName>Talva Corp.</CorpName> <Biography>Didier PH Martin has worked with computers for 21 <Biography>Didier PH Martin has worked with computers for 21 years.</Biography>years.</Biography> </Person></Person>

<Person perID="DN_PRKR" role="ED"><Person perID="DN_PRKR" role="ED"> <PersonName><PersonName> <FirstName>Dianne</FirstName><FirstName>Dianne</FirstName> <LastName>Parker</LastName><LastName>Parker</LastName> </PersonName></PersonName> <CorpName>Wrox Press Ltd.</CorpName><CorpName>Wrox Press Ltd.</CorpName> </Person></Person>

<Person perID="DVD_HNTR" role="AU"><Person perID="DVD_HNTR" role="AU"> <PersonName><PersonName> <FirstName>David</FirstName><FirstName>David</FirstName> <LastName>Hunter</LastName><LastName>Hunter</LastName> </PersonName></PersonName> </Person></Person>

<Person perID="JN_DCKT" role="ED"><Person perID="JN_DCKT" role="ED"> <PersonName><PersonName> <FirstName>Jon</FirstName><FirstName>Jon</FirstName> <LastName>Duckett</LastName><LastName>Duckett</LastName> </PersonName></PersonName> <CorpName>Wrox Press Ltd.</CorpName><CorpName>Wrox Press Ltd.</CorpName> </Person></Person>

<Person perID="JNTHN_PNCK" role="AU"><Person perID="JNTHN_PNCK" role="AU"> <PersonName><PersonName> <FirstName>Jonathan</FirstName><FirstName>Jonathan</FirstName> <LastName>Pinnock</LastName><LastName>Pinnock</LastName> </PersonName></PersonName> <Email>[email protected]</Email><Email>[email protected]</Email> <Address><Address> <City>Hertfordshire</City><City>Hertfordshire</City> <Region>England</Region><Region>England</Region> <Country>UK</Country><Country>UK</Country> </Address></Address> </Person></Person>

<Person perID="KRL_WTSN" role="ED"><Person perID="KRL_WTSN" role="ED"> <PersonName><PersonName> <FirstName>Karli</FirstName><FirstName>Karli</FirstName> <LastName>Watson</LastName><LastName>Watson</LastName> </PersonName></PersonName> <CorpName>Wrox Press Ltd.</CorpName><CorpName>Wrox Press Ltd.</CorpName> </Person></Person>

Page 31: Document Type Definitions (DTD) Basic Valid XML

DTD, by Dr. Khalil 31

BookCatalogExpanded.xml (Cont’d)<Person perID="LS_STPHNSN" role="ED"><Person perID="LS_STPHNSN" role="ED"> <PersonName><PersonName> <FirstName>Lisa</FirstName><FirstName>Lisa</FirstName> <LastName>Stephenson</LastName><LastName>Stephenson</LastName> </PersonName></PersonName> <CorpName>Wrox Press Ltd.</CorpName><CorpName>Wrox Press Ltd.</CorpName> </Person></Person>

<Person perID="MRK_BRBCK" role="AU"><Person perID="MRK_BRBCK" role="AU"> <PersonName><PersonName> <FirstName>Mark</FirstName><FirstName>Mark</FirstName> <LastName>Birbeck</LastName><LastName>Birbeck</LastName> </PersonName></PersonName> <Biography>Mark has been a professional programmer for 18 <Biography>Mark has been a professional programmer for 18 years.</Biography>years.</Biography> </Person></Person>

<Person perID="NKL_OZ" role="AU"><Person perID="NKL_OZ" role="AU"> <PersonName><PersonName> <FirstName>Nikola</FirstName><FirstName>Nikola</FirstName> <LastName>Ozu</LastName><LastName>Ozu</LastName> </PersonName></PersonName> <Biography>Nikola Ozu is a consultant who lives in <Biography>Nikola Ozu is a consultant who lives in

Wyoming.</Biography>Wyoming.</Biography> </Person></Person>

<Person perID="PTR_JNS" role="ED"><Person perID="PTR_JNS" role="ED">

<PersonName><PersonName>

<FirstName>Peter</FirstName><FirstName>Peter</FirstName>

<LastName>Jones</LastName><LastName>Jones</LastName>

</PersonName></PersonName>

<CorpName>Wrox Press Ltd.</CorpName><CorpName>Wrox Press Ltd.</CorpName>

</Person></Person>

<Person perID="STPHN_MHR" role="AE"><Person perID="STPHN_MHR" role="AE">

<PersonName><PersonName>

<FirstName>Stephen</FirstName><FirstName>Stephen</FirstName>

<LastName>Mohr</LastName><LastName>Mohr</LastName>

</PersonName></PersonName>

<CorpName>Omicron Consulting</CorpName><CorpName>Omicron Consulting</CorpName>

</Person></Person>

<Person perID="STVN_LVNGSTN" role="AU"><Person perID="STVN_LVNGSTN" role="AU">

<PersonName><PersonName>

<FirstName>Steven</FirstName><FirstName>Steven</FirstName>

<LastName>Livingstone</LastName><LastName>Livingstone</LastName>

</PersonName></PersonName>

</Person></Person>

</Persons></Persons>

Page 32: Document Type Definitions (DTD) Basic Valid XML

DTD, by Dr. Khalil 32

BookCatalogExpanded.xml (Cont’d)<Subjects><Subjects> <Subject subjectID="INTRNT">Internet</Subject><Subject subjectID="INTRNT">Internet</Subject> <Subject subjectID="INTRNT_PRGRMNG">Internet <Subject subjectID="INTRNT_PRGRMNG">Internet

Programming</Subject>Programming</Subject> <Subject subjectID="XML">XML (eXtensible Markup <Subject subjectID="XML">XML (eXtensible Markup

Language)</Subject>Language)</Subject></Subjects></Subjects>

<Books><Books>

<Book bookID="PRFSNL_XML" isbn="1-861003-11-0" <Book bookID="PRFSNL_XML" isbn="1-861003-11-0" publisher="WRX_PRS_LTD"publisher="WRX_PRS_LTD"

authors="DDR_MRTN JNTHN_PNCK MRK_BRBCK authors="DDR_MRTN JNTHN_PNCK MRK_BRBCK STPHN_MHR NKL_OZ"STPHN_MHR NKL_OZ"

editors="JN_DCKT PTR_JNS KRL_WTSN"editors="JN_DCKT PTR_JNS KRL_WTSN" imprint="PRG2PRG" pubDate="2000-01" pages="1169" imprint="PRG2PRG" pubDate="2000-01" pages="1169"

level="PRO">level="PRO"> <Title>Professional XML</Title><Title>Professional XML</Title> <Abstract>The complete practical encyclopedia for XML <Abstract>The complete practical encyclopedia for XML

today.</Abstract>today.</Abstract> <Prices><Prices> <Price currency="USD">49.99</Price><Price currency="USD">49.99</Price> <Price currency="GBP">35.99</Price><Price currency="GBP">35.99</Price> <Price currency="CDN">74.95</Price><Price currency="CDN">74.95</Price> </Prices></Prices>

<SubjectRefs><SubjectRefs> <SubjectRef subject="INTRNT" /><SubjectRef subject="INTRNT" /> <SubjectRef subject="INTRNT_PRGRMNG" /><SubjectRef subject="INTRNT_PRGRMNG" /> <SubjectRef subject="XML" /><SubjectRef subject="XML" /> </SubjectRefs></SubjectRefs> </Book></Book>

<Book bookID="BEGNNG_XML" isbn="1-861003-41-2" <Book bookID="BEGNNG_XML" isbn="1-861003-41-2" publisher="WRX_PRS_LTD"publisher="WRX_PRS_LTD"

authors="DVD_HNTR JNTHN_PNCK NKL_OZ"authors="DVD_HNTR JNTHN_PNCK NKL_OZ" editors="DN_PRKR LS_STPHNSN"editors="DN_PRKR LS_STPHNSN" imprint="PRG2PRG" level="BEG">imprint="PRG2PRG" level="BEG"> <Title>Beginning XML</Title><Title>Beginning XML</Title> <Abstract>The best practical tutorial for XML.</Abstract><Abstract>The best practical tutorial for XML.</Abstract> <Prices><Prices> <Price>39.99</Price><Price>39.99</Price> <Price currency="GBP">28.99</Price><Price currency="GBP">28.99</Price> <Price currency="CDN">59.95</Price><Price currency="CDN">59.95</Price> </Prices></Prices> <SubjectRefs><SubjectRefs> <SubjectRef subject="INTRNT" /><SubjectRef subject="INTRNT" /> <SubjectRef subject="INTRNT_PRGRMNG" /><SubjectRef subject="INTRNT_PRGRMNG" /> <SubjectRef subject="XML" /><SubjectRef subject="XML" /> </SubjectRefs></SubjectRefs> </Book></Book>

</Books></Books>

</BookCatalog></BookCatalog>

Page 33: Document Type Definitions (DTD) Basic Valid XML

DTD, by Dr. Khalil 33

Limitations of DTDs

DTDs are not extensible (unlike XML itself).DTDs are not extensible (unlike XML itself).

Only one DTD may be associated with each Only one DTD may be associated with each document.document.

DTDs do not work well with XML namespaces.DTDs do not work well with XML namespaces.

Very weak data typing.Very weak data typing.

Page 34: Document Type Definitions (DTD) Basic Valid XML

DTD, by Dr. Khalil 34

Thank you