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

More Related Content

PPT
Introduction to XML
PPTX
Xml ppt
PPTX
Xml presentation
PPTX
HTML, CSS and Java Scripts Basics
ODP
Introduction to XML
Xml ppt
Xml presentation
HTML, CSS and Java Scripts Basics

What's hot (20)

PPT
PPTX
(Fast) Introduction to HTML & CSS
PPTX
An Overview of HTML, CSS & Java Script
PPT
Introduction to html
PPTX
PPTX
Css box-model
PPT
PPTX
Introduction to xml
PPTX
PDF
CSS selectors
PPTX
Complete Lecture on Css presentation
PPT
Intro to html
PPTX
Presentation of bootstrap
PPTX
Extensible Markup Language (XML)
PPTX
PPTX
XML Introduction
PDF
Html / CSS Presentation
(Fast) Introduction to HTML & CSS
An Overview of HTML, CSS & Java Script
Introduction to html
Css box-model
Introduction to xml
CSS selectors
Complete Lecture on Css presentation
Intro to html
Presentation of bootstrap
Extensible Markup Language (XML)
XML Introduction
Html / CSS Presentation
Ad

Similar to Introduction to XML (20)

PPTX
Week1 xml
PPT
PPT
PDF
M.FLORENCE DAYANA WEB DESIGN -Unit 5 XML
PPT
PDF
Java Web Services
PPT
O9xml
PDF
XML for Web Development Information tech.pdf
PDF
XMLin Web development and Applications.pdf
PPT
EXtensible Markup Language
PPTX
XML - Extensible Markup Language for Network Security.pptx
PPT
PPT
PPTX
PPT
PDF
XML Bible
PPT
Intro XML for archivists (2011)
PPT
Xml iet 2015
Week1 xml
M.FLORENCE DAYANA WEB DESIGN -Unit 5 XML
Java Web Services
O9xml
XML for Web Development Information tech.pdf
XMLin Web development and Applications.pdf
EXtensible Markup Language
XML - Extensible Markup Language for Network Security.pptx
XML Bible
Intro XML for archivists (2011)
Xml iet 2015
Ad

More from Jussi Pohjolainen (20)

PDF
Moved to Speakerdeck
PDF
Box2D and libGDX
PDF
libGDX: Screens, Fonts and Preferences
PDF
libGDX: Tiled Maps
PDF
libGDX: User Input and Frame by Frame Animation
PDF
Intro to Building Android Games using libGDX
PDF
Advanced JavaScript Development
PDF
Introduction to JavaScript
PDF
Introduction to AngularJS
PDF
libGDX: Scene2D
PDF
libGDX: Simple Frame Animation
PDF
libGDX: Simple Frame Animation
PDF
libGDX: User Input
PDF
Implementing a Simple Game using libGDX
PDF
Building Android games using LibGDX
PDF
Android Threading
PDF
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
PDF
Creating Games for Asha - platform
PDF
Intro to Asha UI
PDF
Intro to Java ME and Asha Platform
Moved to Speakerdeck
Box2D and libGDX
libGDX: Screens, Fonts and Preferences
libGDX: Tiled Maps
libGDX: User Input and Frame by Frame Animation
Intro to Building Android Games using libGDX
Advanced JavaScript Development
Introduction to JavaScript
Introduction to AngularJS
libGDX: Scene2D
libGDX: Simple Frame Animation
libGDX: Simple Frame Animation
libGDX: User Input
Implementing a Simple Game using libGDX
Building Android games using LibGDX
Android Threading
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Games for Asha - platform
Intro to Asha UI
Intro to Java ME and Asha Platform

Recently uploaded (20)

PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Encapsulation theory and applications.pdf
PDF
Electronic commerce courselecture one. Pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
Spectroscopy.pptx food analysis technology
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPT
Teaching material agriculture food technology
PDF
Unlocking AI with Model Context Protocol (MCP)
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
Digital-Transformation-Roadmap-for-Companies.pptx
Mobile App Security Testing_ A Comprehensive Guide.pdf
20250228 LYD VKU AI Blended-Learning.pptx
Encapsulation theory and applications.pdf
Electronic commerce courselecture one. Pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
MYSQL Presentation for SQL database connectivity
Spectroscopy.pptx food analysis technology
Review of recent advances in non-invasive hemoglobin estimation
Teaching material agriculture food technology
Unlocking AI with Model Context Protocol (MCP)
“AI and Expert System Decision Support & Business Intelligence Systems”
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
MIND Revenue Release Quarter 2 2025 Press Release
Advanced methodologies resolving dimensionality complications for autism neur...
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
NewMind AI Weekly Chronicles - August'25 Week I
Reach Out and Touch Someone: Haptics and Empathic Computing

Introduction to XML

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