Download presentation
Presentation is loading. Please wait.
Published byCornelius Harrington Modified over 9 years ago
1
Lecture 6 XML DTD Content of.xml fileContent of.dtd file
2
What is DTD? DTD (Document Type Definition) define an XML document’s structure. DTD (Document Type Definition) define an XML document’s structure. A typical DTD defines what elements can appear in an XML document, how they can be nested and what attributes the elements have. A typical DTD defines what elements can appear in an XML document, how they can be nested and what attributes the elements have. When creating an XML document we can specify which DTD it conforms to. When creating an XML document we can specify which DTD it conforms to. DTDs are written using the Extended Backus- Naur Form. DTDs are written using the Extended Backus- Naur Form. DTDs can be locally or publicly stored. Examples of public DTDs are the XHTML’s DTDs. DTDs can be locally or publicly stored. Examples of public DTDs are the XHTML’s DTDs.
3
.dtd.xml.xsd DTD Schema or.xml DOM API Software System SAX API.css.xsl.fo Stylesheet DTD in the Context of an XML Project
4
Document Type Declaration <!DOCTYPE myMessage [ ]> Internal subset External subset <!DOCTYPE myMessage SYSTEM "myDTD.dtd" [ ]> Mixed DTD is DOCTYPE’s Internal Subset + External Subset Alternatives
5
Document Type Declaration (full example) Hello World! example.xml message.dtd root element
6
Sequences, Pipe Characters and Occurrence Indicators Pablo Honey You 3:27 Creep 3:55
7
Sequences, Pipe Characters and Occurrence Indicators (contd.) XML: How to Program Multimedia Peter O’Connor
8
Sequences, Pipe Characters and Occurrence Indicators (contd.) <!ELEMENT donutBox ( jelly?, lemon*, ( ( crème | sugar)+ | glazed ) )> grape half-sour sour chocolate semi-sweet whipped sweet
9
Occurrence Indicators (summary) A* A may occur zero, one or more times A* A may occur zero, one or more times A+ A may occur one or more times (but must occur at least once) A+ A may occur one or more times (but must occur at least once) A? A must either not occur or occur once A? A must either not occur or occur once
10
EMPTY, Mixed Content and ANY ANY is used in early stages of developing DTDs. Here is some text, some other text and even more text
11
Attribute Declarations Element x has an attribute y of type CDATA whose value must be provided. Attribute types: 1.CDATA – string that can contain any character text except & ' and " 2.Tokenized attribute types: ID, IDREF, ENTITY, NMTOKEN 3.Enumerated attribute types: NOTATION
12
Well-formed and Valid XML Documents An XML document is well-formed if it is syntactically correct, i.e. An XML document is well-formed if it is syntactically correct, i.e. 1.There is a single root element. 2.Each element has a start and an end tag. 3.Elements are nested properly. 4.Attribute values are in quotes. An XML Document is Valid if it conforms to the DTD specified with the DOCTYPE declaration An XML Document is Valid if it conforms to the DTD specified with the DOCTYPE declaration Any element, attribute and entity used in the XML document must be defined in the DTD;Any element, attribute and entity used in the XML document must be defined in the DTD; Each element’s content and attributes must correspond to the declarations in the DTDEach element’s content and attributes must correspond to the declarations in the DTD An XML document can be well-formed but NOT valid! An XML document can be well-formed but NOT valid!
13
XML Processor Also called XML Parser Also called XML Parser A software program required to process an XML document A software program required to process an XML document Checks syntaxChecks syntax A validating XML processors checks whether an XML document conforms to the specified DTDA validating XML processors checks whether an XML document conforms to the specified DTD Reports any errorsReports any errors Required to pass all characters in a document, including white space characters, to the application using the XML documentRequired to pass all characters in a document, including white space characters, to the application using the XML document A validating XML processor must also inform the application which characters constitute white space appearing in element contentA validating XML processor must also inform the application which characters constitute white space appearing in element content
14
Parameter Entities Internal (parsed) Internal (parsed) Used to declare entities existing only in the DTDUsed to declare entities existing only in the DTD Entity value can be a string of characters that contains:Entity value can be a string of characters that contains: any character that is not &, %, ", ', any character that is not &, %, ", ', parameter entity reference %Name; parameter entity reference %Name; general entity reference &Name; (to be explained shortly) general entity reference &Name; (to be explained shortly) Unicode character reference, e.g., A O Unicode character reference, e.g., A O External (parsed) External (parsed) Used to link to external DTDsUsed to link to external DTDs Can be private or publicCan be private or public URI – Uniform Resource Identifier (more generic than URL)
15
Parameter Entities (examples) %student;
16
General Entities Internal (parsed) Internal (parsed) Can be thought of text macrosCan be thought of text macros Entity value can be a string of characters;Entity value can be a string of characters; any character that is not &, %, ", ', any character that is not &, %, ", ', parameter entity reference %Name; parameter entity reference %Name; general entity reference &Name; general entity reference &Name; Unicode character reference, e.g., A O Unicode character reference, e.g., A O ? <!DOCTYPE author [ ]> &js;
17
General Entities (contd.) External (parsed) External (parsed) Generally reference text that an XML parser has to parse.Generally reference text that an XML parser has to parse. Useful for creating a common reference shared between multiple documents.Useful for creating a common reference shared between multiple documents. Any changes made to external entities are automatically updated in documents they are referenced.Any changes made to external entities are automatically updated in documents they are referenced. Can be private or publicCan be private or public <!ENTITY pc PUBLIC "-//W3C//TEXT copyright//EN" "http://www.w3.org/xmlspec/copyright.html"> &c; &pc;
18
General Entities (contd.) External NDATA entities (unparsed) External NDATA entities (unparsed) Generally reference to non-XML data.Generally reference to non-XML data. Refer to data that an XML processor does not have to parseRefer to data that an XML processor does not have to parse <!ENTITY plogo PUBLIC "-//W3C//GIF logo//EN" "http://www.w3.org/logo.gif" NDATA gif> NOTATIONS are used to identify the format of unparsed entities (non-XML data), elements with a notation attribute, or specific processing instructions.
19
Predefined General Entities There are 5 predefined entities There are 5 predefined entities < << < > >> > & && & " "" " ' '' ' Every character can also be represented as character entity (UNICODE value) Every character can also be represented as character entity (UNICODE value) e.g., ¶ or 꽌e.g., ¶ or 꽌
20
Attribute Declarations Attributes are defined for the elements they belong to or <!ATTLIST test subject CDATA #REQUIRED difficulty CDATA #IMPLIED >
21
Attribute Types CDATA CDATA character data, that is, text that does not form markup (no " ' & %)character data, that is, text that does not form markup (no " ' & %) Tokenized attribute types Tokenized attribute types ID, IDREF, IDREFS, ENTITY, ENTITIES, NMTOKEN, NMTOKENSID, IDREF, IDREFS, ENTITY, ENTITIES, NMTOKEN, NMTOKENS Enumerated types Enumerated types NOTATION, EnumeratedNOTATION, Enumerated
22
Attribute Types (contd.) Tokenized attribute types Tokenized attribute types IDID IDs of a particular value should not appear more than once in an XML document IDs of a particular value should not appear more than once in an XML document An element type may only have one ID attribute An element type may only have one ID attribute An ID attribute can only have an #IMPLIED or #REQUIRED default value An ID attribute can only have an #IMPLIED or #REQUIRED default value The first character of an ID value must be a letter, _, or : The first character of an ID value must be a letter, _, or : IDREFIDREF must refer to an ID value declared elsewhere in the document must refer to an ID value declared elsewhere in the document IDREFSIDREFS Allows multiple ID values separated by whitespace Allows multiple ID values separated by whitespace
23
Attribute Types (contd.) Tokenized attribute types (more…) Tokenized attribute types (more…) ENTITYENTITY Reference to a general entity Reference to a general entity ENTITIESENTITIES Allows multiple entity names separated by white space Allows multiple entity names separated by white space NMTOKENNMTOKEN Name according to the XML specification; The first character must be a letter, digit,., -, _, or : Name according to the XML specification; The first character must be a letter, digit,., -, _, or : NMTOKENSNMTOKENS Allows multiple NMTOKEN names separated by white space Allows multiple NMTOKEN names separated by white space
24
Attribute Types (contd.)... Example 1
25
Attribute Types (contd.) Example 2
26
Attribute Types (contd.) Enumerated attribute types Enumerated attribute types NOTATIONNOTATION useful when text needs to be interpreted in a particular way, for example, by another application. The first character must be a letter, _, or : useful when text needs to be interpreted in a particular way, for example, by another application. The first character must be a letter, _, or : EnumeratedEnumerated Enumerated attribute types allow you to make a choice between different attribute values. The first character of an Enumerated value must be a letter, digit,., -, _, or : Enumerated attribute types allow you to make a choice between different attribute values. The first character of an Enumerated value must be a letter, digit,., -, _, or :
27
Attribute Types (contd.) <!DOCTYPE code [ ]> Some VRML instructions Example 3
28
Attribute Types (contd.) <!DOCTYPE ToDoList [ ]> This is an important task that must be completed This task can wait Example 4
29
Attribute Default Values #REQUIRED #REQUIRED Such an attribute must be suppliedSuch an attribute must be supplied #IMPLIED #IMPLIED Such an attribute may be suppliedSuch an attribute may be supplied #FIXED #FIXED Such an attribute has a fixed value (even if it is NOT supplied)Such an attribute has a fixed value (even if it is NOT supplied)
30
Attribute Default Values (contd.) <!DOCTYPE ToDoList [ ]> This is an important task. This is by default a task with a normal status.
31
Declarations in DTD
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.