Académique Documents
Professionnel Documents
Culture Documents
INDEX – UNIT - V
http://www.saif4u.webs.com
2
The design goals of XML emphasize simplicity, generality, and usability over
theInternet.[6] It is a textual data format with strong support via Unicode for the
languages of the world. Although the design of XML focuses on documents, it is widely
used for the representation of arbitrary data structures, for example in web services.
Many application programming interfaces (APIs) have been developed that software
developers use to process XML data, and several schema systems exist to aid in the
definition of XML-based languages.
What is XML?
• XML was designed to transport and store data, with focus on what data is
• HTML was designed to display data, with focus on how data looks
http://www.saif4u.webs.com
3
Maybe it is a little hard to understand, but XML does not DO anything. XML was created
to structure, store, and transport information.
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
The note above is quite self descriptive. It has sender and receiver information, it also
has a heading and a message body.
But still, this XML document does not DO anything. It is just information wrapped in
tags. Someone must write a piece of software to send, receive or display it.
The tags in the example above (like <to> and <from>) are not defined in any XML
standard. These tags are "invented" by the author of the XML document.
The tags used in HTML are predefined. HTML documents can only use tags defined in
the HTML standard (like <p>, <h1>, etc.).
XML allows the author to define his/her own tags and his/her own document structure.
It is important to understand that XML is not a replacement for HTML. In most web
applications, XML is used to transport data, while HTML is used to format and display
the data.
http://www.saif4u.webs.com
4
XML is Everywhere
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.
http://www.saif4u.webs.com
5
<?xml version="1.0"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
http://www.saif4u.webs.com
6
Below is an example of how to use a CSS style sheet to format an XML document:
XSLT can be used to transform XML into HTML, before it is displayed by a browser:
XML XSLT
<?xml version="1.0" encoding="ISO-8859-1"?> <?xml version="1.0"
<!-- Edited by XMLSpy® --> encoding="ISO-8859-1"?>
<breakfast_menu> <!-- Edited by XMLSpy® -->
<food> <html xsl:version="1.0"
<name>Belgian Waffles</name> xmlns:xsl="http://www.w3.org/1
<price>$5.95</price> 999/XSL/Transform"
<description>two of our famous Belgian Waffles with plenty xmlns="http://www.w3.org/1999
of real maple syrup</description> /xhtml">
<calories>650</calories> <body style="font-
</food> family:Arial;font-
<food> size:12pt;background-
<name>Strawberry Belgian Waffles</name> color:#EEEEEE">
<price>$7.95</price> <xsl:for-each
<description>light Belgian waffles covered with strawberries select="breakfast_menu/food">
and whipped cream</description> <div style="background-
<calories>900</calories> color:teal;color:white;padding:4p
</food> x">
<food> <span style="font-
http://www.saif4u.webs.com
7
OUTPUT
http://www.saif4u.webs.com
8
XPointer allows the hyperlinks to point to more specific parts in the XML document.
What is XLink?
• XLink is short for XML Linking Language
• XLink is used to create hyperlinks in XML documents
• Any element in an XML document can behave as a link
• XLink supports simple links (like HTML) and extended
links (for linking multiple resources together)
• With XLink, the links can be defined outside the linked
files
• XLink is a W3C Recommendation
XLink Syntax
In HTML, we know (and all the browsers know!) that the <a> element defines a
hyperlink. However, this is not how it works with XML. In XML documents, you can use
whatever element names you want - therefore it is impossible for browsers to predict
what hyperlink elements will be called in XML documents.
The solution for creating links in XML documents was to put a marker on elements that
should act as hyperlinks.
Below is a simple example of how to use XLink to create links in an XML document:
<?xml version="1.0"?>
<homepages xmlns:xlink="http://www.w3.org/1999/xlink">
<homepage xlink:type="simple"
xlink:href="http://www.w3schools.com">Visit W3Schools</homepage>
<homepage xlink:type="simple"
xlink:href="http://www.w3.org">Visit W3C</homepage>
</homepages>
To get access to the XLink attributes and features we must declare the XLink
namespace at the top of the document.
http://www.saif4u.webs.com
9
The xlink:type and the xlink:href attributes in the <homepage> elements define that the
type and href attributes come from the xlink namespace.
The xlink:type="simple" creates a simple, two-ended link (means "click from here to go
there"). We will look at multi-ended (multidirectional) links later.
<bookstore xmlns:xlink="http://www.w3.org/1999/xlink">
</bookstore>
http://www.saif4u.webs.com
10
The DOM defines a standard for accessing documents like XML and HTML:
"The W3C Document Object Model (DOM) is a platform and language-neutral interface
that allows programs and scripts to dynamically access and update the content,
structure, and style of a document."
The DOM defines the objects and properties of all document elements, and
the methods (interface) to access them.
http://www.saif4u.webs.com
11
The XML DOM defines the objects and properties of all XML elements, and
the methods (interface) to access them.
In other words: The XML DOM is a standard for how to get, change, add, or delete
XML elements.
http://www.saif4u.webs.com
12
XQuery 1.0 was developed by the XML Query working group of the W3C. The work was
closely coordinated with the development of XSLT 2.0 by the XSL Working Group; the
two groups shared responsibility for XPath 2.0, which is a subset of XQuery 1.0. XQuery
1.0 became a W3C Recommendation on January 23, 2007.
"The mission of the XML Query project is to provide flexible query facilities to extract
data from real and virtual documents on the World Wide Web, therefore finally providing
the needed interaction between the Web world and the database world. Ultimately,
collections of XML files will be accessed like databases".[1]
What is XQuery?
"Select all CD records with a price less than $10 from the CD collection stored in the
XML document called cd_catalog.xml"
http://www.saif4u.webs.com
13
• XQuery is case-sensitive
• XQuery elements, attributes, and variables must be valid XML names
• An XQuery string value can be in single or double quotes
• An XQuery variable is defined with a $ followed by a name, e.g. $bookstore
• XQuery comments are delimited by (: and :), e.g. (: XQuery Comment :)
for $x in doc("books.xml")/bookstore/book
return if ($x/@category="CHILDREN")
then <child>{data($x/title)}</child>
else <adult>{data($x/title)}</adult>
<adult>Everyday Italian</adult>
<child>Harry Potter</child>
<adult>Learning XML</adult>
<adult>XQuery Kick Start</adult>
http://www.saif4u.webs.com
14
XQuery Comparisons
In XQuery there are two ways of comparing values.
The difference between the two comparison methods are shown below.
The following expression returns true if any q attributes have a value greater than 10:
$bookstore//book/@q > 10
The following expression returns true if there is only one q attribute returned by the
expression, and its value is greater than 10. If more than one q is returned, an error
occurs:
$bookstore//book/@q gt 10
Examples
The sample XQuery code below lists the unique speakers in each act of Shakespeare's
play Hamlet, encoded in hamlet.xml
<html><head/><body>
{
for $act in doc("hamlet.xml")//ACT
let $speakers := distinct-values($act//SPEAKER)
return
<div>
<h1>{ string($act/TITLE) }</h1>
<ul>
{
for $speaker in $speakers
return <li>{ $speaker }</li>
}
</ul>
</div>
}
</body></html>
http://www.saif4u.webs.com