Vous êtes sur la page 1sur 46

XML and Related

Technologies
Enterprise Application
Development
Unit Code 425

XML and Related Technologies

XML - Extensible Markup


Language
XML (Extensible Markup Language)
is a general-purpose specification
for creating custom markup
languages. It is classified as an
extensible language, because it
allows the user to define the markup elements.
XML is a software and hardware
independent tool for carrying (store
and transport) information.
Page 2

XML and Related Technologies

XML - Extensible Markup


Language
XML was designed to carry data,
not to display data like HTML.
XML is a complement to HTML not
a replacement.

Page 3

XML and Related Technologies

XML
XML tags are not predefined unlike in
HTML. You must define your own tags.
XML is designed to be self-descriptive.
XML is Just Plain Text.
XML does not DO anything unlike a
programming language that have
instructions.
XML is a W3C Recommendation.
http://www.w3.org/standards/xml/
Reference:

Page 4

XML and Related Technologies

XML File - 1

Page 5

XML and Related Technologies

XML File - 2

Page 6

XML and Related Technologies

Importance of XML
XML is a W3C recommendation.
XML is now as important for the Web
as HTML was to the foundation of the
Web.
XML is the most common tool for data
transmissions between all sorts of
applications.
XML is becoming more and more
popular in the area of storing and
Page 7

XML and Related Technologies

XML for Data Storage


and
Sharing
XML simplifies data storage of web
applications.
XML separates data from HTML.
Makes it possible to display dynamic data
in HTML documents without having to
edit HTML every time data changes.

Page 8

XML and Related Technologies

XML for Data Storage and


Sharing
With a few lines of JavaScript, you can
read an external XML file and update the
data content of your HTML.
XML data is stored in plain text format.
This provides a software and hardware
independent way of storing or transporting
data.

Page 9

XML and Related Technologies

XML for Data Storage and


Sharing
So different applications can
share/communicate the same data.
XML being stored as simple text also
makes it possible for systems to easily port
into different software/hardware platforms.

Page 10

XML and Related Technologies

XML for Data Storage and


Sharing
All kinds of "reading machines" (Handheld
computers, voice machines, news feeds,
etc) understand XML and makes your data
available to a wide variety of audience
including differently-able persons.
All these make your data more available
and diversely useful.

Page 11

XML and Related Technologies

XML for Web


Developers

XML as discussed above makes it easy is


for HTML documents to display dynamic
data.

A lot of new Internet languages are


created with XML like HTML,
WSDL, RSS.

Page 12

XML and Related Technologies

XML Documents
XML documents form a tree structure
that starts at "the root" and branches
to "the leaves".

XML declaration: Version and Encoding


Root element of document, next 4 lines are child elements
End of root element/end of XML document

The 4 child elements are siblings of


Page 13

XML and Related Technologies

XML Document Tree


Structure

Page 14

XML and Related Technologies

XML Syntax Rules


All XML Elements Must Have a Closing
Tag.
XML Tags are Case Sensitive.
XML Elements Must be Properly
Nested.
XML Documents Must Have a Root
Element
XML Attribute Values Must be Quoted
Page 15

XML and Related Technologies

XML Syntax Rules


Use Entity References instead of
characters with a special meaning in
XML.

<!-- Use this notation for comments


Page 16

XML and Related Technologies

XML Syntax Rules


HTML reduces multiple white space
characters to a single white space
but with XML, the white spaces in
your document are not truncated.
XML Stores New Line as LF.

Page 17

XML and Related Technologies

XML Elements
An XML element is everything from
(including) the element's start tag to
(including) the element's end tag.
An element can contain other
elements, simple text or a mixture of
both.
Elements can also have attributes.

Page 18

XML and Related Technologies

XML Elements
In the example,
<bookstore> and
<book> have
element contents,
because they contain
other elements.
<author> has text
content because it
Also
onlytext.
<book> has an attribute
contains
(category="CHILDREN").
Page 19

XML and Related Technologies

XML Element Names


Names can contain letters, numbers,
and other characters
Names cannot start with a number
or punctuation character
Names cannot start with the letter
xml (or XML or Xml, etc)
Names cannot contain spaces.
Page 20

XML and Related Technologies

XML is Extensible

Observe the two XMLs above. A


program originally written to read the
one should not be crashed when the
other XML is instead used as the input.
Therefore the program should not read
element contents by index but by
Page 21

XML and Related Technologies

XML Attributes
XML elements can have attributes in the
start tag, just like HTML.
Attributes provide additional information
about elements.
Better be used to store data about data
(metadata).
XML attributes must be quoted using either
single or double quotes.
There are no rules about when to use
attributes and when to use elements.
Page 22

XML and Related Technologies

XML Validation
XML with correct syntax is "Well
Formed" XML.
A "Valid" XML document is a "Well
Formed" XML document, which also
conforms to the rules of a Document
Type Definition (DTD).

Page 23

XML and Related Technologies

DTD
The purpose of a DTD is to define
the structure of an XML document.

Page 24

XML and Related Technologies

XML Schema
W3C supports an XML based
alternative to DTD called XML
Schema.

Page 25

XML and Related Technologies

Displaying formatted
It is possible to use CSS to format an
XML
XML document.

However W3C recommend using XSLT


(extensible style sheet language
transformations) instead.

Page 26

XML and Related Technologies

XSLT

Page 27

XML and Related Technologies

XML Parser
Most browsers have a built-in XML
parser to read and manipulate XML.
Parser converts XML into a
JavaScript accessible object (XML
DOM object).

Page 28

XML and Related Technologies

XML DOM and


XMLHttpRequest
Object
XML DOM (XML Document Object Model)

defines a standard way for accessing and


manipulating XML documents.

HTML DOM (HTML Document Object Model)


defines a standard way for accessing and
manipulating HTML documents.
XML DOM and HTML DOM used together
makes it possible to display data of XML using
HTML.
The XMLHttpRequest object provides a way to
Page 29

XML and Related Technologies

XML Namespaces
XML Namespaces provide a method to
avoid element name conflicts.
Name conflicts in XML can easily be
avoided using a name prefix.

Page 30

XML and Related Technologies

XML Namespaces
When using prefixes in XML, a socalled namespace for the prefix must
be defined.
The namespace is defined by the
xmlns attribute in the start tag of an
element.
Namespace describes the prefix.
The namespace declaration has the
following syntax. xmlns:prefix="URI.
Page 31

XML and Related Technologies

XML Namespaces
When a namespace is defined for an
element, all child elements with the
same prefix are associated with the
same namespace.
The namespace URI is not used by the
parser to look up information.

Page 32

XML and Related Technologies

XML Namespaces

Page 33

XML and Related Technologies

URI (Uniform Resource


Identifier)

URI is a string of characters which


identifies an Internet Resource.

The most common URI is the


Uniform Resource Locator (URL).
Another, not so common type of
URI is the Universal Resource Name
(URN).

Page 34

XML and Related Technologies

Default Namespaces
Defining a default
namespace for an element
saves us from using prefixes
in all the child elements.

Page 35

XML and Related Technologies

XML CDATA
All text in an XML document will be
parsed by the parser.
The parser does this because
XML elements can contain other
elements.
CDATA is used about text data
that should not be parsed by
the XML parser.
Page 36

XML and Related Technologies

XML Encoding
XML documents can contain non ASCII
characters, like Norwegian , or
French .
XML Encoding may be given as
follows.
<?xml version="1.0"
encoding="UTF-16"?>
Always use the encoding attribute
Use an editor that supports encoding
Page 37

XML and Related Technologies

XML Encoding
Make sure you know what
encoding the editor uses
Use the same encoding in your
encoding attribute

Page 38

XML and Related Technologies

XML on the Server


XML files are plain text files just
like HTML files.
XML can easily be stored and
generated by a standard web
server or even database.
With ASP and PHP its simply a
matter of specifying that content
type is text/xml.
Page 39

XML and Related Technologies

XML on the Server

o generate an XML response from the server


response.ContentType="text/xml"
response.Write("<?xml version='1.0' encoding='ISO-8859-1'?>")
response.Write("<note>")
response.Write("<from>Jani</from>")
response.Write("<to>Tove</to>")
response.Write("<message>Remember me this weekend</message>")
response.Write("</note>")
%>

Page 40

XML and Related Technologies

XML Technologies
XHTML (Extensible HTML)
A stricter and cleaner XML based version of
HTML.
XML DOM (XML Document Object Model)
A standard document model for accessing and
manipulating XML.
XSL (Extensible Style Sheet Language) XSL
consists of three parts:
1.XSLT (XSL Transform) - transforms XML into
other formats, like HTML
2.XSL-FO (XSL Formatting Objects)- for
formatting XML to screen, paper, etc
3.XPath - a language for navigating XML

Page 41

XML and Related Technologies

XML Technologies
XQuery (XML Query Language)
An XML based language for querying XML data.
DTD (Document Type Definition)
A standard for defining the legal elements in an XML
document.
XSD (XML Schema)
An XML-based alternative to DTD.
XLink (XML Linking Language)
A language for creating hyperlinks in XML
documents.
XPointer (XML Pointer Language)
Allows the XLink hyperlinks to point to more specific
parts in the XML document.
Page 42

XML and Related Technologies

XML Technologies
SOAP (Simple Object Access Protocol)
An XML-based protocol to let applications exchange
information over HTTP.
WSDL (Web Services Description Language)
An XML-based language for describing web services.
RDF (Resource Description Framework)
An XML-based language for describing web resources.
RSS (Really Simple Syndication)
A format for syndicating news and the content of news-like
sites.

Page 43

XML and Related Technologies

XML Technologies
XForms (XML Forms)
Uses XML to define form data.
WAP (Wireless Application Protocol)
A XML based language for displaying content on
wireless clients, like mobile phones.
SMIL (Synchronized Multimedia Integration Langu
age)
A language for describing audiovisual
presentations.
SVG (Scalable Vector Graphics)
Defines graphics in XML format.
Page 44

XML and Related Technologies

XML Editors
Professional XML editors will help you
to write error-free XML documents.
Validate your XML against a DTD or a
schema.
Force you to stick to a valid XML
structure.
A popular XML Editor is Altova
XMLSpy.
Page 45

XML and Related Technologies

SOAP
Reference:
http://www.w3schools.com/soap/default.asp

WSDL
Reference:
http://www.w3schools.com/wsdl/default
.asp

XSL

Reference:
http://www.w3schools.com/xsl/defaul
t.asp
Page 46

Vous aimerez peut-être aussi