230 likes | 402 Views
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 10 Points Some Questions for You. What is XML?.
E N D
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
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
An Easy Example (SVG) <?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>
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…
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
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
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>
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.
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 < and & - they have a special significance in XML and may not appear in data unescaped
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
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)
Pop Quiz 5 Minutes Maximum!
Pop Quiz Truth is relative. Let’s vote on the answers.
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.
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
An Easy Example (SVG) <?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>
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.
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)
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.
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
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
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