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
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.
Every XML-document is text-based
=> sharing data between different computers!
=> sharing data in Internet!
=> platform independence!
Binary vs. Text
Problems with Binary format
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...
<jorma> This is a minimal <a href="http://www.w3.org/TR/xhtml1/">XHTML 1.0</a>
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
The menu of TAMKOtuki is saved into XML-document:
Since you can be sure, that the xml-document is well formed, reading the contents of the xml-document is fairly easy