130 likes | 267 Views
XML – A Quick Introduction. Kerry Raymond (stolen from others). What is XML?. XML = Extensible Mark-up Language XML is a simplified version of SGML (Standard Generalized Mark-up Language) Standardised by W3C. Example XML. <?xml version=“1.0” standalone=“yes” ?> <bibliography>
E N D
XML – A Quick Introduction Kerry Raymond(stolen from others)
What is XML? • XML = Extensible Mark-up Language • XML is a simplified version of SGML (Standard Generalized Mark-up Language) • Standardised by W3C
Example XML <?xml version=“1.0” standalone=“yes” ?> <bibliography> <bibItem id=“horgan96” type=“book”> <title>The End of Science</title> <author>John Horgan</author> <date><year>1996</year></date> <publisher>Little, Brown and Company</publisher> </bibItem> <!-- More bibItem elements. --> </bibliography>
XML mark up • The main parts of an XML document are: • Tag • Element • Attribute
XML mark up - Tag • Tags are the most familiar aspect of XML mark up. • Kinds of tags: • Start tag: <title>. • End tag: </title>. Start and end tags form pairs, with some content between them. • Empty tags (no content): <newLine/>.
XML mark up - Element • The portion of a document between an opening tag and its corresponding closing tag. • Example: • <title>The End of Science</title> • May be empty or have nested content.
XML mark up - Attribute • Attributes belong to the element, rather than to the content of the element. • For example, the attribute “id”: • <bibItem id=“horgan96”> • Attributes are typed. For example: • CDATA (string). • Enumeration (one of a list of values) • ID (a unique identifier) • IDREF (reference to an ID – simple cross-reference)
XML example <?xml version=“1.0” standalone=“yes” ?> <bibliography> <bibItem id=“horgan96” type=“book”> <title>The End of Science</title> <author>John Horgan</author> <date><year>1996</year></date> <publisher>Little, Brown and Company</publisher> </bibItem> <!-- More bibItem elements. --> </bibliography>
Well-formed vs. valid XML has two levels of acceptability: • Well-formed documents. • Minimal level required by XML • Syntactically correct andopening and closing tags are properly nested. • Valid documents. • Document must be well-formed and must satisfy the Document Type Definition in all details.
DTD • A document type is defined by a DTD. The DTD defines: • The tree structure a document of a given type can form. • The positions of elements, attributes and so on in document instances of that type. • The relationships between elements. • Any constraints on each of the elements and attributes.
DTD – Example <!DOCTYPE bibliography [ <!ELEMENT bibliography (bibItem)+> <!ELEMENT bibItem (title, (author | editor)*, date, publisher?)> <!ELEMENT title (#PCDATA)> <!ELEMENT author (#PCDATA)> <!ELEMENT editor (#PCDATA)> <!ELEMENT date (year, month?)> <!ELEMENT year (#PCDATA)> <!ELEMENT month (#PCDATA)> <!ELEMENT publisher (#PCDATA)> <!ATTLIST bibItem id ID #REQUIRED type (article | book | report | video | audio) 'article'> ]>
So is it valid? <?xml version=“1.0” standalone=“yes” ?> <!DOCTYPE bibliography SYSTEM “biblio.dtd”> <bibliography> <bibItem id=“horgan96” type=“book”> <title>The End of Science</title> <author>John Horgan</author> <date><year>1996</year></date> <publisher>Little, Brown and Company</publisher> </bibItem> <!-- More bibItem elements. --> </bibliography>