xml - dtd. the building blocks of xml documents elements, tags, attributes, entities, pcdata, and...

14
XML - DTD

Upload: brianna-blair

Post on 29-Dec-2015

220 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: XML - DTD. The building blocks of XML documents Elements, Tags, Attributes, Entities, PCDATA, and CDATA

XML - DTD

Page 2: XML - DTD. The building blocks of XML documents Elements, Tags, Attributes, Entities, PCDATA, and CDATA

The building blocks of XML documents

• Elements,

• Tags,

• Attributes,

• Entities,

• PCDATA, and

• CDATA

Page 3: XML - DTD. The building blocks of XML documents Elements, Tags, Attributes, Entities, PCDATA, and CDATA

Elements

• main building blocks of both XML and HTML documents

• HTML elements are "body" and "table”• XML elements could be "note" and "message“• can contain text, other elements, or be empty• Examples of empty HTML elements are "hr", "br"

and "img".

Page 4: XML - DTD. The building blocks of XML documents Elements, Tags, Attributes, Entities, PCDATA, and CDATA

Tags

• Tags are used to markup elements.

• A starting tag like <element_name> mark up the beginning of an element

• A body element: <body>body text in between</body>.

• A message element: <message>some message in between</message>

Page 5: XML - DTD. The building blocks of XML documents Elements, Tags, Attributes, Entities, PCDATA, and CDATA

Attributes

• Attributes provide extra information about elements• placed inside the start tag of an element• Attributes come in name/value pairs• E.g. <img src="computer.gif" />• the attribute is "src". • value of the attribute is "computer.gif". • Since the element itself is empty it is

closed by a " /"

Page 6: XML - DTD. The building blocks of XML documents Elements, Tags, Attributes, Entities, PCDATA, and CDATA

PCDATA

• PCDATA means parsed character data• character data - the text found between the

start tag and the end tag of an XML element.

• PCDATA is text that will be parsed by a parser

• Tags inside the text will be treated as markup and entities will be expanded. 

Page 7: XML - DTD. The building blocks of XML documents Elements, Tags, Attributes, Entities, PCDATA, and CDATA

CDATA

• 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 and entities will not be expanded.

Page 8: XML - DTD. The building blocks of XML documents Elements, Tags, Attributes, Entities, PCDATA, and CDATA

Entities• Entities are variables used to define

common text

• Entity references are references to entities

• the HTML entity reference: "&nbsp;" 

• Entities are expanded when a document is parsed by an XML parser.

&lt; <

&gt; >

&amp; &

&quot; “

&apos; ‘

The following entities are predefined in XML:

Page 9: XML - DTD. The building blocks of XML documents Elements, Tags, Attributes, Entities, PCDATA, and CDATA

Declaring an Element

• elements are declared with an element declaration

• <!ELEMENT element-name (element-content)>• Empty elements

– <!ELEMENT img (EMPTY)>

• Elements with data– <!ELEMENT element-name (#CDATA)> – or <!ELEMENT element-name (#PCDATA)> – or <!ELEMENT element-name (ANY)>– example:<!ELEMENT note (#PCDATA)>

Page 10: XML - DTD. The building blocks of XML documents Elements, Tags, Attributes, Entities, PCDATA, and CDATA

Elements with children (sequences)

• <!ELEMENT note (to,from,heading,body)> <!ELEMENT to (#CDATA)>

• <!ELEMENT from (#CDATA)> • <!ELEMENT heading (#CDATA)> • <!ELEMENT body (#CDATA)>

Page 11: XML - DTD. The building blocks of XML documents Elements, Tags, Attributes, Entities, PCDATA, and CDATA

Wrapping

• <?xml version="1.0"?>• <!DOCTYPE note [ <!ELEMENT note

(to,from,heading,body)> <!ELEMENT to (#CDATA)> • <!ELEMENT from (#CDATA)> • <!ELEMENT heading (#CDATA)> • <!ELEMENT body (#CDATA)> ]>

• <note> • <to>Tove</to> • <from>Jani</from> • <heading>Reminder</heading> • <body>Don't forget me this weekend</body> • </note>

Page 12: XML - DTD. The building blocks of XML documents Elements, Tags, Attributes, Entities, PCDATA, and CDATA

Declaring Attributes

• attributes are declared with an ATTLIST declaration

• <!ATTLIST element-name attribute-name attribute-type default-value>

• DTD example: – <!ELEMENT square EMPTY> – <!ATTLIST square width CDATA "0">

• XML example: – <square width="100"></square>

Page 13: XML - DTD. The building blocks of XML documents Elements, Tags, Attributes, Entities, PCDATA, and CDATA

TV Scedule DTD

<!DOCTYPE TVSCHEDULE [  <!ELEMENT TVSCHEDULE (CHANNEL+)><!ELEMENT CHANNEL (BANNER, DAY+)><!ELEMENT BANNER (#PCDATA)><!ELEMENT DAY ((DATE, HOLIDAY) | (DATE, PROGRAMSLOT+))+><!ELEMENT HOLIDAY (#PCDATA)><!ELEMENT DATE (#PCDATA)><!ELEMENT PROGRAMSLOT (TIME, TITLE, DESCRIPTION?)><!ELEMENT TIME (#PCDATA)><!ELEMENT TITLE (#PCDATA)> <!ELEMENT DESCRIPTION (#PCDATA)><!ATTLIST TVSCHEDULE NAME CDATA #REQUIRED><!ATTLIST CHANNEL CHAN CDATA #REQUIRED><!ATTLIST PROGRAMSLOT VTR CDATA #IMPLIED><!ATTLIST TITLE RATING CDATA #IMPLIED><!ATTLIST TITLE LANGUAGE CDATA #IMPLIED> ]>

Page 14: XML - DTD. The building blocks of XML documents Elements, Tags, Attributes, Entities, PCDATA, and CDATA