2 xml syntax 2 - 2 xml document structure august 15, 2000 08:00 darmstadt hessen germany fine 25 sw...

30
2 XML Syntax

Upload: clifford-calvin-burns

Post on 04-Jan-2016

219 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 2 XML Syntax 2 - 2 XML Document Structure August 15, 2000 08:00 Darmstadt Hessen Germany fine 25 SW 6 Markup Content

2

XML Syntax

Page 2: 2 XML Syntax 2 - 2 XML Document Structure August 15, 2000 08:00 Darmstadt Hessen Germany fine 25 SW 6 Markup Content

2 - 2

XML Document Structure

<?xml version="1.0"?><weather-report> <date>August 15, 2000</date> <time>08:00</time> <area> <city>Darmstadt</city> <region>Hessen</region> <country>Germany</country> </area> <measurements> <skies>fine</skies> <temperature scale="C">25</temperature> <wind> <direction>SW</direction> <windspeed>6</windspeed> </wind> </measurements></weather-report>

MarkupContent

Page 3: 2 XML Syntax 2 - 2 XML Document Structure August 15, 2000 08:00 Darmstadt Hessen Germany fine 25 SW 6 Markup Content

2 - 3

The Prolog

Prolog<?xml version="1.0"?><weather-report> <date>August 15, 2000</date> <time>08:00</time> <area> <city>Darmstadt</city> <region>Hessen</region> <country>Germany</country> </area> <measurements> <skies>fine</skies> <temperature scale="C">25</temperature> <wind> <direction>SW</direction> <windspeed>6</windspeed> </wind> </measurements></weather-report>

Page 4: 2 XML Syntax 2 - 2 XML Document Structure August 15, 2000 08:00 Darmstadt Hessen Germany fine 25 SW 6 Markup Content

2 - 4

Encoding

Prolog<?xml version="1.0" encoding="UTF-8"?><weather-report> <date>August 15, 2000</date> <time>08:00</time> <area> <city>Darmstadt</city> <region>Hessen</region> <country>Germany</country> </area> <measurements> <skies>fine</skies> <temperature scale="C">25</temperature> <wind> <direction>SW</direction> <windspeed>6</windspeed> </wind> </measurements></weather-report>

Page 5: 2 XML Syntax 2 - 2 XML Document Structure August 15, 2000 08:00 Darmstadt Hessen Germany fine 25 SW 6 Markup Content

2 - 5

Elements and Attributes

<?xml version=“1.0”?><weather-report> <date>August 15, 2000</date> <time>08:00</time> <area> <city>Darmstadt</city> <region>Hessen</region> <country>Germany</country> </area> <measurements> <skies>fine</skies> <temperature scale=“C”>25</temperature> <wind> <direction>SW</direction> <windspeed>6</windspeed> </wind> </measurements></weather-report>

Attribute

Element

Element

Page 6: 2 XML Syntax 2 - 2 XML Document Structure August 15, 2000 08:00 Darmstadt Hessen Germany fine 25 SW 6 Markup Content

2 - 6

XML Names or Identifiers

<book>

<BOOK>

<Book-List>

<WROX:books>

<_book41>

<book.catalog>

Valid names Invalid names

<-book>

<AmountIn$>

<Ben&Jerry>

<41_book>

<XmlData>

<xml_under_windows>

Page 7: 2 XML Syntax 2 - 2 XML Document Structure August 15, 2000 08:00 Darmstadt Hessen Germany fine 25 SW 6 Markup Content

2 - 7

Well-Formedness

<?xml version="1.0"?><weather-report> <date>August 15, 2000</date> <time>08:00</time> <area> <city>Darmstadt</city> <region>Hessen</region> <country>Germany</country> </area> <measurements> <skies>fine</skies> <temperature scale="C">25</temperature> <wind> <direction>SW</direction> <windspeed>6</windspeed> </wind> </measurements></weather-report>

Page 8: 2 XML Syntax 2 - 2 XML Document Structure August 15, 2000 08:00 Darmstadt Hessen Germany fine 25 SW 6 Markup Content

2 - 8

Empty Element

<temperature scale="C"></temperature>

<temperature scale="C"/>

Page 9: 2 XML Syntax 2 - 2 XML Document Structure August 15, 2000 08:00 Darmstadt Hessen Germany fine 25 SW 6 Markup Content

2 - 9

CDATA Sections

<temperature> < 0 </temperature>

<temperature><![CDATA[ <0 ]]> </temperature>

?

Page 10: 2 XML Syntax 2 - 2 XML Document Structure August 15, 2000 08:00 Darmstadt Hessen Germany fine 25 SW 6 Markup Content

2 - 10

Reserved Characters

< &lt;

> &gt;

& &amp;

‘ &apos;

“ &quot;

<temperature> &lt; 0 </temperature>

Page 11: 2 XML Syntax 2 - 2 XML Document Structure August 15, 2000 08:00 Darmstadt Hessen Germany fine 25 SW 6 Markup Content

2 - 11

Character Input

<example>

XML supports international character sets.

This example shows different notations for the number "1":

&#49; (ASCII),

&#x0661; (Devanagari),

&#x0967; (Arabic)

&#x0d67; (Malayalam)

</example>

Page 12: 2 XML Syntax 2 - 2 XML Document Structure August 15, 2000 08:00 Darmstadt Hessen Germany fine 25 SW 6 Markup Content

2 - 12

Comments and Processing Instructions

Comment

<!– This is a comment -->

Processing Instruction

<?xml-stylesheet type="text/css" href="hamlet.css"?>

Page 13: 2 XML Syntax 2 - 2 XML Document Structure August 15, 2000 08:00 Darmstadt Hessen Germany fine 25 SW 6 Markup Content

2 - 13

The Logical Structure of XML Documents

weather-report

dateAugust15,2000

time

08:00

area

city

Darmstadt

region

Hessen

country

Germany

measurements

skies

fine

temperaturescale='C'25

wind

direction

SW

windspeed

6

Page 14: 2 XML Syntax 2 - 2 XML Document Structure August 15, 2000 08:00 Darmstadt Hessen Germany fine 25 SW 6 Markup Content

2 - 14

Valid XML Documents

<?xml version="1.0"?><!DOCTYPE weather-report SYSTEM "weather.dtd"><weather-report> <date>August 15, 2000</date> <time>08:00</time> <area> <city>Darmstadt</city> <region>Hessen</region> <country>Germany</country> </area> <measurements> <skies>fine</skies> <temperature scale=“C”>25</temperature> <wind> <direction>SW</direction> <windspeed>6</windspeed> </wind> </measurements></weather-report>

<!ELEMENT weather-report (date, time, area,measurements)><!ELEMENT date (#PCDATA)><!ELEMENT time (#PCDATA)><!ELEMENT area ((city,region,country) | (x,y))><!ELEMENT city (#PCDATA)><!ELEMENT region (#PCDATA)><!ELEMENT country (#PCDATA)><!ELEMENT x (#PCDATA)><!ELEMENT y (#PCDATA)><!ELEMENT measurements ((skies | temperature | humidity | visibility | wind)+)><!ELEMENT skies (#PCDATA)><!ELEMENT temperature (#PCDATA)><!ELEMENT humidity (#PCDATA)><!ELEMENT visibility (#PCDATA)><!ELEMENT wind (direction,windspeed)><!ELEMENT direction (#PCDATA)><!ELEMENT windspeed (#PCDATA)><!ATTLIST temperature scale CDATA #IMPLIED>

weather.dtd

Page 15: 2 XML Syntax 2 - 2 XML Document Structure August 15, 2000 08:00 Darmstadt Hessen Germany fine 25 SW 6 Markup Content

2 - 15

Document Type Declarationexternal

Inline DTD

<?xml version="1.0"?><!DOCTYPE weather-report[<!ELEMENT weather-report (date,time,area,measurements)><!ELEMENT date (#PCDATA)> ....]><weather-report> <date> ....

<?xml version="1.0"?><!DOCTYPE weather-report SYSTEM "weather.dtd">

Page 16: 2 XML Syntax 2 - 2 XML Document Structure August 15, 2000 08:00 Darmstadt Hessen Germany fine 25 SW 6 Markup Content

2 - 16

Processing XML Documents

DTD

Document Tree

<?xml?><weather-report> <date>August 15, 2000</date> <time>08:00 </time> <area> <city>Darmstadt</city> <temperature scale=“C”>25</temperature>

Parser

Page 17: 2 XML Syntax 2 - 2 XML Document Structure August 15, 2000 08:00 Darmstadt Hessen Germany fine 25 SW 6 Markup Content

2 - 17

Element Type Declaration

<!ELEMENT weather-report (date, time, area, measurements)><!ELEMENT date (#PCDATA)><!ELEMENT time (#PCDATA)><!ELEMENT area ((city,region,country) | (x,y))><!ELEMENT city (#PCDATA)><!ELEMENT region (#PCDATA)><!ELEMENT country (#PCDATA)><!ELEMENT x (#PCDATA)><!ELEMENT y (#PCDATA)><!ELEMENT measurements ((skies | temperature | humidity | visibility | wind)+)><!ELEMENT skies (#PCDATA)><!ELEMENT temperature (#PCDATA)><!ELEMENT humidity (#PCDATA)><!ELEMENT visibility (#PCDATA)>

...

Element Types

ContentModels

Page 18: 2 XML Syntax 2 - 2 XML Document Structure August 15, 2000 08:00 Darmstadt Hessen Germany fine 25 SW 6 Markup Content

2 - 18

Element Content Models

EMPTY no content ANY no constraints on content | choice list

, sequence Cardinality

exactly one+ one or more? zero or one* zero or more

() grouping (#PCDATA) characters (#PCDATA | ...) * characters or elements

("mixed content")

Page 19: 2 XML Syntax 2 - 2 XML Document Structure August 15, 2000 08:00 Darmstadt Hessen Germany fine 25 SW 6 Markup Content

2 - 19

<!ATTLIST temperature scale CDATA #IMPLIED>

Attribute Declaration

Element Type

AttributeName

AttributeType

DefaultValue

<!ATTLIST temperature scale CDATA #REQUIRED><!ATTLIST temperature scale (C| F) #REQUIRED><!ATTLIST temperature scale (C| F) "C" ><!ATTLIST temperature scale CDATA #FIXED "C">

Page 20: 2 XML Syntax 2 - 2 XML Document Structure August 15, 2000 08:00 Darmstadt Hessen Germany fine 25 SW 6 Markup Content

2 - 20

Attribute Type and Default Value

Default Value #REQUIRED value must be provided #IMPLIED no constraints "string" default value #FIXED default is only value

Attribute Type CDATA string value ID attribute value unique

per document IDREF(S) attribute value matches ID value (enumeration) restricts to values

Page 21: 2 XML Syntax 2 - 2 XML Document Structure August 15, 2000 08:00 Darmstadt Hessen Germany fine 25 SW 6 Markup Content

2 - 21

Attribute Types ID and IDREF(S)

<Pers-List>

<Person perID = "A-111">

<Name>Smith</Name>....

</Person>

<Person perID = "A-112">

<Name>Miller</Name> ....

</Person>

....

</Pers-List>

<!ELEMENT Person (Name, Address?, Email*, ...)>

<!ATTLIST Person perID ID #REQUIRED>

<!ELEMENT Team EMPTY>

<!ATTLIST Team members IDREFS #REQUIRED>

<Team members = "A-111 A-112 B-111 ..."/>

Page 22: 2 XML Syntax 2 - 2 XML Document Structure August 15, 2000 08:00 Darmstadt Hessen Germany fine 25 SW 6 Markup Content

2 - 22

Element or Attribute?

<measurements> <skies>fine</skies> <temperature scale="C">25</temperature> .... </measurements>

<measurements> <skies>fine</skies> <temperature>25</temperature> <scale>C</scale> .... </measurements>

Page 23: 2 XML Syntax 2 - 2 XML Document Structure August 15, 2000 08:00 Darmstadt Hessen Germany fine 25 SW 6 Markup Content

2 - 23

Entities and References

Entity Declaration in the DTD

<!DOCTYPE text[<!ENTITY sag "Software AG"><!ENTITY sagtext SYSTEM "http://www.softwareag.com/std.txt">]>

Referencing in the document

<text>&sag; is proud to announce ... &sagtext;</text>

Page 24: 2 XML Syntax 2 - 2 XML Document Structure August 15, 2000 08:00 Darmstadt Hessen Germany fine 25 SW 6 Markup Content

2 - 24

Structuring Documents

<!DOCTYPE purchase-order[<!ENTITY Head SYSTEM "Headsection.xml"> <!ENTITY PositionsPC SYSTEM "Positions/PC1.xml"><!ENTITY PositionsMonitor SYSTEM "http://monitors.de/m2.xml">]><purchase-order> <customer-data> &Head; </customer-data> <order> <position> &PositionsPC; </position> <position> &PositionsMonitor; </position> </order></purchase-order>

Page 25: 2 XML Syntax 2 - 2 XML Document Structure August 15, 2000 08:00 Darmstadt Hessen Germany fine 25 SW 6 Markup Content

2 - 25

Parameter Entities

<!DOCTYPE example

[

<!ENTITY % example-entity "<!ELEMENT example (#PCDATA)>">

%example-entity;

]>

<example>

</example>

Page 26: 2 XML Syntax 2 - 2 XML Document Structure August 15, 2000 08:00 Darmstadt Hessen Germany fine 25 SW 6 Markup Content

2 - 26

<!ENTITY % block "paragraph | listing | picture | box">

<!ELEMENT book (chapter+)>

<!ELEMENT chapter (heading, (%block;)*, section+)>

<!ELEMENT section (heading, (%block;)*, subsection*)>

<!ELEMENT subsection (heading, (%block;)+)>

<!ELEMENT paragraph (#PCDATA)>

...

Internal Parameter Entities

Page 27: 2 XML Syntax 2 - 2 XML Document Structure August 15, 2000 08:00 Darmstadt Hessen Germany fine 25 SW 6 Markup Content

2 - 27

<ENTITY % tab-model SYSTEM "table-model.dtd">

%tab-model;

<!ENTITY % block "paragraph | listing | picture | box | table">

<!ELEMENT book (chapter+)>

<!ELEMENT chapter (heading, (%block;)*, section+)>

<!ELEMENT section (heading, (%block;)*, subsection*)>

<!ELEMENT subsection (heading, (%block;)+)>

<!ELEMENT paragraph (#PCDATA)>

...

External Parameter Entities

Page 28: 2 XML Syntax 2 - 2 XML Document Structure August 15, 2000 08:00 Darmstadt Hessen Germany fine 25 SW 6 Markup Content

2 - 28

Entities and Notations

Integration of "Non-XML-data"

<!ELEMENT logo EMPTY>

<!ATTLIST logo image ENTITY #REQUIRED>

<logo image = "saglogo"/>

<!ENTITY saglogo SYSTEM "http://www.softwareag.com/logo1.gif"NDATA GIF>

<!NOTATION GIF SYSTEM "gifmagic.exe">

Page 29: 2 XML Syntax 2 - 2 XML Document Structure August 15, 2000 08:00 Darmstadt Hessen Germany fine 25 SW 6 Markup Content

2 - 29

Conditional DTD Sections

<!ENTITY % design "INCLUDE">

<!ENTITY % finished "IGNORE" >

<![%design; [<!ELEMENT comment (#PCDATA)>]]

<![%finished; [<!ELEMENT comment EMPTY>]]

<!ELEMENT comment (#PCDATA)>

<![IGNORE[

<!ELEMENT comment (#PCDATA)>

]]>

<![INCLUDE[

<!ELEMENT comment (#PCDATA)>

]]>

Page 30: 2 XML Syntax 2 - 2 XML Document Structure August 15, 2000 08:00 Darmstadt Hessen Germany fine 25 SW 6 Markup Content

2 - 30

Summary

XML is a meta markup language standardized by the W3C. XML documents contain self-descriptive structured data. An XML document is well-formed if it meets a few formal criteria. An XML document is valid if it meets the structure rules of a

Document Type Definition (DTD). The DTD syntax contains grammatical rules for the definition of

elements, attributes, and entities.