Presentation is loading. Please wait.

Presentation is loading. Please wait.

CITA 330 Section 2 DTD. Defining XML Dialects “Well-formedness” is the minimal requirement for an XML document; all XML parsers can check it Any useful.

Similar presentations


Presentation on theme: "CITA 330 Section 2 DTD. Defining XML Dialects “Well-formedness” is the minimal requirement for an XML document; all XML parsers can check it Any useful."— Presentation transcript:

1 CITA 330 Section 2 DTD

2 Defining XML Dialects “Well-formedness” is the minimal requirement for an XML document; all XML parsers can check it Any useful XML document must follow the syntax rules of a specific XML dialect: which tags and attributes can be used, how elements can be ordered or nested … Major mechanisms for defining XML dialects: –Document Type Definition (DTD) –XML Schema (XSD) XML validating parsers can read an XML instance document and its syntax definition DTD/XSD file to validate whether the XML document conforms to the syntax constraints

3 Document Type Definition DTD is simpler than XSD and can specify less syntax constraints DTD is part of XML specification DTD syntax is not based on XML Usually DTD is specified in a separate file so it can be referred to by many of its instance XML documents Local DTD definitions, especially entity name definitions, can also be included at the top of an XML document to override some global definitions

4 External DTD Example A “library” element contains one or more “dvd” elements A “dvd” element contains one “title” element, one “format” element, and one “genre” elements, in the same order The “title”, “format” and “genre” elements all have strings as their values A “dvd” element has a required attribute “id” whose value is a string

5 Declaring Elements Empty elements – –Example: Elements with text or generic data – #PCDATA means that the element contains data that is going to be parsed by a parser for markups including entity references but not for nested elements – The keyword ANY declares an element with any content as its value, including text, entity references and nested elements. Any element nested in this element must also be declared

6 Declaring Elements Elements with children (sequences) – Elements with zero or more nested element – Elements with one or more nested element – Elements with optional nested elements –

7 Declaring Elements Elements with alternative nested elements – Elements with mixed content – –An email element must contain in the same order at least one to child element, exactly one from child element, exactly one header element, zero or more attachment elements, and some other parsed character data as well

8 Operators Used with Element Content Comma (,) specifies a required sequence of child elements Vertical line or pipe (|) specifies a list of candidate child elements Question mark (?) specifies that the child element is optional Plus Sign (+) specifies that at least one child element(s) is required Asterisk (*) specifies the zero or more of the child element(s) may appear

9 Declaring Attributes Syntax: –DTD –XML (having default radius 1) –DTD –XML

10 Declaring Attributes Declaring an optional attribute without default value –DTD –XML (having no attribute radius ) Declaring a mandatory attribute –DTD –XML (invalid element)

11 attributeType TypeDescription CDATAIndicates that the attribute value is character data IDIndicates that the attribute value uniquely identifies the containing element IDREFIndicates that the attribute value is a reference, by ID, to a uniquely identifiable element IDREFSIndicates that the attribute value is a whitespace-separated list of IDREF values ENTITYIndicates that the attribute value is a reference to an external unparsed entity (we will learn more about entities later). The unparsed entity might be an image file or some other external resource such as an MP3 or some other binary file ENTITIESIndicates that the attribute value is a whitespace-separated list of ENTITY values NMTOKENIndicates that the attribute value is a name token. An NMTOKEN is a string of character data consisting of standard name characters NMTOKENSIndicates that the attribute value is a whitespace-separated list of NMTOKEN values Enumerated List Apart from using the default types, you can also declare an enumerated list of possible values for the attribute

12 Declaring Entity Names Syntax: – –Example usage of entity names XML code: A &cs; book costs me €52. View: A Computer Science book costs me €52.

13 Associating DTD Declarations to XML Documents Including DTD declarations in an XML document – <!DOCTYPE library [ ]> Gone with the Wind Movie Classic

14 Associating DTD Declarations to XML Documents Referencing an external DTD file from an XML document – Gone with the Wind Movie Classic


Download ppt "CITA 330 Section 2 DTD. Defining XML Dialects “Well-formedness” is the minimal requirement for an XML document; all XML parsers can check it Any useful."

Similar presentations


Ads by Google