Structured Documents KA1 Document Type definition DTD.
-
date post
20-Dec-2015 -
Category
Documents
-
view
224 -
download
3
Transcript of Structured Documents KA1 Document Type definition DTD.
Structured Documents KA 2
Structural Analysis Structural Analysis and DTDand DTD1. Structural Analyses and DTD
2. What is DTD
3. Ex: phonebook.dtd
4. Ex: phonebook.xml
5. Parts of XML Document
6. Producing XML Document
7. XML Browsers
8. Ex phonebook.xsl
9. DTD Planning
10. XML: Separators
11. XML: Comments and Naming
12. XML: Elelemnts
13. XML: Order of elements
14. Ex: Letter
15. Ex: Letter b
16. Ex: letter c
17. DTD: Building Blocks
18. DTD: Elements
19. XML tags
20. DTD: Attributes
21. Types of Attribute
22. Attribute Defaults
23. DTD: Predefined Entities
24. DTD: Own Entities
25. DTD: PCDATA / CDATA
Structured Documents KA 3
What is a DTDWhat is a DTD
• DTD = Document Type Definition
definition of the document class
•DTD descripes the logical elements, their order and content
•DTD can be created from the structure diagram
Structured Documents KA 4
Example phonebook.dtdExample phonebook.dtd<!-- There can be many persons --><!ELEMENT phonebook (person*)><!ATTLIST phonebook company CDATA #REQUIRED><!ELEMENT person (firstname, surname,address,phone )><!ELEMENT address (street,postalcode, postoffice)><!ELEMENT phone (homenumber, mobile)><!ATTLIST phone confidential (yes | no ) "no"><!ELEMENT firstname (#PCDATA)><!ELEMENT surname (#PCDATA)><!ELEMENT street (#PCDATA)><!ELEMENT postalcode (#PCDATA)><!ELEMENT postoffice (#PCDATA)><!ELEMENT homenumber (#PCDATA)><!ELEMENT mobile (#PCDATA)>
Structured Documents KA 5
Example phonebook. xmlExample phonebook. xml<?xml version="1.0" encoding="ISO-8859-1"?><?xml-stylesheet type="text/xsl" href="phonebook.xsl"?><!DOCTYPE phonebook SYSTEM "phonebook.dtd"><!-- DOCTYPE root-element SYSTEM "filename"-->
<phonebook company = "Gurus ltd"><person>
<firstname>Michael</firstname><surname>Schumacher</surname><address>
<street>Nelikkoratsu 2 A56</street><postalcode>01234</postalcode><postoffice>Heinola</postoffice>
</address><phone> <homenumber>04 11223 344</homenumber>
……
Structured Documents KA 6
Parts of an XML Parts of an XML DocumentDocumentA XML document itself consist of:
• XML declaration (can be missing)
• Document Type Definition (DTD can be missing)
• Root element (eg. <mail>
• Document instance (representative of the document class)
XML declaration informs the XML prosessing system about the version and the character set e.g.
DTD can be written directly into a document itself or into another document
Structured Documents KA 7
Producing an XML Producing an XML DocumentDocument
XML +
DTD
XML editor
dbase dbase
simple editor
Paperdoc
IntelligentIntelligent
OCROCRStructureddoc
conversionconversion
• XML Spy
• XMetal
• Eclipse
Structured Documents KA 8
Example phonebook.xslExample phonebook.xsl<?xml version="1.0" encoding="ISO-8859-1"?><xsl:stylesheet version="1.0”
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/"> <html> <body> <h1>Phonebook</h1> <h2>Company <xsl:value-of select="@company"> </h2> <h4> …..
Structured Documents KA 9
DTD PlanningDTD Planning1. Define application area (firm, department …)2. Define strategy of using the DTD
1. Why to do the DTD?2. How DTD is applied?3. Priority of functionality?4. Access criterias?5. Sorting/Calculation criterias
3. Define the users4. Name the DTD5. Define the logical elements of the document class
1. Structure analyzes2. Name the elements3. Element vs. attribute
Structured Documents KA 10
XML: SeparatosXML: Separatos
<! < </ > /> Used to separate the information and the
markup E.g. <h1> Header</h1>
Structured Documents KA 11
XML: Comments and XML: Comments and NamingNaming A comment is defined <! - - This is a comment - - > XML name consist of the following chars: 1. char a-z, A-Z 2-n. char a-z, A-Z, 0-9,.,- NO tab or whitespace XML names are CASE sensitive
Structured Documents KA 12
XML: ElementsXML: Elements Element format <to> Element ending </to> Element is defined in the DTD
<!ELEMENT to (#PCDATA) > Element can include other elements
<!ELEMENT letter (to, from, p*)> The part within the parenthis is called the model
group. Element can be text, #PCDATA or include other
elements.
Structured Documents KA 13
XML: Order of ElementsXML: Order of Elements
Elements in sequence are separated with a comma (,)
0,1 or n times appearing elements with (*) 1 or n times appearing elements with (+) Alternative elements with a pipe (|) 0 or 1 time appearing element with a question
mark (?)
Structured Documents KA 14
Example: letterExample: letterletter.dtd
<!ELEMENT letter (from, to, p*, sign)>
<!ELEMENT from (#PCDATA) >
<!ELEMENT to (#PCDATA) >
<!ELEMENT p (#PCDATA) >
<!ELEMENT sign (#PCDATA) >
letter.xml
<?xml version=“1.0”?>
<!DOCTYPE letter SYSTEM ”letter.dtd">
<letter>
<from>Seija R.</from>
<to>Kake A.</to>
<p>Perjantaina on tiimipalaveri</p>
<sign>Seija R.</sign>
</letter>
Structured Documents KA 15
Example: letter bExample: letter bletterb.dtd<!ELEMENT LETTER (HEADER, BODY, END)><!ELEMENT HEADER (TO, FROM, SUBJECT)><!ELEMENT BODY (P*) ><!ELEMENT END (SIGN*) ><!ELEMENT FROM (#PCDATA) ><!ELEMENT TO (#PCDATA) ><!ELEMENT SUBJECT (#PCDATA) ><!ELEMENT P (#PCDATA) ><!ELEMENT SIGN (#PCDATA) >
letterb.xml
<?xml version=“1.0”?>
<!DOCTYPE LETTER SYSTEM ”letterb.dtd">
<LETTER><HEADER>
<FROM>Seija R.</FROM>
<TO>Kake A.</TO>
<SUBJECT>Tiimipalaveri</SUBJECT>
</HEADER>
<BODY>
<P>Perjantaina on tiimipalaveri</P> </BODY>
<END> <SIGN>Seija R.</SIGN>
<SIGN>Erkki R.</SIGN> </END>
</LETTER>
Structured Documents KA 16
Example: letter cExample: letter c
letterc.dtd
<!ELEMENT LETTER (HEADER, BODY, END)>
<!ELEMENT HEADER (((FROM,TO+) | (TO+, FROM)), SUBJECT)>
<!ELEMENT BODY (P*) >
<!ELEMENT END (SIGN*) >
<!ELEMENT FROM (#PCDATA) >
<!ELEMENT TO (#PCDATA) >
<!ELEMENT SUBJECT (#PCDATA) >
<!ELEMENT P (#PCDATA) >
<!ELEMENT SIGN (#PCDATA) >
Structured Documents KA 17
DTD Building BlocksDTD Building Blocks
Seen from a DTD point of view, all XML documents (and HTML documents) are made up by the following simple building blocks: Elements Tags Attributes Entities PCDATA = parseable character data CDATA
Structured Documents KA 18
DTD: ElementsDTD: Elements
Elements are the main building blocks of both XML and XHTML documents.
Examples of XHTML elements are "body" and "table". Examples of XML elements could be "note" and "message".
Elements can contain text, other elements, or be empty. Examples of empty HTML elements are "hr", "br" and "img".
Structured Documents KA 19
XML: TagsXML: Tags
Tags are used to markup elements.A starting tag like <element_name> marks
up the beginning of an element, and an ending tag like </element_name> marks up the end of an element.
body element marked up with body tags: <body>body text in between</body>.
message element marked up with message tags: <message>some message in between</message>
Structured Documents KA 20
DTD: AttributesDTD: AttributesAttributes provide extra information about elements.Attributes are always placed inside the starting tag of an
element. Attributes always come in name/value pairs. The following "img" element has additional information about a source file:
<img src="computer.gif" />The name of the element is "img". The name of the attribute
is "src". The value of the attribute is "computer.gif". Since the element itself is empty it is closed by a " /".
DTD: <!ATTLIST DRINK amount CDATA>
.xml: <DRINK amount=”4 dl">
Structured Documents KA 21
Types of AttributeTypes of AttributeType Meaning
CDATA Character data (string)
IDIDREFIDREFS
Name unique within a given documentReference to some element bearing an ID attribute
Series of IDREFs delimited with white spaceENTITYENTITIES
Name of predefined external entitySeries of entity names delimited by white space
NMTOKEN A name
NOTATION Accepts one of a series of explicitly user-defined values that the attribute can take on
dtd: <!ATTLIST someEl someText CDATA #IMPLIED>
xml:< someEl someText =”Pisa is something”>
dtd: <!ATTLIST Person ssn ID #REQUIRED>
xml:< Person ssn = ”22-11-20033”> … </Person>
Structured Documents KA 22
Attribute DefaultsAttribute Defaults
Value Explanation
value The attributes default value
#DEFAULT value The attributes default value
#REQUIRED The attribute value must be included in the element
#IMPLIED The attribute does not have to be included
#FIXED value The attribute value is fixed
<!ATTLIST catalog music (pop | classic | unqualified ) #REQUIRED>
Structured Documents KA 23
DTD: Predefined EntitiesDTD: Predefined Entities
Entities are variables used to define common text. Entity references are references to entities.
Most of you will know the HTML entity reference: " ". This "no-breaking-space" entity is used in HTML to insert an extra space in a document. Entities are expanded when a document is parsed by an XML parser.
The following entities are predefined in XML:
Entity References Character< <> >& &" "' '
Structured Documents KA 24
DTD: Own EntitiesDTD: Own Entities<!ENTITY EVTEK ”Espoo Vantaa Instituite of
Technology">
<!ENTITY deg ”°”>
Every where in XML file the note
&EVTEK;
is replaced with string
Espoo Vantaa Instituite of Technology
and<joke>It is 45 ° now in Turkey </joke>
is replaced with string
It is 45° now in Turkey
Structured Documents KA 25
DTD: PCDATA / CDATADTD: PCDATA / CDATA
PCDATA means parsed character data.
PCDATA is text that will be parsed by a parser. Tags inside the text will be treated as markup and entities will be expanded.
CDATA also means character data.
CDATA is text that will NOT be parsed by a parser.
Tags inside the text will NOT be treated as markup Tags inside the text will NOT be treated as markup and entities will not be expanded.and entities will not be expanded.