XML Basics: With Thanks Slides From Nitin Rastogi
XML Basics: With Thanks Slides From Nitin Rastogi
With thanks
Slides from Nitin Rastogi
• XML like HTML is a markup language, but unlike HTML it doesn’t have
predefined elements.
• You create your own elements and you assign them any name you like, hence the
term extensible.
• HTML describes the presentation of the content, XML describes the content.
• You can use XML to describe virtually any type of document: Koran, works of
Shakespeare, and others.
• Go to http://www.ibiblio.org/boask to download
ICS 541 - 01 (062) XML Basics 5
How can XML be Used?
• XML is used to Exchange Data
• With XML, data can be exchanged between
incompatible systems
• With XML, financial information can be exchanged
over the Internet
• XML can be used to Share Data
• XML can be used to Store Data
• XML can make your Data more Useful
• XML can be used to Create new Languages
<Book>
<Title> Java </Title>
Book <Author> Mustafa </Author>
Title Author year
<Year> 1995 </year>
</Book>
Java Mustafa 1995 …
Pascal Ahmed 1980 …
Basic Ali 1975 …
<Book>
Oracle Emad 1973
<Title> Oracle </Title>
…. …. <Author> Emad </Author>
<Year> 1973 </Year>
Relation </Book>
….
….
</ Bibliography>
XML document
ICS 541 - 01 (062) XML Basics 7
XML and HTML …
<?xml version:”1.0”?>
XML
Processing
Declaration
<?xml-stylesheet type="text/xsl" href=“template.xsl"?> instruction
• Attributes
• Describes an element; e.g. data type, data range, etc.
• Can only appear on beginning tag
• Example: <Book ISBN = “1-111-123”>
• Processing instructions
• Encoding specification (Unicode by default)
• Namespace declaration
• Schema declaration
• If present, the XML declaration must be first--not even white space should
precede it
• attribute values are not easy to test against a Document Type Definition
(DTD) - which is used to define the legal elements of an XML document
• <Book>
…
<Publisher> McGraw Hill </Publisher>
…
</Book>
• XML Schema
• XML Schema is an XML based alternative to DTD
• XML Validators
• Entities
• CDATA
• Declaration
• Default namespace
• Scope
• attribute
xmlns: bk = “http://www.example.com/bookinfo/”
Prefix URI(URL)
Namespace declaration
Example:
<BOOK xmlns:bk=“http://www.bookstuff.org/bookinfo”>
<bk:TITLE> All About XML </bk:TITLE>
<bk:AUTHOR> Joe Developer </bk:AUTHOR>
<bk:PRICE currency=‘US Dollar’> 19.99 </bk:PRICE>
</BOOK>
<BOOK
xmlns=“http://www.bookstuff.org/bookinfo”>
<TITLE> All About XML </TITLE>
<AUTHOR> Joe Developer </AUTHOR>
</BOOK>
ICS 541 - 01 (062) XML Basics 25
Namespaces: Scope
• Unqualified elements belong to the inner-most default
namespace.
• BOOK, TITLE, and AUTHOR belong to the default book namespace
<BOOK xmlns=“www.bookstuff.org/bookinfo”>
<TITLE> All About XML </TITLE>
<AUTHOR> Joe Developer </AUTHOR>
<PUBLISHER xmlns=“urn:publishers:publinfo”>
<NAME> Microsoft Press </NAME>
</PUBLISHER>
</BOOK>
• XML Tutorials
• http://www.programmingtutorials.com/xml.aspx