22
ITApps 2011/12 1/25 XML XML Session 1: Session 1: Introduction to Introduction to XML XML

ITApps 2011/12 1/25 XML Session 1: Introduction to XML

Embed Size (px)

Citation preview

Page 1: ITApps 2011/12 1/25 XML Session 1: Introduction to XML

ITApps 2011/12 1/25

XMLXML

Session 1:Session 1:Introduction to XMLIntroduction to XML

Page 2: ITApps 2011/12 1/25 XML Session 1: Introduction to XML

2/25ITApps 2011/12

XML – Learning ObjectivesXML – Learning Objectives Upon completion of the module you will be Upon completion of the module you will be

able to:able to: Learn how an XML document is defined to be Learn how an XML document is defined to be

well-formed and valid (by using a DTD) and well-formed and valid (by using a DTD) and that anything else isn't an XML document. that anything else isn't an XML document.

Create markup pages of data using tags and Create markup pages of data using tags and attributes.attributes.

Know the difference between well-formed and Know the difference between well-formed and not well-formed XML documents.not well-formed XML documents.

Know how to validate documents in order to Know how to validate documents in order to make them well-formed XML documents. make them well-formed XML documents.

Page 3: ITApps 2011/12 1/25 XML Session 1: Introduction to XML

3/25ITApps 2011/12

XML – Learning ObjectivesXML – Learning Objectives

Create and design DTDs (Document Type Create and design DTDs (Document Type Definition) for XML documents.Definition) for XML documents.

Learn how to create namespaces.Learn how to create namespaces. Have the ability to transform an XML Have the ability to transform an XML

document into another XML document using document into another XML document using XSLT.XSLT.

Learn how XSLT can be used to create HTML Learn how XSLT can be used to create HTML files.files.

Learn XPath to transform an XML document.Learn XPath to transform an XML document.

Page 4: ITApps 2011/12 1/25 XML Session 1: Introduction to XML

4/25ITApps 2011/12

Recommended ReadingRecommended Reading

Holzner, S. Sams teach yourself XML in Holzner, S. Sams teach yourself XML in 21 days (3rd Edition). Sams, 2003.21 days (3rd Edition). Sams, 2003.

Harold, E. R. & Means, W. S. XML in a Harold, E. R. & Means, W. S. XML in a Nutshell (3rd Edition). O'Reilly, 2004.Nutshell (3rd Edition). O'Reilly, 2004.

Eric Ray, Learning XML, O'Reilly & Eric Ray, Learning XML, O'Reilly & Associates, Inc., Sebastopol, CA, January Associates, Inc., Sebastopol, CA, January 2001, ISBN 0-596-00046-4.2001, ISBN 0-596-00046-4.

Page 5: ITApps 2011/12 1/25 XML Session 1: Introduction to XML

5/25ITApps 2011/12

Introduction to the Extensible Markup Introduction to the Extensible Markup Language (XML)Language (XML)

SGML, HTML, and XML are the most SGML, HTML, and XML are the most important markup languages. important markup languages. SGML because it is the parent language of SGML because it is the parent language of both HTML and XML, HTML because it is both HTML and XML, HTML because it is the current language of the web, and XML the current language of the web, and XML because it is the future language of the because it is the future language of the web. web.

Page 6: ITApps 2011/12 1/25 XML Session 1: Introduction to XML

6/25ITApps 2011/12

Standard Generalised Markup Standard Generalised Markup Language (SGML)Language (SGML)

In the late 1960s, IBM researchers worked on the problem of In the late 1960s, IBM researchers worked on the problem of building a portable system for the interchange and manipulation building a portable system for the interchange and manipulation of legal documents. of legal documents.

Their prototype language marked up structural elements, with Their prototype language marked up structural elements, with formatting information kept in separate files, called style sheets. formatting information kept in separate files, called style sheets. The document structure was defined in yet another file, called a The document structure was defined in yet another file, called a Document Type Definition (DTD). Document Type Definition (DTD).

By 1969, the researchers had developed the General Markup By 1969, the researchers had developed the General Markup Language (GML). Language (GML).

After further work worldwide, in 1986, the International After further work worldwide, in 1986, the International Standards Organisation (ISO) adopted a particular version Standards Organisation (ISO) adopted a particular version called the Standard Generalised Markup Language (SGML). It called the Standard Generalised Markup Language (SGML). It quickly became the business standard for data storage and quickly became the business standard for data storage and interchange.interchange.

Page 7: ITApps 2011/12 1/25 XML Session 1: Introduction to XML

7/25ITApps 2011/12

Advantages of SGMLAdvantages of SGML Long-term viability as an ISO standard Long-term viability as an ISO standard Non-proprietary and platform-independent Non-proprietary and platform-independent Supports user-defined tags reflecting the richness of Supports user-defined tags reflecting the richness of

documents documents Disadvantages of SGMLDisadvantages of SGML

Costly to set up, requiring real expertise Costly to set up, requiring real expertise SGML tools are expensive, compared to those for SGML tools are expensive, compared to those for

HTML HTML Creating DTDs with SGML is expensive - especially Creating DTDs with SGML is expensive - especially

labourlabour SGML has a steep learning curve SGML has a steep learning curve Put bluntly, it is too elaborate for the ever-changing Put bluntly, it is too elaborate for the ever-changing

web.web.

Page 8: ITApps 2011/12 1/25 XML Session 1: Introduction to XML

8/25ITApps 2011/12

HyperText Markup Language (HTML)HyperText Markup Language (HTML)

Tim Berners-Lee and Robert Calliau, working Tim Berners-Lee and Robert Calliau, working independently from the other at CERN, independently from the other at CERN, invented the invented the HyperText Markup Language (HTML) based on SGML. (HTML) based on SGML.

HTML is one particular SGML DTD that is HTML is one particular SGML DTD that is easier to learn and use than SGML. easier to learn and use than SGML.

HTML is a trimmed-down version of SGML, HTML is a trimmed-down version of SGML, eliminating SGML features that are rarely eliminating SGML features that are rarely needed, but including hyperlinks to link web needed, but including hyperlinks to link web documents.documents.

Page 9: ITApps 2011/12 1/25 XML Session 1: Introduction to XML

9/25ITApps 2011/12

Sample of an HTML page.Sample of an HTML page.

<html><html><head><head>

<title>This is the title of the page</title><title>This is the title of the page</title>

</head></head>

<body><body>

<p> This is the main details of my page </p><p> This is the main details of my page </p>

</body></body>

</html></html> Filename: Filename:

MyFileSample.htmlMyFileSample.html

Page 10: ITApps 2011/12 1/25 XML Session 1: Introduction to XML

10/25ITApps 2011/12

Cascading Style Sheets (CSS)Cascading Style Sheets (CSS) With earlier versions of HTML, web browsers With earlier versions of HTML, web browsers

controlled the appearance (rendering) of controlled the appearance (rendering) of every web page.every web page.

With the advent of Cascading Style Sheets With the advent of Cascading Style Sheets (CSS), the document author can control the (CSS), the document author can control the way the browser renders the page, or the way the browser renders the page, or the entire web site for that matter.entire web site for that matter.

Style sheets allow document authors to Style sheets allow document authors to specify the style of their page elements specify the style of their page elements (spacing, margins, etc.) separately from their (spacing, margins, etc.) separately from their structure (section headers, body text, etc.), structure (section headers, body text, etc.), thus allowing greater manageability. thus allowing greater manageability.

Page 11: ITApps 2011/12 1/25 XML Session 1: Introduction to XML

11/25ITApps 2011/12

Sample CSSSample CSS

/* This is a CSS example *//* This is a CSS example */

pp

{{

text-align: center;text-align: center;

color: black;color: black;

font-family: arial;font-family: arial;

}}

Filename: MyStyle.cssFilename: MyStyle.css

Page 12: ITApps 2011/12 1/25 XML Session 1: Introduction to XML

12/25ITApps 2011/12

Extensible Markup Language (XML)Extensible Markup Language (XML)

The Extensible Markup Language (XML) is The Extensible Markup Language (XML) is also a descendant of SGML, representing an also a descendant of SGML, representing an industry-wide effort to define which data are industry-wide effort to define which data are displayed (or printed), whereas HTML defines displayed (or printed), whereas HTML defines how a page is displayed. how a page is displayed.

XML will overtake HTML because of its ability XML will overtake HTML because of its ability to describe content. XML has the following to describe content. XML has the following advantages.advantages.

Page 13: ITApps 2011/12 1/25 XML Session 1: Introduction to XML

13/25ITApps 2011/12

Sample XML document:Sample XML document:

<?xml version="1.0" encoding="UTF-8"?><?xml version="1.0" encoding="UTF-8"?><student><student>

<firstname>John</firstname><firstname>John</firstname><surname>Smith</surname><surname>Smith</surname><birthday><birthday>

<day>06</day><day>06</day><month>12</month><month>12</month><year>1975</year><year>1975</year>

</birthday></birthday></student></student>

Filename: MyStudentExample.xmlFilename: MyStudentExample.xml

Page 14: ITApps 2011/12 1/25 XML Session 1: Introduction to XML

14/25ITApps 2011/12

Why make use of XML and the importance of it Why make use of XML and the importance of it in the business worldin the business world

XML XML languageslanguages are being developed for are being developed for many areas of document processing and many areas of document processing and e-commerce. e-commerce.

Example: Example: Chemical Markup Language (Chemical Markup Language (CML) ) Peter Murray-Rust's Chemical Markup Peter Murray-Rust's Chemical Markup Language is used for representing Language is used for representing molecular and chemical information (molecular and chemical information (www.cellml.org). ).

Page 15: ITApps 2011/12 1/25 XML Session 1: Introduction to XML

15/25ITApps 2011/12

Example of a Water Molecule: Example of a Water Molecule:

Page 16: ITApps 2011/12 1/25 XML Session 1: Introduction to XML

16/25ITApps 2011/12

The following illustrates the CML The following illustrates the CML document for a water molecule (H2O): document for a water molecule (H2O):

<?xml version="1.0" encoding="UTF-8"?><?xml version="1.0" encoding="UTF-8"?>

<cml><cml><mol title="Water"><mol title="Water">

<atoms><atoms><array builtin="elsym">H O H</array><array builtin="elsym">H O H</array>

</atoms></atoms><bonds><bonds>

<array builtin="atid1">1 2</array><array builtin="atid1">1 2</array><array builtin="atid2">2 3</array><array builtin="atid2">2 3</array><array builtin="order">1 1</array><array builtin="order">1 1</array>

</bonds></bonds></mol></mol>

</cml></cml> Filename: Filename:

WaterMoleculeCMLExample.xmlWaterMoleculeCMLExample.xml

Page 17: ITApps 2011/12 1/25 XML Session 1: Introduction to XML

17/25ITApps 2011/12

Mathematical Markup Language (MathML)Mathematical Markup Language (MathML)

The Mathematical Markup Language The Mathematical Markup Language [MathML] was developed for describing [MathML] was developed for describing mathematical notations and expressions mathematical notations and expressions using XML.using XML.

It allows mathematical expressions to be It allows mathematical expressions to be processed by different applications for processed by different applications for different purposes (different purposes (www.w3.org/Math). ).

MathML Example for the quadratic equation MathML Example for the quadratic equation xx22+4x+4=0.+4x+4=0.

Page 18: ITApps 2011/12 1/25 XML Session 1: Introduction to XML

18/25ITApps 2011/12

Sample MathMLSample MathML<?xml version="1.0" encoding="UTF-8"?><?xml version="1.0" encoding="UTF-8"?><!DOCTYPE math SYSTEM "http://www.w3.org/TR/MathML2/dtd/mathml2.dtd"><!DOCTYPE math SYSTEM "http://www.w3.org/TR/MathML2/dtd/mathml2.dtd"><math xmlns="http://www.w3.org/1998/Math/MathML"><math xmlns="http://www.w3.org/1998/Math/MathML"> <mrow><mrow> <mrow><mrow> <msup><msup> <mi>x</mi><mi>x</mi> <mn>2</mn><mn>2</mn>

</msup></msup> <mo>+</mo><mo>+</mo> <mrow><mrow> <mn>4</mn><mn>4</mn> <mo>&InvisibleTimes;</mo><mo>&InvisibleTimes;</mo> <mi>x</mi><mi>x</mi> </mrow></mrow> <mo>+</mo><mo>+</mo> <mn>4</mn><mn>4</mn> </mrow></mrow> <mo>=</mo><mo>=</mo> <mn>0</mn><mn>0</mn> </mrow></mrow></math></math>

Filename: MathMLExample.xmlFilename: MathMLExample.xml

Page 19: ITApps 2011/12 1/25 XML Session 1: Introduction to XML

19/25ITApps 2011/12

The The <mi><mi> element is for identifiers. element is for identifiers. The The <mn><mn> element is for numbers. element is for numbers. The The <mo><mo> element is for operators, etc. element is for operators, etc. The entity The entity &InvisibleTimes;&InvisibleTimes; is important – is important –

it is invisible when rendered for viewing, it is invisible when rendered for viewing, spoken when rendered for voice, but spoken when rendered for voice, but indicates multiplication if the equation is indicates multiplication if the equation is being computed!being computed!

Page 20: ITApps 2011/12 1/25 XML Session 1: Introduction to XML

20/25ITApps 2011/12

Wireless Markup Language (WML)Wireless Markup Language (WML)

The The Wireless Markup LanguageWireless Markup Language [WML] allows allows web pages to be displayed on wireless web pages to be displayed on wireless devices such as cellular phones and PDAs. devices such as cellular phones and PDAs.

WML works with the WML works with the Wireless Application Wireless Application ProtocolProtocol (WAP) to deliver the content. (WAP) to deliver the content.

WAP/WML Tutorial:WAP/WML Tutorial:

http://www.w3schools.com/WAP/default.asp

Page 21: ITApps 2011/12 1/25 XML Session 1: Introduction to XML

21/25ITApps 2011/12

Sample WML Sample WML

<?xml version="1.0" encoding="UTF-8"?><?xml version="1.0" encoding="UTF-8"?><!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">"http://www.wapforum.org/DTD/wml_1.1.xml"><wml><wml>

<card title="Welcome to my WML page"><card title="Welcome to my WML page"> <p> <p>

This is my holiday movie page <br/> Click on the This is my holiday movie page <br/> Click on the link below <br/> to play my 3gpp holiday movie.link below <br/> to play my 3gpp holiday movie.

</p></p> <p><p> <a href="rtsp://my-wml-website/my-holiday-<a href="rtsp://my-wml-website/my-holiday-

movie.3gp">Play my holiday</a>movie.3gp">Play my holiday</a> </p></p>

</card></card></wml></wml>

Filename: Filename: WMLExample.wmlWMLExample.wml

Page 22: ITApps 2011/12 1/25 XML Session 1: Introduction to XML

22/25ITApps 2011/12

ReferencesReferences

Useful links:Useful links: penguin.dcs.bbk.ac.uk/academic/xml/index.php www.w3schools.com/xml/default.asp en.wikipedia.org/wiki/XML xml.coverpages.org/xml.html www-128.ibm.com/developerworks/xml/newto www.mozilla.org/newlayout/xml www.cellml.org/tutorial/xml_guide webdesign.about.com/library/nosearch/bl_xmlclass1-1.htmwebdesign.about.com/library/nosearch/bl_xmlclass1-1.htm developer.openwave.com/dvl/support/documentation/developer.openwave.com/dvl/support/documentation/

guides_and_references/best_practices_in_xhtml_design/guides_and_references/best_practices_in_xhtml_design/index.htmindex.htm

www.yospace.comwww.yospace.com www.waptiger.com/waptigerwww.waptiger.com/waptiger www.w3.org/TR/NOTE-sgml-xml-971215www.w3.org/TR/NOTE-sgml-xml-971215