Вы находитесь на странице: 1из 21

XML eXtensibleMarkupLanguage

Unit V

XML Introduction
XML is to represent structured data.
XML is the most widely used for transmitting
structured data over the Web.
Eg:
<text>
This is my first XML Document
</text>

XML Introduction
XML stands for eXtensible Markup Language.
XML is designed to transport and store data.
XML was designed to carry data, not to
display data
XML tags are not predefined. You must define
your own tags
XML is designed to be self-descriptive
XML is a W3C Recommendation

XML History & Versions


XML was developed under the help of the
World Wide Web Consortium as a language for
representing documents to be communicated
over the World Wide Web.
The group that developed XML was formed
and published in 1996.
XML 1.0 was officially adopted as a W3C
recommendation in early 1998.

XML Versions
XML 1.0 has been widely adopted without the
need for substantial modification.
W3C released an XML 1.1 recommendation in
2004
The W3C at the same time encouraged those
who do not need 1.1s (relatively few) new
features to continue to use XML 1.0.

XML Declaration
The XML recommendations suggest (but do not
require) that every XML document begin with a
special tag known as an XML declaration.
<?xml version="1.0"?>
This is used to specify the version of XML used
to write the document and optionally some
additional meta-information about the
document, such as the character set/encoding
used.

XML Declaration
An encoding other than one of default
encodings may be specified by including an
encoding declaration within the XML
declaration.
<?xml version="1.0" encoding="ISO-8859-1"?
>
the version and encoding declarations must appear
in the order shown.

XML Documents
XML is a software- and hardwareindependent tool for carrying information.
XML Separates Data from HTML
With a few lines of JavaScript code, you can
read an external XML file and update the data
content of your web page.

XML Documents
- basic XML syntax rules
1. An XML document consists of markup and
character data.
2. There are two types of markup: tags and references.
3. Tags begin with a less-than (<) character and end
with a greater-than (>) character.
4. References in an XML document begin with an
ampersand (&) and are of two types: character
references (such as &#x20;) and entity references
(such as &lt;).

XML Documents
- basic XML syntax rules
5. All XML documents may make references to
the entities lt(<), gt(>), amp(&), apos('), and
quot("), Other entities may also be defined,
depending on the XML DTD used and/or
application processing the document.
6. If not used to begin markup, the characters <
and & must be escaped (an exception is that
escaping is not necessary within comments
and CDATA sections).

XML Documents
- basic XML syntax rules
7. Element tags are of three types: start tags, end
tags (which begin with </), and empty element
tags (which end with />).
8. Character data may only appear within a
nonempty element.
9. Start and end tags must be paired and must be
properly nested with other pairs of start and
end tags.

XML Documents
- basic XML syntax rules
10. Attribute specifications may appear within
start tags or empty-element tags. Every
attribute specification consists of an attribute
name followed by an equals sign (=) followed
by a quoted attribute value. Attribute
specifications are white-space-separated from
one another.
11. Element and attribute names are case
sensitive.

XML Documents
- basic XML syntax rules
12. The XML white space characters are the
same as in XHTML: space, carriage return,
line feed, and tab.
13. XML comments begin with <!--, end with
-->, and may not contain the string -elsewhere within the content of the comment.

XML Documents - CDATA section


The content of a CDATA section is interpreted
as character data, even if it contains characters
such as < and & that would normally be
interpreted as markup.
A CDATA section begins with the string <!
[CDATA[ and ends with the string ]]>.

XML Documents - CDATA section Example


<message>
The markup
<![CDATA[
<message>This & that</message>
]]>

is not valid XML because the &amp; must be escaped.

</message>
The CDATA section could be replaced with the
equivalent markup
&lt;message&gt;This &amp; that&lt;/message&gt;

Well formed XML Documents


Any document that follows the syntactic rules and
that has a single root element is an example of a
well-formed XML document.
While a syntactically correct document with two
root elements, such as
<root1>
</root1>
<root2>
</root2>

is not considered well formed.

XML Advantages
Different applications can access your data,
not only in HTML pages, but also from XML
data sources.
With XML, your data can be available to all
kinds of "reading machines" (Handheld
computers, voice machines, news feeds, etc.),
and make it more available for blind people, or
people with other disabilities.

XML Tree
<?xml version="1.0" encoding="UTF-8"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!
</body>
</note>

XML Tree
Example:

<bookstore>
<book category="COOKING">
<title lang="en">Everyday
Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="CHILDREN">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book category="WEB">
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>

What is an XML Element?


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
text
attributes
or a mix of all of the above.

Empty XML Elements <book></book> or


<book />

XML Naming Rules


XML elements must follow these naming rules:
Names can contain letters, numbers, _, - and .
Names cannot start with a number or punctuation
character
Names cannot start with the letters xml (or XML,
or Xml, etc)
Names cannot contain spaces
Any name can be used, no words are reserved.

Вам также может понравиться