1 xmlintroduction noea / pqc 2007 (rev. fen) xml introduction what is xml? examples of xml use a xml...

37
1 XML 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

Upload: jessica-bates

Post on 12-Jan-2016

237 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 1 XMLIntroduction NOEA / PQC 2007 (rev. fen) XML introduction What is XML? Examples of XML use A XML document Structuring data with tags More about tags

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

Page 2: 1 XMLIntroduction 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

Page 3: 1 XMLIntroduction NOEA / PQC 2007 (rev. fen) XML introduction What is XML? Examples of XML use A XML document Structuring data with tags More about tags

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

Page 4: 1 XMLIntroduction NOEA / PQC 2007 (rev. fen) XML introduction What is XML? Examples of XML use A XML document Structuring data with tags More about tags

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

Page 5: 1 XMLIntroduction NOEA / PQC 2007 (rev. fen) XML introduction What is XML? Examples of XML use A XML document Structuring data with tags More about tags

5XML Introduction NOEA / PQC 2007 (rev. fen)

XML Documents can be parsed using a browser:

Page 6: 1 XMLIntroduction NOEA / PQC 2007 (rev. fen) XML introduction What is XML? Examples of XML use A XML document Structuring data with tags More about tags

6XML Introduction NOEA / PQC 2007 (rev. fen)

…and created and edited using a text editor:

But be careful

Page 7: 1 XMLIntroduction NOEA / PQC 2007 (rev. fen) XML introduction What is XML? Examples of XML use A XML document Structuring data with tags More about tags

7XML Introduction NOEA / PQC 2007 (rev. fen)

…or using a better tool:

Page 8: 1 XMLIntroduction NOEA / PQC 2007 (rev. fen) XML introduction What is XML? Examples of XML use A XML document Structuring data with tags More about tags

8XML Introduction NOEA / PQC 2007 (rev. fen)

Data descripes itself

• What is descriped here:

Page 9: 1 XMLIntroduction NOEA / PQC 2007 (rev. fen) XML introduction What is XML? Examples of XML use A XML document Structuring data with tags More about tags

9XML Introduction NOEA / PQC 2007 (rev. fen)

And what is this?

?

Page 10: 1 XMLIntroduction NOEA / PQC 2007 (rev. fen) XML introduction What is XML? Examples of XML use A XML document Structuring data with tags More about tags

10XML Introduction NOEA / PQC 2007 (rev. fen)

Sometimes a commentary is helpful

Page 11: 1 XMLIntroduction NOEA / PQC 2007 (rev. fen) XML introduction What is XML? Examples of XML use A XML document Structuring data with tags More about tags

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.

Page 12: 1 XMLIntroduction NOEA / PQC 2007 (rev. fen) XML introduction What is XML? Examples of XML use A XML document Structuring data with tags More about tags

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

Page 13: 1 XMLIntroduction NOEA / PQC 2007 (rev. fen) XML introduction What is XML? Examples of XML use A XML document Structuring data with tags More about tags

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

Page 14: 1 XMLIntroduction NOEA / PQC 2007 (rev. fen) XML introduction What is XML? Examples of XML use A XML document Structuring data with tags More about tags

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

Page 15: 1 XMLIntroduction NOEA / PQC 2007 (rev. fen) XML introduction What is XML? Examples of XML use A XML document Structuring data with tags More about tags

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

Page 16: 1 XMLIntroduction NOEA / PQC 2007 (rev. fen) XML introduction What is XML? Examples of XML use A XML document Structuring data with tags More about tags

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

Page 17: 1 XMLIntroduction NOEA / PQC 2007 (rev. fen) XML introduction What is XML? Examples of XML use A XML document Structuring data with tags More about tags

17XML Introduction NOEA / PQC 2007 (rev. fen)

Format with a stylesheet

XML document

Stylesheet (XSL)

XML with stylesheet

Page 18: 1 XMLIntroduction NOEA / PQC 2007 (rev. fen) XML introduction What is XML? Examples of XML use A XML document Structuring data with tags More about tags

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

Page 19: 1 XMLIntroduction NOEA / PQC 2007 (rev. fen) XML introduction What is XML? Examples of XML use A XML document Structuring data with tags More about tags

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

Page 20: 1 XMLIntroduction NOEA / PQC 2007 (rev. fen) XML introduction What is XML? Examples of XML use A XML document Structuring data with tags More about tags

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

Page 21: 1 XMLIntroduction NOEA / PQC 2007 (rev. fen) XML introduction What is XML? Examples of XML use A XML document Structuring data with tags More about tags

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 _)

Page 22: 1 XMLIntroduction NOEA / PQC 2007 (rev. fen) XML introduction What is XML? Examples of XML use A XML document Structuring data with tags More about tags

22XML Introduction NOEA / PQC 2007 (rev. fen)

The structure can be expanded

Page 23: 1 XMLIntroduction NOEA / PQC 2007 (rev. fen) XML introduction What is XML? Examples of XML use A XML document Structuring data with tags More about tags

23XML Introduction NOEA / PQC 2007 (rev. fen)

Root

Parent

Child

Siblings

XML documents is alway a tree structure

Page 24: 1 XMLIntroduction NOEA / PQC 2007 (rev. fen) XML introduction What is XML? Examples of XML use A XML document Structuring data with tags More about tags

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

Page 25: 1 XMLIntroduction NOEA / PQC 2007 (rev. fen) XML introduction What is XML? Examples of XML use A XML document Structuring data with tags More about tags

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.

Page 26: 1 XMLIntroduction NOEA / PQC 2007 (rev. fen) XML introduction What is XML? Examples of XML use A XML document Structuring data with tags More about tags

26XML Introduction NOEA / PQC 2007 (rev. fen)

Components in a XML Documents

• XML Declaration• Elements• Attributes• Entities• Commentary

<?declaration?><element attribute="value"> &lt; is a character reference. It is also an entity <!-- Comment: &lt; is the less-than symbol --></element>

Page 27: 1 XMLIntroduction NOEA / PQC 2007 (rev. fen) XML introduction What is XML? Examples of XML use A XML document Structuring data with tags More about tags

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"?>

Page 28: 1 XMLIntroduction NOEA / PQC 2007 (rev. fen) XML introduction What is XML? Examples of XML use A XML document Structuring data with tags More about tags

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

Page 29: 1 XMLIntroduction NOEA / PQC 2007 (rev. fen) XML introduction What is XML? Examples of XML use A XML document Structuring data with tags More about tags

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)

Page 30: 1 XMLIntroduction NOEA / PQC 2007 (rev. fen) XML introduction What is XML? Examples of XML use A XML document Structuring data with tags More about tags

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. < &lt;)

• 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)

Page 31: 1 XMLIntroduction NOEA / PQC 2007 (rev. fen) XML introduction What is XML? Examples of XML use A XML document Structuring data with tags More about tags

31XML Introduction NOEA / PQC 2007 (rev. fen)

Examples of entities

• Character entity:– Character: >– Entity reference: &gt; or &#62;– Usage: <formula> x &gt; 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>

Page 32: 1 XMLIntroduction NOEA / PQC 2007 (rev. fen) XML introduction What is XML? Examples of XML use A XML document Structuring data with tags More about tags

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">]>

Page 33: 1 XMLIntroduction NOEA / PQC 2007 (rev. fen) XML introduction What is XML? Examples of XML use A XML document Structuring data with tags More about tags

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 -->

Page 34: 1 XMLIntroduction NOEA / PQC 2007 (rev. fen) XML introduction What is XML? Examples of XML use A XML document Structuring data with tags More about tags

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

Page 35: 1 XMLIntroduction NOEA / PQC 2007 (rev. fen) XML introduction What is XML? Examples of XML use A XML document Structuring data with tags More about tags

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.....

Page 36: 1 XMLIntroduction NOEA / PQC 2007 (rev. fen) XML introduction What is XML? Examples of XML use A XML document Structuring data with tags More about tags

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?

Page 37: 1 XMLIntroduction NOEA / PQC 2007 (rev. fen) XML introduction What is XML? Examples of XML use A XML document Structuring data with tags More about tags

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