Sunteți pe pagina 1din 47

 XML (Extensible Markup Language

– XML is a markup language.
– XML stands for eXtensible Markup Language.
–  The XML standard was created by W3C to provide an 
easy to use and standardized way to store self­describing 
data (self­describing data is data that describes both its 
content and its structure).

Communication Between Application
XML is nothing by itself. XML is more of a "common ground"
standard. The main benefit of XML is that you can use it to take data
from a program like MSSQL (Microsoft SQL), convert it into XML,
then share that XML with a slough of other programs and platforms

What makes XML truly powerful is the international acceptance it


has received.

Many individuals and corporations have put forth their hard work
to make XML interfaces for databases, programming, office
application, mobile phones and more.
Applications of XML

* Cell Phones - XML data is sent to some cell


phones. The data is then formatted by the specification
of the cell phone software designer to display text or
images, and even to play sounds!
* File Converters - Many applications have been
written to convert existing documents into the XML
standard. An example is a PDF to XML converter.
* VoiceXML - Converts XML documents into an
audio format so that you can listen to an XML
document.
Free XML Viewer
Internet Explorer 6.0 supports viewing XML files.
You can download IE 6.0 from Microsoft's Website. Internet
Explorer 6.0 has special color coding the make XML documents
easier to read.
Firefox XML Viewer: Firefox has some of the same features as
Internet Explorer. You can download Mozilla's Firefox from
Mozilla.com.
Free XML Editors:
There are many free XML editors available for download on the
internet. Here are a few we have found useful:
* XML Cooktop
* XML Mind Standard Edition
* Pete's XML Editor
XML Syntax: 
XML Code:
<?xml version="1.0" encoding="ISO-8859-15"?>
<class_list>
<student>
<name>Robert</name>
<grade>A+</grade>
</student>
<student>
<name>Lenard</name>
<grade>A-</grade>
</student>
</class_list>
XML code.
<?xml version="1.0" encoding="ISO-8859-15"?>
This line with special symbols and attributes is what is
referred to as the XML declaration. It simply states
what version of XML you are using and the type of
encoding you are using
XML Tag

The XML tag is very similar to that of the HTML tag.


Each element is marked with an opening tag and a
closing tag.
<name>Robert</name>
<grade>A+</grade>
XML Elements
They contain the opening and closing tags, child
elements, and data.
<student>
<name>Robert</name>
<grade>A+</grade>
</student>
XML Attribute
An attribute appears within the opening tag of
an element.
<student active="true">
<name>Robert</name>
<grade>A+</grade>
</student>
XML Attribute Quotation Usage
The types of quotes that you use around your
attribute values is entirely up to you. Both the
single quote (') and the double quote (") are
perfectly fine to use in your XML documents.
<student nickname=Rob "The Dog''>
<name>Robert</name>
<grade>A+</grade>
</student>
<student group="Pete's Pandas">
<name>Robert</name>
<grade>A+</grade>
</student>
XML Comment Syntax
<?xml version="1.0" encoding="ISO-8859-15"?>
<!-- Students grades are updated bi-monthly -->
<class_list>
<student>
<name>Robert</name>
<grade>A+</grade>
</student>
<student>
<name>Lenard</name>
<grade>A-</grade>
</student>
</class_list>
XML Commenting out XML
To temporarily remove some XML code from your XML document.
<?xml version="1.0" encoding="ISO-8859-15"?>

<class_list>

<student>

<name>Robert</name>

<grade>A+</grade>

</student>

<!--

<student>

<name>Lenard</name>

<grade>A-</grade>

</student>

-->

</class_list>
XML Prolog
The prolog is an optional component of the XML
document. If included, the prolog must be appear
before the root element. A prolog consists of two parts:
the XML declaration and the Document Type
Declaration (DTD). Depending on your needs, you can
choose to include both, either, or neither of these items
in your XML document.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML
1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
* !DOCTYPE - Tell the XML processor that this
piece of code defines the Document Type Definition
* html - Specifies the root element of the XML
document. Here our example is an HTML file, which has
<html> as the root element.
* PUBLIC - Specifies that this a publicly available
DTD.
* "-//W3C//D..." - The definition of the public
document. Describing this is beyond the scope of this
tutorial.
* "http://www.w3.org/..." - The physical location of
the DTD. Notice how this DTD resides on w3's servers.
XML Nesting

When an element appears within another element, it is


said that the inner element is "nested". The term nested
can be related directly to the word "nest". If an element
is nested within another element, then it is surrounded,
protected, or encapsulated by the outer element
Example A
<phonebook>
<number>
<name>
</number>
</name>
</phonebook>
Example B
<phonebook>
<number>
<name>
</name>
</number>

</phonebook>
All elements are closed in the order that they were
opened. Those elements which were opened first are
closed last.
Example B is what example A must look like to be a
well-formed XML document.
XML Namespaces

XML was designed to be a very robust markup language that could be used in many different

applications. However, with XML being able to communicate between so many different

platforms, there is one problem that tends to occur.

<?xml version="1.0" encoding="ISO-8859-15"?>

<html>

<body>

<p>Welcome to my Health Resource</p>

</body>

<body>

<height>6ft</height>

<weight>155 lbs</weight>

</body>

Two very different elements that want to use the same name: body. The solution to this problem is

to create XML Namespaces,


XML Documents: Valid Versus Well-Formed
In XML, there are three ways to measure a
document's validity: valid, well-formed, and broken.
* One Root Element - The XML document may
only have one root element. See our Root Element
Lesson for more information.
* Proper Nesting - XML elements must be closed
in the order they are opened. See our Nesting Lesson
for more information.
* Well-Formed Entities - Any entities that are
referenced in the document must also be well-formed.
See our Entity Lesson for more information.
Broken XML Code:
<email>
<to>Mr. Garcia
<body>Hello there! How are we today?</to>
</body>
</email>
Well-Formed XML Code:
<email>
<to>Mr. Garcia</to>
<body>Hello there! How are we today?</body>
</email>
The error in the first example was:The document suffers from improper
nesting. The body element was opened inside the to element, yet body was
not closed before the to element was closed!
XML Tree: The great benefit about XML 
is that the document itself describes the 
structure of data. 

inventory is the root element.


XML ­ The Tree Structure
Structure of an XML Document
Tree Structure

<root>
<child>
<subchild>.....</subchild>
</child>
</root>
Entity References
If you place a character like "<" inside an XML element,
it will generate an error because the parser interprets it as
the start of a new element.
<message>if salary < 1000 then</message>
<message>if salary &lt; 1000 then</message>

There are 5 predefined entity references in XML:


&lt; < less than
&gt; > greater than
&amp; & ampersand
&apos; ' apostrophe
&quot; " quotation mark
XML(Table)
XPath ­ Finding Information

XPath is the solution to finding information in an XML


document. XPath uses expressions to find elements,
attributes, and other information in your XML. If you
have an XML document that contained a bunch of your
favorite books, each with author children elements, you
can use a one line XPath expression to find all the
authors of your favorite books!
The most common place people might see XPath
expressions are in XSLT (Extensible Stylesheet
Language Transformation).
Structure of an XML Document
Structure of an XML Document
Structure of an XML Document
Structure of an XML Document
Structure of an XML Document
Structure of an XML Document
Structure of an XML Document
XML is Used to Create New Internet Languages

A lot of new Internet languages are created with XML.

Here are some examples:

* XHTML the latest version of HTML


* WSDL for describing available web services
* WAP and WML as markup languages for handheld devices
* RSS languages for news feeds
* RDF and OWL for describing resources and ontology
* SMIL for describing multimedia for the web
SMIL 2.0 – XML for Web Multimedia
– SMIL stands for Synchronized Multimedia
Integration Language
– SMIL is pronounced "smile"
– SMIL is a language for describing audiovisual
presentations
– SMIL is easy to learn and understand
– SMIL is an HTML-like language
– SMIL is written in XML
– SMIL presentations can be written using a text-
editor
– SMIL is a W3C standard
What Can SMIL Do?
Although plug-ins and media players have the ability to
show many different types of media with varying
support for interaction, only SMIL offers the ability to
define the presentation in the form of text as a script.
This feature could be called media composition.
Also, SMIL offers accessibility options and powerful
features not present in other media players.
Implementing SMIL
Common SMIL implementations

* Internet or Intranet presentations.


* Slide show presentations.
* Presentations which link to other SMIL files.
* Presentations which have Control buttons (stop, start, next, ...)
* Defining sequences and duration of multimedia elements.
* Defining position and visibility of multimedia elements.
* Displaying multiple media types such as audio, video, text
* Displaying multiple files at the same time.
* Displaying files from multiple web servers.

Currently, SMIL's most widespread usage is with MMS. MMS (Multimedia


Messaging System) is a mobile device technology
Guidelines and Rules

SMIL documents look a lot like HTML. SMIL files need to be written according to
the following rules:

* SMIL documents must follow the XML rules of well-formedness.


* SMIL tags are case sensitive.
* All SMIL tags are written with lowercase letters.
* SMIL documents must start with a <smil> tag and end with a </smil> closing
tag.
* SMIL documents must contain a <body> tag for storing the contents of the
presentation.
* SMIL documents can have a <head> element (like HTML) for storing
metadata information about the document itself, as well as presentation layout
information.
<smil>
<head>
<layout>
...
</layout>
</head>

<body>
...
</body>
</smil>
Image to our presentation

<smil>
<head>
<layout>
<root-layout width="300" height="300"
background-color="white"/>
<region id="cows" top="0" left="0"
width="300" height="197"/>
</layout>
</head>
<body>
<img src="cows.jpg" region="cows"/>
</body>
</smil>
Copy and paste this URL,
"http://html.tucows.com/designer/basictut/example1.s
mil" into your SMIL parser, i.e., RealPlayer,
QuickTime, for an example of the SMIL presentation
created
 Multiple Regions

We placed the new region, "text", 200 pixels from the top and 50 pixels from the left so that
it's centered in our presentation.
Below is a table with the possible values we can give to
the fit attribute.
We want to make the tucows.gif image fit perfectly
within the region, so we would add fit="fill" to the text
region. Below is an example.
 Time Control
You can also control how long you want a certain piece of media to be display for by
using the "dur" attribute. This attribute takes a numerical value in seconds with the letter
"s" after the number. For example, lets say we want the cows to be displayed for 10
seconds and the rest of the images for only 5. We would add "dur="10s"" to the cow's img
tag and "dur="5s"" to the rest of the img tags. Below is what our code would look like.
This should display the TUCOWS text image, then the
HTML text image during a span of 10 seconds.
SMIL for phones
MMS uses SMIL to define the layout of multimedia
content.
SMIL was adopted because it was a well-defined,
standard language to describe the layout and timing of
the content inside MMS messages.

S-ar putea să vă placă și