Introduction to XML Jussi Pohjolainen TAMK University of Applied Sciences
What is XML? <ul><li>e X tensible  M arkup  L anguage, is a specification for creating custom markup languages </li></ul><...
XML Document <ul><li>Every XML-document is  text-based </li></ul><ul><li>=>  sharing data between different computers! </l...
Binary vs. Text <ul><li>Problems with Binary format </li></ul><ul><ul><li>Platform depence </li></ul></ul><ul><ul><li>Fire...
XML Doc Advantages <ul><li>Easy data sharing, text documents are readable between any device. </li></ul><ul><li>Documents ...
.doc – file format Windows MS Word 2000 Mac OS X Since .doc is closed binary-format, there are very few alternatives for w...
.docx – file format (Office Open XML) Windows MS Word 2007 Mac OS X Hopefully in the future there will be loads of free pr...
SGML vs. XML SGML: Standard Generalized Markup Language  XML HTML (.html) XHTML (.xhtml) MathML (.mml) OOXML (.docx)
XML – Meta Language <ul><li>XML is meta language, which you can use to create your own markup languages. </li></ul><ul><li...
XHTML - Example <ul><li><?xml version=&quot;1.0&quot;?> </li></ul><ul><li><!DOCTYPE html  </li></ul><ul><li>PUBLIC &quot;-...
SVG - Example <ul><li><?xml version=&quot;1.0&quot;?> </li></ul><ul><li><!DOCTYPE svg  </li></ul><ul><li>PUBLIC &quot;-//W...
MathML (Open Office) <ul><li><?xml version=&quot;1.0&quot;?> </li></ul><ul><li><!DOCTYPE math:math PUBLIC &quot;-//OpenOff...
RSS 2.0 - Example <ul><li><?xml version=&quot;1.0&quot;?> </li></ul><ul><li><rss version=&quot;2.0&quot;> </li></ul><ul><l...
XML Editors <ul><li>XML Spy  </li></ul><ul><li>EditiX  </li></ul><ul><li>Microsoft XML Notepad </li></ul><ul><li>Visual XM...
WELL FORMED XML - DOCUMENT <ul><li>Rules that Apply to Every XML-Document </li></ul>
Correctness <ul><li>There are two levels of correctness of an XML document: </li></ul><ul><ul><li>Well-formed . A well-for...
Simple Generic XML Example <ul><li><?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; standalone=&quot;yes&quot;?> <...
XML-Declaration <ul><li>XML-declaration is  optional in XML 1.0, mandatory in 1.1. </li></ul><ul><ul><li>Recommendation:  ...
Comparing Declarations <ul><li><?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; standalone=&quot;no&quot;?> </li><...
Element vs. Tag vs. Attribute <ul><li>Element  consists of  start tag, optional content  and an  end tag: </li></ul><ul><u...
Rules about Elements <ul><li>Only one root - element </li></ul><ul><li>Every element contains starting tag and an ending t...
Rules about Attributes <ul><li>XML elements can have attributes in the start tag. </li></ul><ul><li>Attributes must be quo...
Naming Tags <ul><li>Names can contain letters, numbers, and other characters </li></ul><ul><li>Names must not start with a...
Well-Formed XML <ul><li>XML document is well-formed if it follows the syntax rules. </li></ul><ul><li>XML document  must b...
Is this Well-Formed XML Document? <ul><li><?xml version=&quot;1.0&quot;?> </li></ul><ul><li><html xmlns=&quot;http://www.w...
Is this Well-Formed XML Document? <ul><li><?xml version=&quot;1.0&quot;?> </li></ul><ul><li><html xmlns=&quot;http://www.w...
VALID XML DOCUMENT <ul><li>Defining the Structure for XML documents </li></ul>
Valid XML <ul><li>XML document is valid if </li></ul><ul><ul><li>1) It is well formed AND </li></ul></ul><ul><ul><li>2) It...
DTD Linking <ul><li><?xml version=&quot;1.0&quot;?> </li></ul><ul><li><!DOCTYPE html  </li></ul><ul><li>PUBLIC &quot;-//W3...
DTD Linking Defines the structure, tag names and order for all xhtml - documents W3C has created XML-language &quot;XHTML&...
Is this valid XML Document? <ul><li><?xml version=&quot;1.0&quot;?> </li></ul><ul><li><html xmlns=&quot;http://www.w3.org/...
Invalid XHTML-document <ul><li><?xml version=&quot;1.0&quot;?> </li></ul><ul><li><!DOCTYPE html  </li></ul><ul><li>PUBLIC ...
Validating with W3C Service
Invalid XHTML in Browser? May work... or not. Browser tries to detect the errors and  tries  to understand them. If it wor...
Invalid XML in General <ul><li>Because of HTML heritage, browsers try to understand invalid XHTML-pages </li></ul><ul><li>...
Example: MathML and Open Office
Open the Document in External Editor
Modify and Save the Document Break the XML file
Open the Document
Result Nope.. It does not try to understand the errors in the document. It does  not  handle the  document at all.
Benefits of WF and Valid <ul><li>XML has strict rules for WF and Valid </li></ul><ul><li>If application tries to manipulat...
Case: TAMKOtuki <ul><li>The menu of TAMKOtuki is saved into XML-document: </li></ul><ul><ul><li>http://php.tpu.fi/~pohjus/...
Upcoming SlideShare
Loading in …5
×

Introduction to XML

6,779 views

Published on

Introduction to XML.

Published in: Technology, News & Politics
1 Comment
16 Likes
Statistics
Notes
No Downloads
Views
Total views
6,779
On SlideShare
0
From Embeds
0
Number of Embeds
201
Actions
Shares
0
Downloads
953
Comments
1
Likes
16
Embeds 0
No embeds

No notes for slide

Introduction to XML

  1. 1. Introduction to XML Jussi Pohjolainen TAMK University of Applied Sciences
  2. 2. What is XML? <ul><li>e X tensible M arkup L anguage, is a specification for creating custom markup languages </li></ul><ul><li>W3C Recommendation </li></ul><ul><li>Primary purpose is to help computers to share data </li></ul><ul><li>XML is meta-language. This means that you use it for creating languages. </li></ul><ul><li>XML is an extensive concept. </li></ul>
  3. 3. XML Document <ul><li>Every XML-document is text-based </li></ul><ul><li>=> sharing data between different computers! </li></ul><ul><li>=> sharing data in Internet! </li></ul><ul><li>=> platform independence! </li></ul>
  4. 4. Binary vs. Text <ul><li>Problems with Binary format </li></ul><ul><ul><li>Platform depence </li></ul></ul><ul><ul><li>Firewalls </li></ul></ul><ul><ul><li>Hard to debug </li></ul></ul><ul><ul><li>Inspecting the file can be hard </li></ul></ul><ul><li>Since XML is text-based, it does not have the problems mentioned above. </li></ul><ul><li>What are the disadvantages in text format? </li></ul>
  5. 5. XML Doc Advantages <ul><li>Easy data sharing, text documents are readable between any device. </li></ul><ul><li>Documents can be modified with any text editor. </li></ul><ul><li>Possible to understand the contents of the xml-document just by looking at it with text editor. </li></ul><ul><li>Easy to manipulate via programming languages </li></ul><ul><li>Two levels of correctness: Well formed and Valid. </li></ul>
  6. 6. .doc – file format Windows MS Word 2000 Mac OS X Since .doc is closed binary-format, there are very few alternatives for word processors that fully support the doc – file format 0101011010101010001010 1010101110101010001011 1010101110101010110101 1110101010101010101010
  7. 7. .docx – file format (Office Open XML) Windows MS Word 2007 Mac OS X Hopefully in the future there will be loads of free programs that support this new open and easy access file format <xml> <heading1>title</heading1> . . </xml> Now the format is open and it's much easier to access
  8. 8. SGML vs. XML SGML: Standard Generalized Markup Language XML HTML (.html) XHTML (.xhtml) MathML (.mml) OOXML (.docx)
  9. 9. XML – Meta Language <ul><li>XML is meta language, which you can use to create your own markup languages. </li></ul><ul><li>There are several XML Markup Languages made for different purposes </li></ul><ul><li>All the languages have common xml-rules </li></ul><ul><li>Languages: XHTML, OOXML, Open Document, RSS, SVG, SOAP, SMIL, MathML... </li></ul><ul><li>List: </li></ul><ul><ul><li>http://en.wikipedia.org/wiki/List_of_XML_markup_languages </li></ul></ul>
  10. 10. XHTML - Example <ul><li><?xml version=&quot;1.0&quot;?> </li></ul><ul><li><!DOCTYPE html </li></ul><ul><li>PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; </li></ul><ul><li>&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;> </li></ul><ul><li><html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; xml:lang=&quot;en&quot; lang=&quot;en&quot;> </li></ul><ul><li><head> </li></ul><ul><li><title>Minimal XHTML 1.0 Document</title> </li></ul><ul><li></head> </li></ul><ul><li><body> </li></ul><ul><li><p>This is a minimal <a href=&quot;http://www.w3.org/TR/xhtml1/&quot;>XHTML 1.0</a> </li></ul><ul><li>document.</p> </li></ul><ul><li></body> </li></ul><ul><li></html> </li></ul>
  11. 11. SVG - Example <ul><li><?xml version=&quot;1.0&quot;?> </li></ul><ul><li><!DOCTYPE svg </li></ul><ul><li>PUBLIC &quot;-//W3C//DTD SVG 1.1//EN&quot; </li></ul><ul><li>&quot;http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd&quot;> </li></ul><ul><li><svg width=&quot;100%&quot; height=&quot;100%&quot; version=&quot;1.1&quot; </li></ul><ul><li>xmlns=&quot;http://www.w3.org/2000/svg&quot;> </li></ul><ul><li><circle cx=&quot;100&quot; cy=&quot;50&quot; r=&quot;40&quot; stroke=&quot;black&quot; </li></ul><ul><li>stroke-width=&quot;2&quot; fill=&quot;red&quot;/> </li></ul><ul><li></svg> </li></ul>
  12. 12. MathML (Open Office) <ul><li><?xml version=&quot;1.0&quot;?> </li></ul><ul><li><!DOCTYPE math:math PUBLIC &quot;-//OpenOffice.org//DTD Modified W3C MathML 1.01//EN&quot; &quot;math.dtd&quot;> </li></ul><ul><li><math:math xmlns:math=&quot;http://www.w3.org/1998/Math/MathML&quot;> </li></ul><ul><li><math:semantics> </li></ul><ul><li><math:mrow> </li></ul><ul><li><math:mi>x</math:mi> </li></ul><ul><li><math:mo math:stretchy=&quot;false&quot;>=</math:mo> </li></ul><ul><li><math:mfrac> </li></ul><ul><li><math:mrow> </li></ul><ul><li>... </li></ul><ul><li></math:mrow> </li></ul><ul><li><math:annotation math:encoding=&quot;StarMath 5.0&quot;>x = {-b +-sqrt{b^{2}-4{ac}} } over {2 {a}} </math:annotation> </li></ul><ul><li></math:semantics> </li></ul><ul><li></math:math> </li></ul>
  13. 13. RSS 2.0 - Example <ul><li><?xml version=&quot;1.0&quot;?> </li></ul><ul><li><rss version=&quot;2.0&quot;> </li></ul><ul><li><channel> </li></ul><ul><li><title>W3Schools Home Page</title> </li></ul><ul><li><link>http://www.w3schools.com</link> </li></ul><ul><li><description>Free web building tutorials</description> </li></ul><ul><li><item> </li></ul><ul><li><title>RSS Tutorial</title> </li></ul><ul><li><link>http://www.w3schools.com/rss</link> </li></ul><ul><li><description>New RSS tutorial on W3Schools</description> </li></ul><ul><li></item> </li></ul><ul><li><item> </li></ul><ul><li><title>XML Tutorial</title> </li></ul><ul><li><link>http://www.w3schools.com/xml</link> </li></ul><ul><li><description>New XML tutorial on W3Schools</description> </li></ul><ul><li></item> </li></ul><ul><li></channel> </li></ul><ul><li></rss> </li></ul>
  14. 14. XML Editors <ul><li>XML Spy </li></ul><ul><li>EditiX </li></ul><ul><li>Microsoft XML Notepad </li></ul><ul><li>Visual XML </li></ul><ul><li>XML Viewer </li></ul><ul><li>Xeena </li></ul><ul><li>XML Styler, Morphon, XML Writer… </li></ul>
  15. 15. WELL FORMED XML - DOCUMENT <ul><li>Rules that Apply to Every XML-Document </li></ul>
  16. 16. Correctness <ul><li>There are two levels of correctness of an XML document: </li></ul><ul><ul><li>Well-formed . A well-formed document conforms to all of XML's syntax rules. </li></ul></ul><ul><ul><li>Valid . A valid document additionally conforms to some semantic rules. </li></ul></ul><ul><li>Let's first look at the XML's syntax rules (1). </li></ul>
  17. 17. Simple Generic XML Example <ul><li><?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; standalone=&quot;yes&quot;?> </li></ul><ul><li><presentation> </li></ul><ul><li><slide number=&quot;1&quot;> </li></ul><ul><li><name>Introduction to XML</name> </li></ul><ul><li><contents>XML is ...</contents> </li></ul><ul><li></slide> </li></ul><ul><li></presentation> </li></ul>
  18. 18. XML-Declaration <ul><li>XML-declaration is optional in XML 1.0, mandatory in 1.1. </li></ul><ul><ul><li>Recommendation: use it. </li></ul></ul><ul><li>Version: 1.0 or 1.1 </li></ul><ul><li>Encoding: character encoding , default utf-8 </li></ul><ul><li>Standalone: </li></ul><ul><ul><li>is the xml-document linked to external markup declaration </li></ul></ul><ul><ul><li>yes: no external markup declarations </li></ul></ul><ul><ul><li>no: can have external markup declaration (open issue..) </li></ul></ul><ul><ul><li>default: &quot;no&quot; </li></ul></ul>
  19. 19. Comparing Declarations <ul><li><?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; standalone=&quot;no&quot;?> </li></ul><ul><li><presentation> </li></ul><ul><li><slide> </li></ul><ul><li><name>Introduction to XML</name> </li></ul><ul><li><contents>XML is ...</contents> </li></ul><ul><li></slide> </li></ul><ul><li></presentation> </li></ul><ul><li><?xml version=&quot;1.0&quot;?> </li></ul><ul><li><presentation> </li></ul><ul><li><slide> </li></ul><ul><li><name>Introduction to XML</name> </li></ul><ul><li><contents>XML is ...</contents> </li></ul><ul><li></slide> </li></ul><ul><li></presentation> </li></ul>Same Declaration
  20. 20. Element vs. Tag vs. Attribute <ul><li>Element consists of start tag, optional content and an end tag: </li></ul><ul><ul><li><name>Introduction to XML</name> </li></ul></ul><ul><li>Start tag </li></ul><ul><ul><li><name> </li></ul></ul><ul><li>Content </li></ul><ul><ul><li>Introduction to XML </li></ul></ul><ul><li>End tag </li></ul><ul><ul><li></name> </li></ul></ul><ul><li>Start tag may have attribute </li></ul><ul><ul><li><slide number=&quot;1&quot; > </li></ul></ul>
  21. 21. Rules about Elements <ul><li>Only one root - element </li></ul><ul><li>Every element contains starting tag and an ending tag </li></ul><ul><li>Content is optional: Empty element </li></ul><ul><ul><li><x></x> <!-- same as --> </li></ul></ul><ul><ul><li><x/> </li></ul></ul><ul><li>Tag – names are case-sensitive: </li></ul><ul><ul><li><X></x> <!-- Error --> </li></ul></ul><ul><li>Elements must be ended with the end tag in correct order : </li></ul><ul><ul><li><p><i>problem here</p></i> <!– Error  </li></ul></ul>
  22. 22. Rules about Attributes <ul><li>XML elements can have attributes in the start tag. </li></ul><ul><li>Attributes must be quoted: </li></ul><ul><ul><li><person sex=&quot;female&quot;> </li></ul></ul><ul><ul><li><person sex='female'> </li></ul></ul><ul><ul><li><gangster name='George &quot;Shotgun&quot; Ziegler'> </li></ul></ul><ul><ul><li><gangster name=&quot;George &quot;Shotgun&quot; Ziegler&quot;> </li></ul></ul>
  23. 23. Naming Tags <ul><li>Names can contain letters, numbers, and other characters </li></ul><ul><li>Names must not start with a number or punctuation character </li></ul><ul><li>Names must not start with the letters xml (or XML, or Xml, etc) </li></ul><ul><li>Names cannot contain spaces </li></ul>
  24. 24. Well-Formed XML <ul><li>XML document is well-formed if it follows the syntax rules. </li></ul><ul><li>XML document must be well-formed! </li></ul><ul><ul><li>it's not an xml-document, if it does not follow the rules.. </li></ul></ul>
  25. 25. Is this Well-Formed XML Document? <ul><li><?xml version=&quot;1.0&quot;?> </li></ul><ul><li><html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; xml:lang=&quot;en&quot; lang=&quot;en&quot;> </li></ul><ul><li><head> </li></ul><ul><li><title>Minimal XHTML 1.0 Document</title> </li></ul><ul><li></head> </li></ul><ul><li><body> </li></ul><ul><li><p>This is a minimal <a href=&quot;http://www.w3.org/TR/xhtml1/&quot;>XHTML 1.0</a> </li></ul><ul><li>document.</p> </li></ul><ul><li></body> </li></ul><ul><li></html> </li></ul>
  26. 26. Is this Well-Formed XML Document? <ul><li><?xml version=&quot;1.0&quot;?> </li></ul><ul><li><html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; xml:lang=&quot;en&quot; lang=&quot;en&quot;> </li></ul><ul><li><head> </li></ul><ul><li><title>Minimal XHTML 1.0 Document</title> </li></ul><ul><li></head> </li></ul><ul><li><body> </li></ul><ul><li><jorma> This is a minimal <a href=&quot;http://www.w3.org/TR/xhtml1/&quot;>XHTML 1.0</a> </li></ul><ul><li>document. </jorma> </li></ul><ul><li></body> </li></ul><ul><li></html> </li></ul>
  27. 27. VALID XML DOCUMENT <ul><li>Defining the Structure for XML documents </li></ul>
  28. 28. Valid XML <ul><li>XML document is valid if </li></ul><ul><ul><li>1) It is well formed AND </li></ul></ul><ul><ul><li>2) It follows some semantic rules </li></ul></ul><ul><li>XML document is usually linked to an external file, that has semantic rules for the document. </li></ul><ul><ul><li>The file can be dtd (.dtd) or schema (.xsd) </li></ul></ul><ul><li>Semantic rules? </li></ul><ul><ul><li>Name of tags, order of elements </li></ul></ul>
  29. 29. DTD Linking <ul><li><?xml version=&quot;1.0&quot;?> </li></ul><ul><li><!DOCTYPE html </li></ul><ul><li>PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; </li></ul><ul><li>&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;> </li></ul><ul><li><html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; xml:lang=&quot;en&quot; lang=&quot;en&quot;> </li></ul><ul><li><head> </li></ul><ul><li><title>Minimal XHTML 1.0 Document</title> </li></ul><ul><li></head> </li></ul><ul><li><body> </li></ul><ul><li><p>This is a minimal <a href=&quot;http://www.w3.org/TR/xhtml1/&quot;>XHTML 1.0</a> </li></ul><ul><li>document.</p> </li></ul><ul><li></body> </li></ul><ul><li></html> </li></ul>Rules for XHTML elements (order, names, etc)
  30. 30. DTD Linking Defines the structure, tag names and order for all xhtml - documents W3C has created XML-language &quot;XHTML&quot; by defining it's rules in DTD.
  31. 31. Is this valid XML Document? <ul><li><?xml version=&quot;1.0&quot;?> </li></ul><ul><li><html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; xml:lang=&quot;en&quot; lang=&quot;en&quot;> </li></ul><ul><li><head> </li></ul><ul><li><title>Minimal XHTML 1.0 Document</title> </li></ul><ul><li></head> </li></ul><ul><li><body> </li></ul><ul><li><jorma> This is a minimal <a href=&quot;http://www.w3.org/TR/xhtml1/&quot;>XHTML 1.0</a> </li></ul><ul><li>document. </jorma> </li></ul><ul><li></body> </li></ul><ul><li></html> </li></ul><ul><li>There is no DTD! What language is this? MathML? SVG? XHTML? </li></ul><ul><li>Assuming this is XHTML, what version of XHTML? Transitional? Strict? </li></ul><ul><li>Assuming this is XHTML strict, does &quot;jorma&quot; – tag belong to XHTML Language? </li></ul>
  32. 32. Invalid XHTML-document <ul><li><?xml version=&quot;1.0&quot;?> </li></ul><ul><li><!DOCTYPE html </li></ul><ul><li>PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; </li></ul><ul><li>&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;> </li></ul><ul><li><html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; xml:lang=&quot;en&quot; lang=&quot;en&quot;> </li></ul><ul><li><head> </li></ul><ul><li><title>Minimal XHTML 1.0 Document</title> </li></ul><ul><li></head> </li></ul><ul><li><body> </li></ul><ul><li><jorma> This is a minimal <a href=&quot;http://www.w3.org/TR/xhtml1/&quot;>XHTML 1.0</a> </li></ul><ul><li>document. </jorma> </li></ul><ul><li></body> </li></ul><ul><li></html> </li></ul>
  33. 33. Validating with W3C Service
  34. 34. Invalid XHTML in Browser? May work... or not. Browser tries to detect the errors and tries to understand them. If it works with one browser, are you certain that it works with all other browsers? And with all the versions with the browsers? What about browsers in handheld devices? And it might work now, but what about future ? How will Firefox 5.0 handle incorrect web pages?
  35. 35. Invalid XML in General <ul><li>Because of HTML heritage, browsers try to understand invalid XHTML-pages </li></ul><ul><li>This is not the case in other XML-languages. </li></ul><ul><li>In general, if XML-document is invalid, the processing of the document is cancelled. </li></ul>
  36. 36. Example: MathML and Open Office
  37. 37. Open the Document in External Editor
  38. 38. Modify and Save the Document Break the XML file
  39. 39. Open the Document
  40. 40. Result Nope.. It does not try to understand the errors in the document. It does not handle the document at all.
  41. 41. Benefits of WF and Valid <ul><li>XML has strict rules for WF and Valid </li></ul><ul><li>If application tries to manipulate xml-document it does not have to try to understand the possible errors in the document </li></ul><ul><li>This means that handling xml-files via programming language is much easier </li></ul><ul><ul><li>If the document is correctly formed, manipulate it </li></ul></ul><ul><ul><li>If it isn't display error </li></ul></ul>
  42. 42. Case: TAMKOtuki <ul><li>The menu of TAMKOtuki is saved into XML-document: </li></ul><ul><ul><li>http://php.tpu.fi/~pohjus/menu/index.php </li></ul></ul><ul><li>Since you can be sure, that the xml-document is well formed, reading the contents of the xml-document is fairly easy </li></ul><ul><ul><li>Showing the contents in Web-page: </li></ul></ul><ul><ul><ul><li>http://tamkotuki.tamk.fi/en/ravintolat.php </li></ul></ul></ul><ul><ul><li>Showing the contents in TAMK-intra: </li></ul></ul><ul><ul><ul><li>https://intra.tamk.fi </li></ul></ul></ul><ul><ul><li>Showing the contents in Mobile Devices.. </li></ul></ul>

×