xml – a quick introduction
Post on 19-Jan-2016
35 Views
Preview:
DESCRIPTION
TRANSCRIPT
XML – A Quick Introduction
Kerry Raymond(stolen from others)
© 2000, DSTC Pty Ltd
2
What is XML?
• XML = Extensible Mark-up Language
• XML is a simplified version of SGML (Standard Generalized Mark-up Language)
• Standardised by W3C
© 2000, DSTC Pty Ltd
3
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>
© 2000, DSTC Pty Ltd
4
XML mark up
• The main parts of an XML document are:– Tag– Element– Attribute
© 2000, DSTC Pty Ltd
5
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/>.
© 2000, DSTC Pty Ltd
6
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.
© 2000, DSTC Pty Ltd
7
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)
© 2000, DSTC Pty Ltd
8
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>
© 2000, DSTC Pty Ltd
9
Well-formed vs. valid
XML has two levels of acceptability:• Well-formed documents.
– Minimal level required by XML
– Syntactically correct and opening and closing tags are properly nested.
• Valid documents.– Document must be well-formed and must satisfy
the Document Type Definition in all details.
© 2000, DSTC Pty Ltd
10
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.
© 2000, DSTC Pty Ltd
11
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'>]>
© 2000, DSTC Pty Ltd
12
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>
top related