XML Technologies DTD Dr Alexiei Dingli 1 Whats
- Slides: 38
XML Technologies DTD Dr Alexiei Dingli 1
What’s in a DTD? • Document Type Definition • Defines – the legal building blocks of an XML document – the document structure – The legal elements and attributes • A DTD can be defined inside an xml document or outside 2
Why do we need a DTD? • An XML file can carry a description of its own format • Independent groups of people can agree to use a standard DTD for interchanging data • Applications can use a standard DTD to verify that the data received from the outside world is valid • A DTD can be used to verify the data 3
An inside DTD (1) <!DOCTYPE root-element [element-declarations]> 4
An inside DTD (2) 5
An inside DTD (3) • !DOCTYPE note defines that the root element of this document is note. • !ELEMENT note defines that the note element contains four elements: "to, from, heading, body". • !ELEMENT to defines the to element to be of the type "#PCDATA". • !ELEMENT from defines the from element to be of the type "#PCDATA". • !ELEMENT heading defines the heading element to be of the type "#PCDATA". 6 • !ELEMENT body defines the body element to be of the type "#PCDATA".
External DTD <!DOCTYPE root-element SYSTEM "filename"> <!DOCTYPE note SYSTEM "note. dtd"> 7
The building blocks • Elements • Attributes • Entities • PCDATA • CDATA 8
Elements • Main building block • Can contain text, other elements or be empty • The elements b, title and br can be used as follows: <b>Hello world</b> <title>Hello <b>Tom</b></title> <br /> 9
Attributes • Provide extra information about elements • Always placed inside the opening tag • Always have a name/value pair Which is the element, attribute and value? <img src="computer. gif" /> 10
Entities Entity References Character < < > > & & " " ' ' 11
CDATA • Text that will NOT be parsed by a parser • Tags inside the text will NOT be treated as markup and entities will not be expanded 12
PCDATA • Parsed character data • Character data is the text found between the start tag and the end tag of an XML element • Text that WILL be parsed by a parser – The text will be examined by the parser for entities and markup • Tags inside the text will be treated as markup and entities will be expanded • However, parsed character data should not contain any &, <, or > characters; these need to be represented by the & < and > entities, 13 respectively
Different Elements <!ELEMENT element-name category> 14
The Empty Element <!ELEMENT br EMPTY> <br /> 15
Element with PCDATA <!ELEMENT element-name (#PCDATA)> <!ELEMENT from (#PCDATA)> 16
Element with Any <!ELEMENT element-name ANY> <!ELEMENT note ANY> 17
Elements with Children <!ELEMENT element-name (child 1, child 2, . . . )> <!ELEMENT note (to, from, heading, body)> *Sequence must be respected 18
Element with one child <!ELEMENT element-name (child-name)> <!ELEMENT note (message)> 19
Occurrences • One or more – <!ELEMENT element-name (child-name+)> – <!ELEMENT note (message+)> • Zero or more – <!ELEMENT element-name (child-name*)> – <!ELEMENT note (message*)> • Zero or One – <!ELEMENT element-name (child-name? )> – <!ELEMENT note (message? )> 20
Mixing. . . • Either or – <!ELEMENT note (to, from, header, (message|body))> • Mixed content – <!ELEMENT note (#PCDATA|to|from|header|message)*> 21
Declaring Attributes <!ATTLIST element-name attribute-type default-value> <!ATTLIST payment type CDATA "check"> <payment type="check" /> 22
Atribute Type Description CDATA The value is character data (en 1|en 2|. . ) The value must be one from an enumerated list ID The value is a unique id IDREF The value is the id of another element IDREFS The value is a list of other ids NMTOKEN The value is a valid XML name NMTOKENS The value is a list of valid XML names ENTITY The value is an entity ENTITIES The value is a list of entities NOTATION The value is a name of a notation xml: The value is a predefined xml value 23
Attribute Value Explanation value The default value of the attribute #REQUIRED The attribute is required #IMPLIED The attribute is not required #FIXED value The attribute value is fixed 24
CDATA example <!ATTLIST mountain country CDATA "New Zealand"> <mountains> <mountain country="New Zealand"> <name>Mount Cook</name> </mountain> 25
Enumerated Example <!ATTLIST tutorial published (yes | no) "no"> <tutorial published="yes"> <name>XML Tutorial</name> </tutorial> 26
ID example <!ATTLIST mountain_id ID #REQUIRED> <mountain_id="m 10001"> <name>Mount Cook</name> </mountain> 27
ID Ref example <!ATTLIST employee_id ID #REQUIRED manager_id IDREF #IMPLIED> <employees> <employee_id="e 10001" manager_id="e 10002"> <first_name>Homer</first_name> <last_name>Flinstone</last_name> </employee> <employee_id="e 10002"> <first_name>Fred</first_name> <last_name>Burns</last_name> 28 </employee> </employees>
ID Refs example <!ATTLIST individual_id ID #REQUIRED parent_id IDREFS #IMPLIED> <individual_id="e 10001" parent_id="e 10002 e 10003"> <first_name>Bart</first_name> <last_name>Simpson</last_name> </individual> 29
NMTOKEN example <!ATTLIST tutorial published NMTOKEN #REQUIRED> * Can contain only letters, digits, points, hyphen, underline and colon <mountain country="NZ"> <name>Mount Cook</name> </mountain> 30
Notation example <!NOTATION name SYSTEM "external_id"> * Allow you to add data which is not XML <!NOTATION GIF SYSTEM "image/gif"> <!NOTATION JPG SYSTEM "image/jpeg"> <!NOTATION PNG SYSTEM "image/png"> <!ATTLIST mountain photo ENTITY #IMPLIED photo_type NOTATION (GIF | JPG | PNG) #IMPLIED> 31
Entity example <!ATTLIST mountain photo ENTITY #IMPLIED> <!ENTITY mt_cook_1 SYSTEM "mt_cook 1. jpg"> <mountain photo="mt_cook_1"> <name>Mount Cook</name> </mountain> 32
More about Entities • Entities are variables used to define shortcuts to standard text or special characters – Entity references are references to entities – Entities can be declared internal or external 33
Internal Entities <!ENTITY writer “Alexiei Dingli"> <!ENTITY copyright "Copyright Dingli@UOM"> <author>&writer; ©right; </author> 34
External Entities <!ENTITY writer SYSTEM "http: //www. um. edu. mt/entities. dtd"> <!ENTITY copyright SYSTEM "http: //www. um. edu. mt/entities. dtd"> <author>&writer; ©right; </author> 35
Example 36
Exercise • Define an XML Vocabulary for a Toaster Markup Language (TML) • It must support features such as: – Print message on toast – Display on LCD – Time stamp 37
Questions? 38
- External dtd
- Dtd xml
- Whats dtd
- Data integration with xml and semantic web technologies
- Dtd syntax
- Internal dtd example
- Dtd in web technology
- Dtd
- Dtd
- Dtd idrefs
- Accounting income vs taxable income
- Archivo dtd
- Visual studio
- Dtd vs schema
- Adbs
- Dtd
- Dtd
- Dtd
- Dtd
- Slidetodoc
- Whats hot whats not
- Zig tutorial
- What is xul
- создание парсеров
- Xray xml editor
- Dublin core xml
- Java soap xml 파싱
- Java xml datei einlesen
- Xml stands for
- Xml stands for *
- Xml gateway
- Syntax xml
- Advantages of xml
- Textml server reviews
- Extracting data from xml
- Specifications and constraints
- Xml meaning
- Xbrl vs xml
- Xml in web services