xml – 1h. xml: contents what is xml? what is “well formed” xml? what is “valid” xml?...

23
XML – 1h

Upload: verity-montgomery

Post on 29-Dec-2015

299 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: XML – 1h. XML: Contents What is XML? What is “Well Formed” XML? What is “Valid” XML? –Document Type Definitions –Scalable Vector Graphics (SVG) XML in

XML – 1h

Page 2: XML – 1h. XML: Contents What is XML? What is “Well Formed” XML? What is “Valid” XML? –Document Type Definitions –Scalable Vector Graphics (SVG) XML in

XML: Contents

• What is XML?

• What is “Well Formed” XML?

• What is “Valid” XML?– Document Type Definitions– Scalable Vector Graphics (SVG)

• XML in 10 Points

• Some Questions for You

Page 3: XML – 1h. XML: Contents What is XML? What is “Well Formed” XML? What is “Valid” XML? –Document Type Definitions –Scalable Vector Graphics (SVG) XML in

What is XML?

XML is a method of putting structured data in a file format. It is not a programming language; it doesn’t DO anything

• An XML document includes text and mark-up; just like HTML.

• XML permits new markup tags to be defined

• XML is rather more strict than HTML

Page 4: XML – 1h. XML: Contents What is XML? What is “Well Formed” XML? What is “Valid” XML? –Document Type Definitions –Scalable Vector Graphics (SVG) XML in

<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "../../svg11-flat.dtd">

<svg width="12cm" height="4cm" viewBox="0 0 1200 400" xmlns="http://www.w3.org/2000/svg" version="1.1">

<circle cx="600" cy="200" r="100" fill="red" stroke="blue" stroke-width="10" />

<rect width="20" height="10"/>

<text>Kilroy was here.</text></svg>

An Easy Example (SVG)

Page 5: XML – 1h. XML: Contents What is XML? What is “Well Formed” XML? What is “Valid” XML? –Document Type Definitions –Scalable Vector Graphics (SVG) XML in

What is “Well Formed” XML?

• 1. Taken as a whole, it matches the production labelled document.

• 2. It meets all the well-formedness constraints given in the W3 specification.

• 3. Each of the parsed entities which is referenced directly or indirectly within the document is well-formed.

…I find this a bit vague…

Page 6: XML – 1h. XML: Contents What is XML? What is “Well Formed” XML? What is “Valid” XML? –Document Type Definitions –Scalable Vector Graphics (SVG) XML in

What is “Well Formed” XML?

• There are Elements, Tags and Character Data, eg:

<person> Alan Turing</person>

• The whole example was a person Element. • Alan Turing was Character Data• <person> was a tag

Page 7: XML – 1h. XML: Contents What is XML? What is “Well Formed” XML? What is “Valid” XML? –Document Type Definitions –Scalable Vector Graphics (SVG) XML in

What is “Well Formed” XML?

• Elements MUST be closed

• Tags may be opening or closing tags of elements

• Alternatively, single tags may be closed by a slash, eg

<img src=“picture.gif” />

• Elements may also be empty

Page 8: XML – 1h. XML: Contents What is XML? What is “Well Formed” XML? What is “Valid” XML? –Document Type Definitions –Scalable Vector Graphics (SVG) XML in

What is “Well Formed” XML?

• Tags have Names and Attributes <p font=“ariel”>

(p was a name; font was an attribute)

• XML is case sensitive, so the name “BR” is regarded as different to “br”

• XML must be well nested: <b><i> Horrors!!! </b></i>

Page 9: XML – 1h. XML: Contents What is XML? What is “Well Formed” XML? What is “Valid” XML? –Document Type Definitions –Scalable Vector Graphics (SVG) XML in

What is “Well Formed” XML?

Names and attributes may contain:

• A…Z, a…z or the characters of ANY alphabet (eg: ي...א )

• Numbers 0…9• Underscore_ • Hyphen- • Period.• That’s it.

Page 10: XML – 1h. XML: Contents What is XML? What is “Well Formed” XML? What is “Valid” XML? –Document Type Definitions –Scalable Vector Graphics (SVG) XML in

What is “Well Formed” XML?

• Tags must be closed.

• Elements may contain elements - nesting must "proper".

• Tags may contain attributes.

• Characters such as < and & must be "escaped" as &lt; and &amp; - they have a special significance in XML and may not appear in data unescaped

Page 11: XML – 1h. XML: Contents What is XML? What is “Well Formed” XML? What is “Valid” XML? –Document Type Definitions –Scalable Vector Graphics (SVG) XML in

What is “Well Formed” XML?

• Must begin with the XML declaration• Must have one unique root element• All start tags must match end-tags• XML tags are case sensitive• All elements must be closed• All elements must be properly nested• All attribute values must be quoted• XML entities must be used for special characters

Page 12: XML – 1h. XML: Contents What is XML? What is “Well Formed” XML? What is “Valid” XML? –Document Type Definitions –Scalable Vector Graphics (SVG) XML in

What is “Well Formed” XML?

• Well-formedness is not the same as Validity (see later)

Amazingly strict rule:

• If a parser encounters a well-formedness violation while parsing a document, it MUST STOP (usually with a useful error message)

Page 13: XML – 1h. XML: Contents What is XML? What is “Well Formed” XML? What is “Valid” XML? –Document Type Definitions –Scalable Vector Graphics (SVG) XML in

Pop Quiz

5 Minutes Maximum!

WHICH OF THESE IS WELL-FORMED?

?<p><b>but soft!</b> what <i>light</i> through…</p>

<stuff><stuff>bits</stuff>&amp;<pieces></stuff>

<tree>I think <tree>that I will never see <tree>a poem</tree> lovely as <tree>a tree</tree> </tree></tree>

<a href="http://www.w3.org">link</a>

<p>a picture<img src="pic.gif"><br>Next line</p>

<p>a picture<img src="pic.gif"/><br></br></p>

<p>We may be sure that within the realm of real numbers x*x<0 is never true.</p>

<a href='http://www.o'reilly.com'>Nutshell Series</a>

And of course and ampersand may be escape-escaped &amp;amp;

Page 14: XML – 1h. XML: Contents What is XML? What is “Well Formed” XML? What is “Valid” XML? –Document Type Definitions –Scalable Vector Graphics (SVG) XML in

Pop Quiz

Truth is relative.

Let’s vote on the answers.

Page 15: XML – 1h. XML: Contents What is XML? What is “Well Formed” XML? What is “Valid” XML? –Document Type Definitions –Scalable Vector Graphics (SVG) XML in

What is “Valid” XML?

If an XML document is well-formed we may ask if it is valid. A valid XML document is one that agrees with the additional rules set out in a DTD (document type definition). The DTD includes:

• ELEMENT: These dictate what kind of child

nodes each element is permitted.• ATTLIST: This indicates what kind of attributes

are permitted.

Page 16: XML – 1h. XML: Contents What is XML? What is “Well Formed” XML? What is “Valid” XML? –Document Type Definitions –Scalable Vector Graphics (SVG) XML in

Scalable Vector Graphics (SVG)

• (In bit-map graphics we specify the colour of each pixel in a grid). This isn’t it.

• Instead, we describe objects to be rendered. • Allows us to produce graphics (boxes, lines,

curves, text) in a scalable format. • Arbitrarily high resolution with constant file size. • Similar to Flash (but Flash has binary format)• Designed and controlled by W3C

Page 17: XML – 1h. XML: Contents What is XML? What is “Well Formed” XML? What is “Valid” XML? –Document Type Definitions –Scalable Vector Graphics (SVG) XML in

<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "../../svg11-flat.dtd">

<svg width="12cm" height="4cm" viewBox="0 0 1200 400" xmlns="http://www.w3.org/2000/svg" version="1.1">

<circle cx="600" cy="200" r="100" fill="red" stroke="blue" stroke-width="10" />

<rect width="20" height="10"/>

<text>Kilroy was here.</text></svg>

An Easy Example (SVG)

Page 18: XML – 1h. XML: Contents What is XML? What is “Well Formed” XML? What is “Valid” XML? –Document Type Definitions –Scalable Vector Graphics (SVG) XML in

Scalable Vector Graphics (SVG)

• Good example of an XML application.

• Standard defined by www.w3.org

• W3C supply a DTD and a description of how each element should be interpreted

• Anyone can produce a processor for the language

• Anyone can produce content.

Page 19: XML – 1h. XML: Contents What is XML? What is “Well Formed” XML? What is “Valid” XML? –Document Type Definitions –Scalable Vector Graphics (SVG) XML in

Narrative and Record Documents

• XML documents normally fall into two categories:

• An XHTML description of a web page starts at the beginning of the document and works its way down to the end

• An XML description of a spreadsheet simply describes the data (there isn’t a beginning or an end)

Page 20: XML – 1h. XML: Contents What is XML? What is “Well Formed” XML? What is “Valid” XML? –Document Type Definitions –Scalable Vector Graphics (SVG) XML in

Narrative and Record Documents

• An XHTML web page is an example of a Narrative document

• A spreadsheet in Microsoft Office Open XML (OOXML) is an example of a record document.

Page 21: XML – 1h. XML: Contents What is XML? What is “Well Formed” XML? What is “Valid” XML? –Document Type Definitions –Scalable Vector Graphics (SVG) XML in

XML in 10 Points

1. XML lets you put structured data in a text file

2. XML looks like HTML but isn't HTML

3. XML is text, but isn't meant to be read

4. XML is a family of technologies

5. XML is verbose, but that is not a problem

Page 22: XML – 1h. XML: Contents What is XML? What is “Well Formed” XML? What is “Valid” XML? –Document Type Definitions –Scalable Vector Graphics (SVG) XML in

XML in 10 Points

6. XML is new, but not that new

7. XML is license-free

8. XML is platform-independent

9. XML is well-supported

10. XML is a W3 standard

11. For what it does, there are no competitors

Page 23: XML – 1h. XML: Contents What is XML? What is “Well Formed” XML? What is “Valid” XML? –Document Type Definitions –Scalable Vector Graphics (SVG) XML in

Recap of Unit

• What is XML?

• What is “Well Formed” XML?

• What is “Valid” XML?– Document Type Definitions– Scalable Vector Graphics (SVG)

• XML in 10 Points

• Some Questions for You