XML Introduction

Download Report

Transcript XML Introduction

XML Introduction
• What is XML
– XML is the eXtensible Markup Language
– Became a W3C Recommendation in 1998
– Tag-based syntax, like HTML
– You get to make up your own tags
– Foundation for several next-gen Web
technologies
• XTHML, RSS (Blogs), AJAX, Web Services
XML Introduction
• What does XML do?
– XML is used to structure and describe
information
– Intended to be used with the Internet
– XML can be used as a way to interchange
data between disparate systems
Tools for Working with XML
• Simple Text Editors- Notepad, TextPad
– Free or cheap
– Simple to use, no frills editing
• Adobe Dreamweaver
– Good XML editing features
– Can check an XML file against a given Document Type Definition
• Altova XMLSpy
– Advanced XML tool, intended for Professional use
– XSLT debugging and XPath expression testing
• Microsoft Visual Web Developer Express
– Free, and has good XML editing features
Advantages of XML
• Content is kept separate from any notion of
presentation
• Information can be easily read and understood
• Specific tag sets that target specific problems
can be easily created
• XML is an open forum format that can be
processed by any XML-aware application, like a
browser
• XML data can be exchanged between systems
that were never designed to do so
Disadvantages of XML
• XML is not especially good at handling
very large amounts of data
• XML can quickly become difficult to read if
a lot of information is included in one file
• Certain type of data (images, other binary
date) are not represented well in XML
• XML’s simplicity makes it easy to lose
sight of the whole design process
Proper XML Syntax
• All XML documents have a single root tag
• XML documents must be “well-formed”
– Empty tags must be closed with />
• Use <elem />
– Attributes can not be minimised
• <element attr> is wrong, must do <element attr=“attr”>
– Attribute values must always be inside quotes, either
single or double
• <element attr=value> is wrong, use <element attr=“value”>
– Tags must be properly nested inside each other
• <elem1><elem2></elem1></elem2> is wrong
• Always do <elem1><elem2></elem2></elem1>
Contents of XML Files
• XML Declaration
–
<?xml version=“1.0” encoding=“utf-8” standalone=“yes” ? >
• Elements or Tags
–
<element> just like HTML
• Attributes
–
<element attr=“value”>, like HTML
• Comments
–
<! --- XML comments --- >
• Character Data Sections
–
<! [CDATA [This is some text & data] ]
>
• Processing Instructions- special instructions that are only of interest
to the application that is processing XML
– <?SpellCheckMode mode=“us-english”?>
• Entity References- provide a way to include characters that would
otherwise be illegal to type in markup
– Character (&#60;) and General (&copyright;)
Valid XML Documents
• A valid XML Document is one that has
been tested against a set of rules
• These rules are specific as either DTD or
XML Schema files
• DTDs are simpler but less powerful and
don’t use the same syntax as the XML
itself
• Schema is more powerful but more
complex and is written using XML syntax
XML Namespaces
• Have the form
– <html xmlns=http://www.w3.org/1999/xhtml”>
• Namespaces provide a way to prevent tags with
same names but different meanings from colliding
with each other