1 xmlintroduction noea / pqc 2007 (rev. fen) xml introduction what is xml? examples of xml use a xml...
TRANSCRIPT
1XML Introduction NOEA / PQC 2007 (rev. fen)
XML introduction
• What is XML?• Examples of XML use• A XML document• Structuring data with tags• More about tags
2XML Introduction NOEA / PQC 2007 (rev. fen)
What is XML? • eXtensible Markup Language• Is a markup language for making other markup languages
XML is a meta language• Examples of markup languages :
– HTML– XHTML (a xml version of html)– RTF– (S)GML– Except from XHTML, these are not xml
• With XML, tags specific to the domain can be defined.
Sounds complicated?You can make your own tags to describe data with in XML
3XML Introduction NOEA / PQC 2007 (rev. fen)
In Other Words…
• XML is a meta language - a language to define other languages in
• You define the language using XML as meta language• Your XML language describes the data structure of your
domain
4XML Introduction NOEA / PQC 2007 (rev. fen)
XML describes structure and semantics, not formatting
<BODY> <DT> Hot Cop <DD> by Jacques Morali, Henri Belolo, and Victor Willis <UL> <LI > Jacques Morali <LI > PolyGram Records <LI > 6:20 <LI > 1978 <LI > Village People </UL></BODY>
HTML mixes data and layout
XML tells nothing
about layout
5XML Introduction NOEA / PQC 2007 (rev. fen)
XML Documents can be parsed using a browser:
6XML Introduction NOEA / PQC 2007 (rev. fen)
…and created and edited using a text editor:
But be careful
7XML Introduction NOEA / PQC 2007 (rev. fen)
…or using a better tool:
8XML Introduction NOEA / PQC 2007 (rev. fen)
Data descripes itself
• What is descriped here:
9XML Introduction NOEA / PQC 2007 (rev. fen)
And what is this?
?
10XML Introduction NOEA / PQC 2007 (rev. fen)
Sometimes a commentary is helpful
11XML Introduction NOEA / PQC 2007 (rev. fen)
Data exchange between applications
• XML is a non propritary format• Meaning it is not owned by somebody or
belongs to certain application• It is easy for humans to read and
write xml documents• It can be written in a simple editor• It can easily be send by the network
in a secure or unsecure format
• Note: But xml is not smart, if you send big data amounts. Why?
In contrast to doc (word, word
perfect...), pdf, mdb, qt, drw, etc.
12XML Introduction NOEA / PQC 2007 (rev. fen)
XML standards
• DTD (Document Type Definition) Definition of a XML-language. The old way.
• XSCHEMADefinition of a XML-language. The new way.
• XPATHTraversing / navigation in a xml-document.
• XSL(T)Stylesheet. Used for converting from one format to another. For instance from xml to html.
• XSL-FOFormatting stylesheets. Used for documents in a non markup langauge, e.g. pdf-document og svg-documents
Not an XML-language it
selves
13XML Introduction NOEA / PQC 2007 (rev. fen)
Examples of use of xml
• Data exchange• Handling of multiple client types on www• SOAP – Simple Object Access Protocol
Services are descriped with xml. Data is transported in a xml-document. Example: WebServices
• RSS feeds – See for instance Visual Studio• Configuration files e.g. web.config
14XML Introduction NOEA / PQC 2007 (rev. fen)
Use of XML
Ap p lik a tio n s s er v er
D atab as e
X M L d ata
R em o te O b jec tS O AP
R em o te O b jec tS O AP
Ap p lik a tio n s s er v er
D atab as e
X M L d ata
X M L d ata
R em o te O b jec tS O AP
X S LT
W M L HT M L X M L
W eb s er v er
15XML Introduction NOEA / PQC 2007 (rev. fen)
Examples of xml-languages
• ODFOpen Document Format
• OOXMLOpen Office XML
• CMLChemical Markup Language
• OFXOpen Financial eXchange
• SVGScalable Vector Graphics
• OSDOpen Software Description
• XHTMLHTML i xml udgave
16XML Introduction NOEA / PQC 2007 (rev. fen)
XML can also be viewed in Mozilla
Demo: Hello World
XML might be written NotePad
XML can be viewed in a msie browser
17XML Introduction NOEA / PQC 2007 (rev. fen)
Format with a stylesheet
XML document
Stylesheet (XSL)
XML with stylesheet
18XML Introduction NOEA / PQC 2007 (rev. fen)
Example: TV schedule
By this example the following is discussed:• Good xml-style• Structure and syntax in xml-documents• Terminology and definitions• XML tree
19XML Introduction NOEA / PQC 2007 (rev. fen)
Find candidates for tags
As in database modelling:– By finding objects / entities in the user domain– Find keywords in the problem description– Look at existing output.
E.g. Look in TV section of the paper.– Map from an existing database. – ...
Keywords:- Title - Description- Station - Category- Date - Production year- Start time - Stars- Duration
20XML Introduction NOEA / PQC 2007 (rev. fen)
StruktureringEt XML-dokuments opbygning:
– Dokumentet er hierarkisk opbygget i en træstruktur– Giver nogle fordele, men også ulemper ift. relations databaser– Der er eet rod-element, som indeholder alt det andet– Declarations <?..?> er ikke en del af træet– Træet kan indeholde et vilkårligt antal knuder
DeclarationRod
element
Underelement
21XML Introduction NOEA / PQC 2007 (rev. fen)
A little about xml-style• As in programming you should choose a strict way of writing:• How shall naming be? Use _ or capital first letter?
Or only capitals?• When to use text between start and end tags? and when to use
attributes?• Else: Use w3.org's way (only non capitals and _)
22XML Introduction NOEA / PQC 2007 (rev. fen)
The structure can be expanded
23XML Introduction NOEA / PQC 2007 (rev. fen)
Root
Parent
Child
Siblings
XML documents is alway a tree structure
24XML Introduction NOEA / PQC 2007 (rev. fen)
Nesting of elements
• Terminology:
– Child elements – elements that are contained in other elements
– Parent elements – elements that contains other elements
– Sibling elements – elements that have the same parent element
25XML Introduction NOEA / PQC 2007 (rev. fen)
XML Syntax
• “Syntax” refers to the rules of the language• Syntax is necessary for making documents written in the
language consistent• Programs that interpret documents assume that the
rules of the syntax is satisfied, else it can't be guarantied that the document is interpreted correctly.
26XML Introduction NOEA / PQC 2007 (rev. fen)
Components in a XML Documents
• XML Declaration• Elements• Attributes• Entities• Commentary
<?declaration?><element attribute="value"> < is a character reference. It is also an entity <!-- Comment: < is the less-than symbol --></element>
27XML Introduction NOEA / PQC 2007 (rev. fen)
Components: XML Declaration
• XML Declaration:– Tells that the document is a XML document and other optional
information's– The XML declaration is always the first line in a XML document– Attributes that can be used in the XML Declaration:
• version• encoding• standalone
<?xml version=“1.0” Encoding=“UTF-8” standalone=“yes”?><?xml-stylesheet type="text/xsl" href="HelloWorld_v1.xsl"?>
28XML Introduction NOEA / PQC 2007 (rev. fen)
Components: XML Elements
• Elements:– Used for describing data. Contains of:
• start tag• contents• end tag
– Examples: <element>Content</element>– The “root” element in a document is the outer most element
and contains all other elements in the documents. A document can only contain one root element
• A element without content is called a “empty element”, but is still an element– Example: <empty_element attribute="value"/>
In real world, html: <input> and <img> are empty elements
29XML Introduction NOEA / PQC 2007 (rev. fen)
Components: XML Attributes
• Attributes helps to describe XML elements• Attributes are always a part of the start tag• Attributes is also known as “name-value par”
Instead of<SHOW>... <START_TIME> 3:45 </START_TIME>...</SHOW>
you could write<SHOW start_time="3:45“>...</SHOW>
It’s your design decision if something is
an element or an attribute of some
element (as in other data modelling
processes)
30XML Introduction NOEA / PQC 2007 (rev. fen)
Components: XML Entities
• Two types of entities:– General – Can contain information stored in a XML document– Parameters – used in DTD for referring an element-group
• Three types of general entities:– Character – used instead of special characters(e.g. < <)
• Starts with ‘&’ and ends with ‘;’– Content – used for reuse of blocks of text (variables)– Unparsed – used for binary or non-textual data (e.g. pictures)
31XML Introduction NOEA / PQC 2007 (rev. fen)
Examples of entities
• Character entity:– Character: >– Entity reference: > or >– Usage: <formula> x > y </formula>
• Content entity:– Declaration: <!ENTITY address “123 Main St”> – Usage: <ship_address> &address; <ship_address>
• Unparsed entity:– Declaration: <!ENTITY image SYSTEM “sunset.gif” NDATA GIF>
– Usage: <picture> &aimage; </picture>
32XML Introduction NOEA / PQC 2007 (rev. fen)
Defining entities
• An entity is a name and an associated value• The value may be:
– A special character code– A piece of text– A filename
• Entity definitions in DTD (next session) or in the xml-document it selves:
<!DOCTYPE DOCUMENT [<!ENTITY signature "Kys og Klap">]>
33XML Introduction NOEA / PQC 2007 (rev. fen)
Components: Comments
• Comments are ignored by the xml interpreter• The content of the commentary is surrounded by
<!–- and -->• Example: <!-- This is a comment -->
34XML Introduction NOEA / PQC 2007 (rev. fen)
Well-Formed XML Documents
• A “well-formed” document satisfies the syntax rules of XML:– A XML document contains one root element– All elements must have a start and an end tag, except empty
elements– Elements must be nested correctly– All attributes must have a value– Attributes can only be defined in start tags and must be
unique– Element names are case-sensitive– Special characters must be written as entities– Names of elements must start with a letter or underscore and
may only contain letters, numbers, hyphen, period and underscore
35XML Introduction NOEA / PQC 2007 (rev. fen)
Parser
• A xml parser is a program, that as minimum can validate whether a xml document is well formed.
• Most parsers are also able to validate a xml document according to some xml language defined by a DTD or Schema.
• A quick way is a view the document in a browser: MSIE5.5 +, Netscape 6+ or Mozilla/Firefox.
• The most common parsers is properly Xerces (java) and MSXML (ms).
• And you can write your own.....
36XML Introduction NOEA / PQC 2007 (rev. fen)
Mozilla 1.7
Parsing with the browser
• We have seen when it goes well. Here is a document with errors errors
SourceInternet Explorer 6.0
What is the error?
37XML Introduction NOEA / PQC 2007 (rev. fen)
Reading stuff i.e.• Books:
– XML and Web Services, Ron Schemlzer et al., Sams – XML- How To Program, Deitel et al., Prentice Hall– An Introduction to XML and Web Technologies, Anders Møller and
Michael Schwartzbach, Addison-Wesley• Links:
– www.zvon.org References and tutorials
– www.w3.orgStandards
– www.w3school.comTutorials
– www.topxml.comDeveloper forum
– www.ibiblio.org/xmlXML bible
– http://www.brics.dk/ixwt/Web site accompanying the book by Møller&Schwartzbach