SlideShare a Scribd company logo
1 of 44
Download to read offline
7/9/2019
1
XML
Extensible Markup Language
Prepared By: Dr.Saranya.K.G
SGML (Standard Generalized
Markup Language)
• It is an internationally agreed standard for data representation.
• It is an international standard for the definition of device
independent, system independent methods of representing texts
in electronic form.
Prepared By: Dr.Saranya.K.G
7/9/2019
2
Introduction
• XML stands for EXtensible Markup Language
• XML is a markup language much like HTML. A markup language is
used to provide information about a document.
• A simplified version of SGML
• More flexible and adaptable than HTML
• XML was designed to describe data
Prepared By: Dr.Saranya.K.G
• Tags are added to the document to provide the extra
information.
• HTML tags tell a browser how to display the document.
• XML tags give a reader some idea what some of the data
means.
• XML tags are not predefined. You must define your own tags
• XML uses a Document Type Definition (DTD) or an XML
Schema to describe the data
Prepared By: Dr.Saranya.K.G
7/9/2019
3
• XML was designed to store and transport data.
• XML was designed to be both human- and machine-readable.
• XML is often used for distributing data over the Internet.
• XML is a W3C Recommendation.
• World Wide Web Consortium published the first XML 1.0 standard
definition in 1998.
Prepared By: Dr.Saranya.K.G
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!
</body>
</note>
The XML above is quite self-descriptive:
• It has sender information.
• It has receiver information
• It has a heading
• It has a message body.
But still, the XML above does not DO anything. XML is just information
wrapped in tags.
Note
To: Tove
From: Jani
Reminder
Don't forget me
this weekend!
Prepared By: Dr.Saranya.K.G
7/9/2019
4
XML Does Not Use Predefined Tags
• The XML language has no predefined tags.
• 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.
• HTML works with predefined tags like <p>, <h1>, <table>, etc.
• With XML, the author must define both the tags and the document
structure.
Prepared By: Dr.Saranya.K.G
XML is Extensible
• Most XML applications will work as expected even if new data is added
(or removed).
• Imagine an application designed to display the original version of note.xml
(<to> <from> <heading> <body>).
• Then imagine a newer version of note.xml with added <date> and <hour>
elements, and a removed <heading>.
• The way XML is constructed, older version of the application can still
work:
Prepared By: Dr.Saranya.K.G
7/9/2019
5
<note>
<date>2015-09-01</date>
<hour>08:30</hour>
<to>Tove</to>
<from>Jani</from>
<body>Don't forget me this
weekend!</body>
</note>
Older Version
Note
To: Tove
From: Jani
Reminder
Don't forget me this weekend!
New Version
Note
To: Tove
From: Jani
Date: 2015-09-01 08:30
Don't forget me this weekend!
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this
weekend! </body>
</note>
Prepared By: Dr.Saranya.K.G
XML Simplifies Things
• It simplifies data sharing
• It simplifies data transport
• It simplifies platform changes
• It simplifies data availability
Many computer systems contain data in incompatible formats. Exchanging data between incompatible systems (or
upgraded systems) is a time-consuming task for web developers. Large amounts of data must be converted, and
incompatible data is often lost.
XML stores data in plain text format. This provides a software- and hardware-independent way of storing, transporting,
and sharing data.
XML also makes it easier to expand or upgrade to new operating systems, new applications, or new browsers, without
losing data.
With XML, data can be available to all kinds of "reading machines" like people, computers, voice machines, news feeds,
etc. Prepared By: Dr.Saranya.K.G
7/9/2019
6
XML is a W3C Recommendation
XML Separates Data from Presentation
• XML does not carry any information about how to be displayed.
• The same XML data can be used in many different presentation
scenarios.
• Because of this, with XML, there is a full separation between data and
presentation.
Prepared By: Dr.Saranya.K.G
XML is Often a Complement to HTML
In many HTML applications, XML is used to store or transport data, while HTML is used
to format and display the same data.
XML Separates Data from HTML
• When displaying data in HTML, you should not have to edit the HTML file
when the data changes.
• With XML, the data can be stored in separate XML files.
• With a few lines of JavaScript code, you can read an XML file and update the
data content of any HTML page.
Prepared By: Dr.Saranya.K.G
7/9/2019
7
Difference between XML and HTML
The main difference between XML and HTML
• XML was designed to carry data. (XML is not a replacement for HTML)
XML and HTML were designed with different goals:
• XML was designed to describe data and to focus on what data is.
HTML was designed to display data and to focus on how data looks.
• HTML is about displaying information, while XML is about describing
information.
• XML tags are not predefined like HTML tags are
Prepared By: Dr.Saranya.K.G
What is XML Used For?
• XML documents are used to transfer data from one place to another often over the
Internet.
• XML subsets are designed for particular applications.
• One is RSS (Rich Site Summary or Really Simple Syndication ). It is used to send
breaking news bulletins from one web site to another.
• A number of fields have their own subsets. These include chemistry, mathematics,
and books publishing.
• Most of these subsets are registered with the W3Consortium and are available for
anyone’s use. Prepared By: Dr.Saranya.K.G
7/9/2019
8
Why Is XML Important?
• Plain Text
• Easy to edit
• Possible to efficiently store large amounts of XML data through an XML
front end to a database
• Data Identification
• Tell you what kind of data you have
• Can be used in different ways by different applications
Prepared By: Dr.Saranya.K.G
Why is XML important?
• Linkability -- XLink and XPointer
• Simple unidirectional hyperlinks
• Two-way links
• Multiple-target links
• “Expanding” links
• Easily Processed
• Regular and consistent notation
• Hierarchical
• Faster to access
• Easier to rearrange
Prepared By: Dr.Saranya.K.G
7/9/2019
9
Advantages of XML
• XML is text (Unicode) based.
• Takes up less space.
• Can be transmitted efficiently.
• One XML document can be displayed differently in different media.
• Html, video, CD, DVD,
• You only have to change the XML document in order to change all the rest.
• XML documents can be modularized. Parts can be reused.
Prepared By: Dr.Saranya.K.G
XML Specifications
•XML 1.0
Defines the syntax of XML
•XPointer, XLink
Defines a standard way to represent links between resources
•XSL
Defines the standard style sheet language for XML
Prepared By: Dr.Saranya.K.G
7/9/2019
10
XML Tree Structure
XML Structure
XML documents form a tree structure that starts at "the root" and branches to "the leaves".
Prepared By: Dr.Saranya.K.G
XML Trees
• An XML document has a single root node.
• The tree is a general ordered tree.
• A parent node may have any number of children.
• Child nodes are ordered, and may have siblings.
• Preorder traversals are usually used for getting
information out of the tree.
<root>
<child>
<subchild>.....</subchild>
</child>
</root>
Prepared By: Dr.Saranya.K.G
7/9/2019
11
<?xml version="1.0" encoding="UTF-8"?>
<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>
Category Title Author Year Price
Cooking Everyday
Italian
Giada De
Laurentiis
2005 30.00
children Harry Potter J K. Rowling 2005 29.99
web Learning XML Erik T. Ray 2003 39.95
Book Store Details:
Prepared By: Dr.Saranya.K.G
A prolog defines the XML version and the character encoding:
<?xml version="1.0" encoding="UTF-8"?>
The next line is the root element of the document:
<bookstore>
The next line starts a <book> element:
<book category="cooking">
Prepared By: Dr.Saranya.K.G
7/9/2019
12
The <book> elements have 4 child elements: <title>, <author>, <year>, <price>.
<title lang="en">Everyday
Italian</title>
<author>Giada De
Laurentiis</author>
<year>2005</year>
<price>30.00</price>
The next line ends the book element:
</book>
Prepared By: Dr.Saranya.K.G
Expanded Example
<?xml version = “1.0” ?>
<address>
<name>
<first> Alice </first>
<last> Lee </last>
</name>
<email> alee@aol.com </email>
<phone> 123-45-6789 </phone>
<birthday>
<year> 1983 </year>
<month> 07 </month>
<day> 15 </day>
</birthday>
</address>
Prepared By: Dr.Saranya.K.G
7/9/2019
13
XML Files are Trees
address
name email phone birthday
first last year month day
Prepared By: Dr.Saranya.K.G
XML SYNTAX
Prepared By: Dr.Saranya.K.G
7/9/2019
14
XML Syntax Rules
The syntax rules of XML are very simple and logical. The rules are easy to learn, and easy
to use.
1. XML Documents Must Have a Root Element
XML documents must contain one root element that is the parent of all other elements:
<root>
<child>
<subchild>.....</subchild>
</child>
</root>
Prepared By: Dr.Saranya.K.G
In this example <note> is the root element:
<?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>
Example
Prepared By: Dr.Saranya.K.G
7/9/2019
15
The XML Prolog
The above line is called as the XML prolog
<?xml version="1.0" encoding="UTF-8"?>
• The XML prolog is optional. If it exists, it must come first in the document.
• XML documents can contain international characters, like Norwegian øæå or
French êèÊ.
• To avoid errors, you should specify the encoding used, or save your XML files as
UTF-8.
• UTF-8 is the default character encoding for XML documents.
Prepared By: Dr.Saranya.K.G
2. All XML Elements Must Have a Closing Tag
<p>This is a paragraph.</p>
<br />
The XML prolog does not have a closing tag! This is not an error. The prolog is not a
part of the XML document.
Prepared By: Dr.Saranya.K.G
7/9/2019
16
3. XML Tags are Case Sensitive
• XML tags are case sensitive. The tag <Letter> is different from the tag <letter>.
• Opening and closing tags must be written with the same case:
<message>This is correct</message>
"Opening and closing tags" are often referred to as "Start and end tags". Use
whatever you prefer. It is exactly the same thing.
Prepared By: Dr.Saranya.K.G
4. XML Elements Must be Properly Nested
In HTML, you might see improperly nested elements:
<b><i>This text is bold and italic</b></i>
In XML, all elements must be properly nested within each other:
<b><i>This text is bold and italic</i></b>
In the example above, "Properly nested" simply means that since the <i> element is
opened inside the <b> element, it must be closed inside the <b> element.
Prepared By: Dr.Saranya.K.G
7/9/2019
17
5. XML Attribute Values Must Always be Quoted
• XML elements can have attributes in name/value pairs just like in HTML.
In XML, the attribute values must always be quoted:
<note date="12/11/2007“>
<to>Tove</to>
<from>Jani</from>
</note>
Prepared By: Dr.Saranya.K.G
6. Entity References
• Some characters have a special meaning in XML.
• 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.
This will generate an XML error:
<message> salary < 1000 </message>
To avoid this error, replace the "<" character with an entity reference:
Prepared By: Dr.Saranya.K.G
7/9/2019
18
<message> salary &lt; 1000 </message>
There are 5 pre-defined entity references in XML:
&lt; < less than
&gt; > greater than
&amp; & ampersand
&apos; ' apostrophe
&quot; " quotation mark
Only < and & are strictly illegal in XML, but it is a good habit to replace > with &gt;
as well.
Prepared By: Dr.Saranya.K.G
7. Comments in XML
The syntax for writing comments in XML is similar to that of HTML:
<!-- This is a comment -->
Two dashes in the middle of a comment are not allowed:
<!-- This is an invalid -- comment -->
Prepared By: Dr.Saranya.K.G
7/9/2019
19
8. White-space is Preserved in XML
• XML does not truncate multiple white-spaces (HTML truncates multiple
white-spaces to one single white-space):
XML: Hello Tove
HTML: Hello Tove
Prepared By: Dr.Saranya.K.G
9. XML Stores New Line as LF
• Windows applications store a new line as: carriage return and line
feed (CR+LF).
• Unix and Mac OSX uses LF.
• Old Mac systems uses CR.
• XML stores a new line as LF.
Prepared By: Dr.Saranya.K.G
7/9/2019
20
XML Syntax (Summary)
• XML declaration is the first statement. (Prolog)
• All XML elements must have a closing tag
• XML tags are case sensitive
• All XML elements must be properly nested
• All XML documents must have a root tag
• Attribute values must always be quoted
• With XML, white space is preserved
• Comments in XML: <!-- This is a comment -->
• Certain characters are reserved for parsing
Prepared By: Dr.Saranya.K.G
XML Elements
Prepared By: Dr.Saranya.K.G
7/9/2019
21
What is an XML Element?
• An XML element is everything from (including) the element's start tag to
(including) the element's end tag.
<price>29.99</price>
An element can contain:
• text
• attributes
• other elements
• or a mix of the above
Prepared By: Dr.Saranya.K.G
<bookstore>
<book category="children">
<title>Harry Potter</title>
<author>J K.
Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book category="web">
<title>Learning XML</title>
<author>Erik T.
Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore> Prepared By: Dr.Saranya.K.G
7/9/2019
22
In the example above:
<title>, <author>, <year>, and <price> have text content because they
contain text (like 29.99).
<bookstore> and <book> have element contents, because they contain
elements.
<book> has an attribute (category="children").
Prepared By: Dr.Saranya.K.G
Empty XML Elements
• An element with no content is said to be empty.
• In XML, you can indicate an empty element like this:
<element></element>
You can also use a so called self-closing tag:
<element />
Empty elements can have attributes.
Prepared By: Dr.Saranya.K.G
7/9/2019
23
XML Naming Rules
XML elements must follow these naming rules:
• Element names are case-sensitive
• Element names must start with a letter or underscore
• Element names cannot start with the letters xml (or XML, or Xml, etc)
• Element names can contain letters, digits, hyphens, underscores, and
periods
• Element names cannot contain spaces
• Any name can be used, no words are reserved (except xml).
Prepared By: Dr.Saranya.K.G
Best Naming Practices
• Create descriptive names, like this: <person>, <firstname>, <lastname>.
• Create short and simple names, like this: <book_title> not like this:
<the_title_of_the_book>.
• Avoid "-". If you name something "first-name", some software may think you want to
subtract "name" from "first".
• Avoid ".". If you name something "first.name", some software may think that "name" is a
property of the object "first".
• Avoid ":". Colons are reserved for namespaces (more later).
• Non-English letters like éòá are perfectly legal in XML, but watch out for problems if your
software doesn't support them.
Prepared By: Dr.Saranya.K.G
7/9/2019
24
Naming Styles
Style Example Description
Lower case <firstname> All letters lower case
Upper case <FIRSTNAME> All letters upper case
Underscore <first_name> Underscore separates words
Pascal case <FirstName> Uppercase first letter in each word
Camel case <firstName>
Uppercase first letter in each word except
the first
• If you choose a naming style, it is good to be consistent!
• XML documents often have a corresponding database. A common practice is to
use the naming rules of the database for the XML elements.
• Camel case is a common naming rule in JavaScripts.
Prepared By: Dr.Saranya.K.G
XML Elements are Extensible
• XML elements can be extended to carry more information.
Look at the following XML example:
<note>
<to>Tove</to>
<from>Jani</from>
<body>Don't forget me this weekend!</body>
</note>
Prepared By: Dr.Saranya.K.G
7/9/2019
25
Let's imagine that we created an application that extracted the <to>, <from>, and
<body> elements from the XML document to produce this output:
MESSAGE To: Tove
From: Jani
Don't forget me this weekend!
Imagine that the author of the XML document added some extra information to it
<note>
<date>2008-01-10</date>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
Prepared By: Dr.Saranya.K.G
• Should the application break or crash?
• No. The application should still be able to find the <to>, <from>,
and <body> elements in the XML document and produce the
same output.
• This is one of the beauties of XML. It can be extended without
breaking applications.
Prepared By: Dr.Saranya.K.G
7/9/2019
26
XML Attributes
• Attributes are designed to contain data related to a specific element.
• XML attributes are used to describe XML elements or to provide
additional information about elements.
• Attributes provide additional information that is not part of the data.
Ex:
<Book no=“99-2456” media=“CD”></Book>
Prepared By: Dr.Saranya.K.G
XML Attributes Must be Quoted
• Attribute values must always be quoted. Either single or
double quotes can be used.
• For a person's gender, the <person> element can be written
like this:
<person gender="female">
or like this:
<person gender='female'>
Prepared By: Dr.Saranya.K.G
7/9/2019
27
If the attribute value itself contains double quotes you can use single quotes,
like in this example:
<gangster name='George "Shotgun" Ziegler'>
or you can use character entities:
<gangster name="George &quot;Shotgun&quot; Ziegler">
Prepared By: Dr.Saranya.K.G
XML Elements vs. Attributes
<person gender="female">
<firstname>Anna</firstname>
<lastname>Smith</lastname>
</person>
<person>
<gender>female</gender>
<firstname>Anna</firstname>
<lastname>Smith</lastname>
</person>
• In the first example gender is an attribute. In the last, gender is an element. Both
examples provide the same information.
• There are no rules about when to use attributes or when to use elements in XML.
Prepared By: Dr.Saranya.K.G
7/9/2019
28
Consider the following three XML documents contain exactly the same information:
A date attribute is used in the first example:
<note date="2008-01-10">
<to>Tove</to>
<from>Jani</from>
</note>
A <date> element is used in the second example:
<note>
<date>2008-01-10</date>
<to>Tove</to>
<from>Jani</from>
</note>
An expanded <date> element is used in the third example:
<note>
<date>
<year>2008</year>
<month>01</month>
<day>10</day>
</date>
<to>Tove</to>
<from>Jani</from>
</note> Prepared By: Dr.Saranya.K.G
Avoid XML Attributes?
Some things to consider when using attributes are:
• attributes cannot contain multiple values (elements can)
• attributes cannot contain tree structures (elements can)
• attributes are not easily expandable (for future changes)
Don't end up like this:
<note day="10" month="01" year="2008"
to="Tove" from="Jani" heading="Reminder"
body="Don't forget me this weekend!">
</note>
Prepared By: Dr.Saranya.K.G
7/9/2019
29
XML Attributes for Metadata
• Sometimes ID references are assigned to elements. These IDs can be
used to identify XML elements in much the same way as the id
attribute in HTML. This example demonstrates this:
<messages>
<note id="501">
<to>Tove</to>
<from>Jani</from>
Prepared By: Dr.Saranya.K.G
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
<note id="502">
<to>Jani</to>
<from>Tove</from>
<heading>Re: Reminder</heading>
<body>I will not</body>
</note>
</messages>
The id attributes above are for identifying the different notes. It is not a part of the note itself.
Metadata (data about data) should be stored as attributes, and the data itself should be
stored as elements.
Prepared By: Dr.Saranya.K.G
7/9/2019
30
XML Specifications
• XML 1.0
Defines the syntax of XML
• XPointer, XLink
Defines a standard way to represent links between resources
• XSL
Defines the standard stylesheet language for XML
Prepared By: Dr.Saranya.K.G
XML Validation
There are two types of XML documents
• "Well Formed" XML document
--correct XML syntax
• "Valid" XML document
• “well formed”
• Conforms to the rules of a DTD (Document Type Definition)
• XML DTD
• defines the legal building blocks of an XML document
• Can be inline in XML or as an external reference
• XML Schema
• an XML based alternative to DTD, more powerful
• Support namespace and data types
Prepared By: Dr.Saranya.K.G
7/9/2019
31
Displaying XML
• XML documents do not carry information about how to
display the data
• We can add display information to XML with
• CSS (Cascading Style Sheets)
• XSL (eXtensible Stylesheet Language) --- preferred
Prepared By: Dr.Saranya.K.G
XML support in IE 5.0+
Internet Explorer 5.0 has the following XML support:
• Viewing of XML documents
• Full support for W3C DTD standards
• Binding XML data to HTML elements
• Transforming and displaying XML with XSL
• Displaying XML with CSS
• Access to the XML DOM (Document Object Model)
*Netscape 6.0 also have full XML support
Prepared By: Dr.Saranya.K.G
7/9/2019
32
XML features
• XML uses the concept of document type and hence a DTD (Document
Type Definition) to describe data
• XML with DTD is self descriptive
• XML separates data from display formats
• XML can be used as a format to exchange data
Prepared By: Dr.Saranya.K.G
XML Syntax consists of
• XML Declaration
• XML Elements
• XML Attributes
• The first line of an XML document should always consist of an
XML declaration defining the version of XML
Prepared By: Dr.Saranya.K.G
7/9/2019
33
General Structure
<root>
<child>
<subchild>…….</subchild>
</child>
</root>
Prepared By: Dr.Saranya.K.G
Main Components of an XML Document
• Elements: <hello>
• Attributes: <item id=“33905”>
• Entities: &lt; (<)
• Advanced Components
• CData Sections
• Processing Instructions
Prepared By: Dr.Saranya.K.G
7/9/2019
34
XML strengths
• Its ability to describe data
• Its ability to structure data
• Separate display from structure
• Supported by industry
• Availability of tools
Prepared By: Dr.Saranya.K.G
XML applications
• B2B
• EDI
• Journal publishing
• Database development
Prepared By: Dr.Saranya.K.G
7/9/2019
35
An example of XML
<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<to>XXX</to>
<from>YYY</from>
<heading>XML</heading>
<body> Extensible Markup Language </body>
</note>
Prepared By: Dr.Saranya.K.G
Contents of the ProductList.xml Document
Prepared By: Dr.Saranya.K.G
7/9/2019
36
• The first line represents the XML document declaration and it is
mandatory.
• Every XML has a root element. In our example, the second line is
the root element - <ProductList>
• The root element can contain child elements. In our example,
Product is the child element of ProductList
• Each element can contain sub-elements.
• <P_CODE>,<P_PRICE> are sub-elements.
Prepared By: Dr.Saranya.K.G
Example
<?xml version="1.0" encoding= "ISO-8859-1" ?>
<book>
<title> XML </title>
<chapter> introduction to xml
<para>Markup languages</para>
<para>Features of XML</para>
</chapter>
<chapter>XML syntax
<para>Elements must be enclosed in tags</para>
<para>Elements must be properly nested</para>
</chapter>
</book>
Prepared By: Dr.Saranya.K.G
7/9/2019
37
XML Architecture
Prepared By: Dr.Saranya.K.G
How do you get the data?
XML
data
Parser Information
structure
(tree+links)
Documents, stylesheets, and other data can all be expressed in XML.
DOM Interface
Any application can
plug in via an API
called “Document
Object Model”
DTD/Schema
This model can work locally or over a network.
Parsing, tree-building, and access can shift between
client/server
Prepared By: Dr.Saranya.K.G
7/9/2019
38
XML Parser
• All modern browsers have a built-in XML parser.
• An XML parser converts an XML document into an XML DOM object -
which can then be manipulated with a JavaScript.
XML DOM
• A DOM (Document Object Model) defines a standard way for accessing
and manipulating XML documents.
Prepared By: Dr.Saranya.K.G
XML Namespaces
• XML Namespaces provide a method to avoid element name conflicts.
• This XML carries HTML table information:
<table>
<tr>
<td>Apples</td>
<td>Bananas</td>
</tr>
</table>
Prepared By: Dr.Saranya.K.G
7/9/2019
39
• This XML carries information about a table (a piece of furniture):
<table>
<name>African Coffee Table</name>
<width>80</width>
<length>120</length>
</table>
• If these XML fragments were added together, there would be a name
conflict.
• Both contain a <table>element, but the elements have different content
and meaning.
• An XML parser will not know how to handle these differences.
Prepared By: Dr.Saranya.K.G
Solving the Name Conflict Using a Prefix
• Name conflicts in XML can easily be avoided using a name prefix.
• This XML carries information about an HTML table, and a piece of furniture:
<h:table>
<h:tr>
<h:td>Apples</h:td>
<h:td>Bananas</h:td>
</h:tr>
</h:table>
<f:table>
<f:name>African Coffee Table</f:name>
<f:width>80</f:width>
<f:length>120</f:length>
</f:table> Prepared By: Dr.Saranya.K.G
7/9/2019
40
• In the example above, there will be no conflict because the
two <table> elements have different names.
Prepared By: Dr.Saranya.K.G
XML Namespaces - The xmlns Attribute
• When using prefixes in XML, a so-called namespace for the prefix
must be defined.
• The namespace is defined by the xmlns attribute in the start tag
of an element.
• The namespace declaration has the following syntax.
xmlns:prefix="URI".
Prepared By: Dr.Saranya.K.G
7/9/2019
41
<root>
<h:table xmlns:h="http://www.w3.org/TR/html4/">
<h:tr>
<h:td>Apples</h:td>
<h:td>Bananas</h:td>
</h:tr>
</h:table>
<f:table xmlns:f="http://www.w3schools.com/furniture">
<f:name>African Coffee Table</f:name>
<f:width>80</f:width>
<f:length>120</f:length>
</f:table>
</root>
XML Namespaces - The xmlns Attribute
Prepared By: Dr.Saranya.K.G
• In the example above, the xmlns attribute in the <table> tag give the
h: and f: prefixes a qualified namespace.
• When a namespace is defined for an element, all child elements
with the same prefix are associated with the same namespace.
• Namespaces can be declared in the elements where they are used or
in the XML root element:
Prepared By: Dr.Saranya.K.G
7/9/2019
42
URI
• Uniform Resource Identifier (URI)
• A Uniform Resource Identifier (URI) is a string of characters which identifies
an Internet Resource.
• The most common URI is the Uniform Resource Locator (URL) which identifies
an Internet domain address. Another, not so common type of URI is the
Universal Resource Name (URN).
Prepared By: Dr.Saranya.K.G
PCDATA - Parsed Character Data
• XML parsers normally parse all the text in an XML document.
• When an XML element is parsed, the text between the XML tags is
also parsed:
<message>This text is also parsed</message>
Prepared By: Dr.Saranya.K.G
7/9/2019
43
<name><first>Bill</first><last>Gates</last></name>
The parser does this because XML elements can contain other elements, as in
this example, where the <name> element contains two other elements (first
and last): and the parser will break it up into sub-elements like this:
<name>
<first>Bill</first>
<last>Gates</last>
</name
Parsed Character Data (PCDATA) is a term used about text data that will be
parsed by the XML parser. Prepared By: Dr.Saranya.K.G
CDATA - (Unparsed) Character Data
• The term CDATA is used about text data that should not be parsed by the XML
parser.
• Characters like "<" and "&" are illegal in XML elements.
• "<" will generate an error because the parser interprets it as the start of a new
element.
• "&" will generate an error because the parser interprets it as the start of an
character entity.
• Some text, like JavaScript code, contains a lot of "<" or "&" characters. To
avoid errors script code can be defined as CDATA.
Prepared By: Dr.Saranya.K.G
7/9/2019
44
• Everything inside a CDATA section is ignored by the parser.
• A CDATA section starts with "<![CDATA[" and ends with "]]>":
<script>
<![CDATA[
function matchwo(a,b)
{
if (a < b && a < 0) then
{
return 1;
}
else
{
return 0;
}
}
]]>
</script>
In this example, everything inside the CDATA section is ignored by the
parser
Prepared By: Dr.Saranya.K.G
Conclusion
• XML is a self-descriptive language
• XML is a powerful language to describe structure data for web application
• XML is currently applied in many fields
• Many vendors already supports or will support XML
• XML Documents can be validated through the use of DTD and XSD
documents
• XML impacts B2B data exchanges, legacy system integration, web page
development, database system integration.
Prepared By: Dr.Saranya.K.G

More Related Content

Similar to XML-INTRODUCTION.pdf (20)

Xml passing in java
Xml passing in javaXml passing in java
Xml passing in java
 
XML
XMLXML
XML
 
xml
xmlxml
xml
 
Unit iv xml dom
Unit iv xml domUnit iv xml dom
Unit iv xml dom
 
Markup For Dummies (Russ Ward)
Markup For Dummies (Russ Ward)Markup For Dummies (Russ Ward)
Markup For Dummies (Russ Ward)
 
1 xml fundamentals
1 xml fundamentals1 xml fundamentals
1 xml fundamentals
 
Xml
XmlXml
Xml
 
Xml unit1
Xml unit1Xml unit1
Xml unit1
 
WEB TECHNOLOGIES XML
WEB TECHNOLOGIES XMLWEB TECHNOLOGIES XML
WEB TECHNOLOGIES XML
 
Xml
XmlXml
Xml
 
XML1.pptx
XML1.pptxXML1.pptx
XML1.pptx
 
Xml material
Xml materialXml material
Xml material
 
Xml material
Xml materialXml material
Xml material
 
Xml material
Xml materialXml material
Xml material
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
 
BITM3730Week5.pptx
BITM3730Week5.pptxBITM3730Week5.pptx
BITM3730Week5.pptx
 
XML.pptx
XML.pptxXML.pptx
XML.pptx
 
Xml
XmlXml
Xml
 
Xml
XmlXml
Xml
 
XML, XML Databases and MPEG-7
XML, XML Databases and MPEG-7XML, XML Databases and MPEG-7
XML, XML Databases and MPEG-7
 

More from KGSCSEPSGCT

Introduction to Distributed Systems
Introduction to Distributed SystemsIntroduction to Distributed Systems
Introduction to Distributed SystemsKGSCSEPSGCT
 
Unit4_Managing Contracts.ppt
Unit4_Managing Contracts.pptUnit4_Managing Contracts.ppt
Unit4_Managing Contracts.pptKGSCSEPSGCT
 
WSstandards.ppt
WSstandards.pptWSstandards.ppt
WSstandards.pptKGSCSEPSGCT
 
REST Introduction.ppt
REST Introduction.pptREST Introduction.ppt
REST Introduction.pptKGSCSEPSGCT
 
3-SchemaExamples.pdf
3-SchemaExamples.pdf3-SchemaExamples.pdf
3-SchemaExamples.pdfKGSCSEPSGCT
 
Converting DTDs to XML Schemas.pdf
Converting DTDs to XML Schemas.pdfConverting DTDs to XML Schemas.pdf
Converting DTDs to XML Schemas.pdfKGSCSEPSGCT
 
XSL- XSLT.pdf
XSL- XSLT.pdfXSL- XSLT.pdf
XSL- XSLT.pdfKGSCSEPSGCT
 

More from KGSCSEPSGCT (11)

Introduction to Distributed Systems
Introduction to Distributed SystemsIntroduction to Distributed Systems
Introduction to Distributed Systems
 
Unit4_Managing Contracts.ppt
Unit4_Managing Contracts.pptUnit4_Managing Contracts.ppt
Unit4_Managing Contracts.ppt
 
WSstandards.ppt
WSstandards.pptWSstandards.ppt
WSstandards.ppt
 
UDDI.ppt
UDDI.pptUDDI.ppt
UDDI.ppt
 
ROA.ppt
ROA.pptROA.ppt
ROA.ppt
 
REST Introduction.ppt
REST Introduction.pptREST Introduction.ppt
REST Introduction.ppt
 
3-SchemaExamples.pdf
3-SchemaExamples.pdf3-SchemaExamples.pdf
3-SchemaExamples.pdf
 
Converting DTDs to XML Schemas.pdf
Converting DTDs to XML Schemas.pdfConverting DTDs to XML Schemas.pdf
Converting DTDs to XML Schemas.pdf
 
XSL- XSLT.pdf
XSL- XSLT.pdfXSL- XSLT.pdf
XSL- XSLT.pdf
 
XSLT.ppt
XSLT.pptXSLT.ppt
XSLT.ppt
 
2-DTD.ppt
2-DTD.ppt2-DTD.ppt
2-DTD.ppt
 

Recently uploaded

IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxvipinkmenon1
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoĂŁo Esperancinha
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
microprocessor 8085 and its interfacing
microprocessor 8085  and its interfacingmicroprocessor 8085  and its interfacing
microprocessor 8085 and its interfacingjaychoudhary37
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2RajaP95
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝soniya singh
 

Recently uploaded (20)

IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptx
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
microprocessor 8085 and its interfacing
microprocessor 8085  and its interfacingmicroprocessor 8085  and its interfacing
microprocessor 8085 and its interfacing
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
 

XML-INTRODUCTION.pdf

  • 1. 7/9/2019 1 XML Extensible Markup Language Prepared By: Dr.Saranya.K.G SGML (Standard Generalized Markup Language) • It is an internationally agreed standard for data representation. • It is an international standard for the definition of device independent, system independent methods of representing texts in electronic form. Prepared By: Dr.Saranya.K.G
  • 2. 7/9/2019 2 Introduction • XML stands for EXtensible Markup Language • XML is a markup language much like HTML. A markup language is used to provide information about a document. • A simplified version of SGML • More flexible and adaptable than HTML • XML was designed to describe data Prepared By: Dr.Saranya.K.G • Tags are added to the document to provide the extra information. • HTML tags tell a browser how to display the document. • XML tags give a reader some idea what some of the data means. • XML tags are not predefined. You must define your own tags • XML uses a Document Type Definition (DTD) or an XML Schema to describe the data Prepared By: Dr.Saranya.K.G
  • 3. 7/9/2019 3 • XML was designed to store and transport data. • XML was designed to be both human- and machine-readable. • XML is often used for distributing data over the Internet. • XML is a W3C Recommendation. • World Wide Web Consortium published the first XML 1.0 standard definition in 1998. Prepared By: Dr.Saranya.K.G <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend! </body> </note> The XML above is quite self-descriptive: • It has sender information. • It has receiver information • It has a heading • It has a message body. But still, the XML above does not DO anything. XML is just information wrapped in tags. Note To: Tove From: Jani Reminder Don't forget me this weekend! Prepared By: Dr.Saranya.K.G
  • 4. 7/9/2019 4 XML Does Not Use Predefined Tags • The XML language has no predefined tags. • 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. • HTML works with predefined tags like <p>, <h1>, <table>, etc. • With XML, the author must define both the tags and the document structure. Prepared By: Dr.Saranya.K.G XML is Extensible • Most XML applications will work as expected even if new data is added (or removed). • Imagine an application designed to display the original version of note.xml (<to> <from> <heading> <body>). • Then imagine a newer version of note.xml with added <date> and <hour> elements, and a removed <heading>. • The way XML is constructed, older version of the application can still work: Prepared By: Dr.Saranya.K.G
  • 5. 7/9/2019 5 <note> <date>2015-09-01</date> <hour>08:30</hour> <to>Tove</to> <from>Jani</from> <body>Don't forget me this weekend!</body> </note> Older Version Note To: Tove From: Jani Reminder Don't forget me this weekend! New Version Note To: Tove From: Jani Date: 2015-09-01 08:30 Don't forget me this weekend! <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend! </body> </note> Prepared By: Dr.Saranya.K.G XML Simplifies Things • It simplifies data sharing • It simplifies data transport • It simplifies platform changes • It simplifies data availability Many computer systems contain data in incompatible formats. Exchanging data between incompatible systems (or upgraded systems) is a time-consuming task for web developers. Large amounts of data must be converted, and incompatible data is often lost. XML stores data in plain text format. This provides a software- and hardware-independent way of storing, transporting, and sharing data. XML also makes it easier to expand or upgrade to new operating systems, new applications, or new browsers, without losing data. With XML, data can be available to all kinds of "reading machines" like people, computers, voice machines, news feeds, etc. Prepared By: Dr.Saranya.K.G
  • 6. 7/9/2019 6 XML is a W3C Recommendation XML Separates Data from Presentation • XML does not carry any information about how to be displayed. • The same XML data can be used in many different presentation scenarios. • Because of this, with XML, there is a full separation between data and presentation. Prepared By: Dr.Saranya.K.G XML is Often a Complement to HTML In many HTML applications, XML is used to store or transport data, while HTML is used to format and display the same data. XML Separates Data from HTML • When displaying data in HTML, you should not have to edit the HTML file when the data changes. • With XML, the data can be stored in separate XML files. • With a few lines of JavaScript code, you can read an XML file and update the data content of any HTML page. Prepared By: Dr.Saranya.K.G
  • 7. 7/9/2019 7 Difference between XML and HTML The main difference between XML and HTML • XML was designed to carry data. (XML is not a replacement for HTML) XML and HTML were designed with different goals: • XML was designed to describe data and to focus on what data is. HTML was designed to display data and to focus on how data looks. • HTML is about displaying information, while XML is about describing information. • XML tags are not predefined like HTML tags are Prepared By: Dr.Saranya.K.G What is XML Used For? • XML documents are used to transfer data from one place to another often over the Internet. • XML subsets are designed for particular applications. • One is RSS (Rich Site Summary or Really Simple Syndication ). It is used to send breaking news bulletins from one web site to another. • A number of fields have their own subsets. These include chemistry, mathematics, and books publishing. • Most of these subsets are registered with the W3Consortium and are available for anyone’s use. Prepared By: Dr.Saranya.K.G
  • 8. 7/9/2019 8 Why Is XML Important? • Plain Text • Easy to edit • Possible to efficiently store large amounts of XML data through an XML front end to a database • Data Identification • Tell you what kind of data you have • Can be used in different ways by different applications Prepared By: Dr.Saranya.K.G Why is XML important? • Linkability -- XLink and XPointer • Simple unidirectional hyperlinks • Two-way links • Multiple-target links • “Expanding” links • Easily Processed • Regular and consistent notation • Hierarchical • Faster to access • Easier to rearrange Prepared By: Dr.Saranya.K.G
  • 9. 7/9/2019 9 Advantages of XML • XML is text (Unicode) based. • Takes up less space. • Can be transmitted efficiently. • One XML document can be displayed differently in different media. • Html, video, CD, DVD, • You only have to change the XML document in order to change all the rest. • XML documents can be modularized. Parts can be reused. Prepared By: Dr.Saranya.K.G XML Specifications •XML 1.0 Defines the syntax of XML •XPointer, XLink Defines a standard way to represent links between resources •XSL Defines the standard style sheet language for XML Prepared By: Dr.Saranya.K.G
  • 10. 7/9/2019 10 XML Tree Structure XML Structure XML documents form a tree structure that starts at "the root" and branches to "the leaves". Prepared By: Dr.Saranya.K.G XML Trees • An XML document has a single root node. • The tree is a general ordered tree. • A parent node may have any number of children. • Child nodes are ordered, and may have siblings. • Preorder traversals are usually used for getting information out of the tree. <root> <child> <subchild>.....</subchild> </child> </root> Prepared By: Dr.Saranya.K.G
  • 11. 7/9/2019 11 <?xml version="1.0" encoding="UTF-8"?> <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> Category Title Author Year Price Cooking Everyday Italian Giada De Laurentiis 2005 30.00 children Harry Potter J K. Rowling 2005 29.99 web Learning XML Erik T. Ray 2003 39.95 Book Store Details: Prepared By: Dr.Saranya.K.G A prolog defines the XML version and the character encoding: <?xml version="1.0" encoding="UTF-8"?> The next line is the root element of the document: <bookstore> The next line starts a <book> element: <book category="cooking"> Prepared By: Dr.Saranya.K.G
  • 12. 7/9/2019 12 The <book> elements have 4 child elements: <title>, <author>, <year>, <price>. <title lang="en">Everyday Italian</title> <author>Giada De Laurentiis</author> <year>2005</year> <price>30.00</price> The next line ends the book element: </book> Prepared By: Dr.Saranya.K.G Expanded Example <?xml version = “1.0” ?> <address> <name> <first> Alice </first> <last> Lee </last> </name> <email> alee@aol.com </email> <phone> 123-45-6789 </phone> <birthday> <year> 1983 </year> <month> 07 </month> <day> 15 </day> </birthday> </address> Prepared By: Dr.Saranya.K.G
  • 13. 7/9/2019 13 XML Files are Trees address name email phone birthday first last year month day Prepared By: Dr.Saranya.K.G XML SYNTAX Prepared By: Dr.Saranya.K.G
  • 14. 7/9/2019 14 XML Syntax Rules The syntax rules of XML are very simple and logical. The rules are easy to learn, and easy to use. 1. XML Documents Must Have a Root Element XML documents must contain one root element that is the parent of all other elements: <root> <child> <subchild>.....</subchild> </child> </root> Prepared By: Dr.Saranya.K.G In this example <note> is the root element: <?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> Example Prepared By: Dr.Saranya.K.G
  • 15. 7/9/2019 15 The XML Prolog The above line is called as the XML prolog <?xml version="1.0" encoding="UTF-8"?> • The XML prolog is optional. If it exists, it must come first in the document. • XML documents can contain international characters, like Norwegian øÌü or French êèÊ. • To avoid errors, you should specify the encoding used, or save your XML files as UTF-8. • UTF-8 is the default character encoding for XML documents. Prepared By: Dr.Saranya.K.G 2. All XML Elements Must Have a Closing Tag <p>This is a paragraph.</p> <br /> The XML prolog does not have a closing tag! This is not an error. The prolog is not a part of the XML document. Prepared By: Dr.Saranya.K.G
  • 16. 7/9/2019 16 3. XML Tags are Case Sensitive • XML tags are case sensitive. The tag <Letter> is different from the tag <letter>. • Opening and closing tags must be written with the same case: <message>This is correct</message> "Opening and closing tags" are often referred to as "Start and end tags". Use whatever you prefer. It is exactly the same thing. Prepared By: Dr.Saranya.K.G 4. XML Elements Must be Properly Nested In HTML, you might see improperly nested elements: <b><i>This text is bold and italic</b></i> In XML, all elements must be properly nested within each other: <b><i>This text is bold and italic</i></b> In the example above, "Properly nested" simply means that since the <i> element is opened inside the <b> element, it must be closed inside the <b> element. Prepared By: Dr.Saranya.K.G
  • 17. 7/9/2019 17 5. XML Attribute Values Must Always be Quoted • XML elements can have attributes in name/value pairs just like in HTML. In XML, the attribute values must always be quoted: <note date="12/11/2007“> <to>Tove</to> <from>Jani</from> </note> Prepared By: Dr.Saranya.K.G 6. Entity References • Some characters have a special meaning in XML. • 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. This will generate an XML error: <message> salary < 1000 </message> To avoid this error, replace the "<" character with an entity reference: Prepared By: Dr.Saranya.K.G
  • 18. 7/9/2019 18 <message> salary &lt; 1000 </message> There are 5 pre-defined entity references in XML: &lt; < less than &gt; > greater than &amp; & ampersand &apos; ' apostrophe &quot; " quotation mark Only < and & are strictly illegal in XML, but it is a good habit to replace > with &gt; as well. Prepared By: Dr.Saranya.K.G 7. Comments in XML The syntax for writing comments in XML is similar to that of HTML: <!-- This is a comment --> Two dashes in the middle of a comment are not allowed: <!-- This is an invalid -- comment --> Prepared By: Dr.Saranya.K.G
  • 19. 7/9/2019 19 8. White-space is Preserved in XML • XML does not truncate multiple white-spaces (HTML truncates multiple white-spaces to one single white-space): XML: Hello Tove HTML: Hello Tove Prepared By: Dr.Saranya.K.G 9. XML Stores New Line as LF • Windows applications store a new line as: carriage return and line feed (CR+LF). • Unix and Mac OSX uses LF. • Old Mac systems uses CR. • XML stores a new line as LF. Prepared By: Dr.Saranya.K.G
  • 20. 7/9/2019 20 XML Syntax (Summary) • XML declaration is the first statement. (Prolog) • All XML elements must have a closing tag • XML tags are case sensitive • All XML elements must be properly nested • All XML documents must have a root tag • Attribute values must always be quoted • With XML, white space is preserved • Comments in XML: <!-- This is a comment --> • Certain characters are reserved for parsing Prepared By: Dr.Saranya.K.G XML Elements Prepared By: Dr.Saranya.K.G
  • 21. 7/9/2019 21 What is an XML Element? • An XML element is everything from (including) the element's start tag to (including) the element's end tag. <price>29.99</price> An element can contain: • text • attributes • other elements • or a mix of the above Prepared By: Dr.Saranya.K.G <bookstore> <book category="children"> <title>Harry Potter</title> <author>J K. Rowling</author> <year>2005</year> <price>29.99</price> </book> <book category="web"> <title>Learning XML</title> <author>Erik T. Ray</author> <year>2003</year> <price>39.95</price> </book> </bookstore> Prepared By: Dr.Saranya.K.G
  • 22. 7/9/2019 22 In the example above: <title>, <author>, <year>, and <price> have text content because they contain text (like 29.99). <bookstore> and <book> have element contents, because they contain elements. <book> has an attribute (category="children"). Prepared By: Dr.Saranya.K.G Empty XML Elements • An element with no content is said to be empty. • In XML, you can indicate an empty element like this: <element></element> You can also use a so called self-closing tag: <element /> Empty elements can have attributes. Prepared By: Dr.Saranya.K.G
  • 23. 7/9/2019 23 XML Naming Rules XML elements must follow these naming rules: • Element names are case-sensitive • Element names must start with a letter or underscore • Element names cannot start with the letters xml (or XML, or Xml, etc) • Element names can contain letters, digits, hyphens, underscores, and periods • Element names cannot contain spaces • Any name can be used, no words are reserved (except xml). Prepared By: Dr.Saranya.K.G Best Naming Practices • Create descriptive names, like this: <person>, <firstname>, <lastname>. • Create short and simple names, like this: <book_title> not like this: <the_title_of_the_book>. • Avoid "-". If you name something "first-name", some software may think you want to subtract "name" from "first". • Avoid ".". If you name something "first.name", some software may think that "name" is a property of the object "first". • Avoid ":". Colons are reserved for namespaces (more later). • Non-English letters like Êòå are perfectly legal in XML, but watch out for problems if your software doesn't support them. Prepared By: Dr.Saranya.K.G
  • 24. 7/9/2019 24 Naming Styles Style Example Description Lower case <firstname> All letters lower case Upper case <FIRSTNAME> All letters upper case Underscore <first_name> Underscore separates words Pascal case <FirstName> Uppercase first letter in each word Camel case <firstName> Uppercase first letter in each word except the first • If you choose a naming style, it is good to be consistent! • XML documents often have a corresponding database. A common practice is to use the naming rules of the database for the XML elements. • Camel case is a common naming rule in JavaScripts. Prepared By: Dr.Saranya.K.G XML Elements are Extensible • XML elements can be extended to carry more information. Look at the following XML example: <note> <to>Tove</to> <from>Jani</from> <body>Don't forget me this weekend!</body> </note> Prepared By: Dr.Saranya.K.G
  • 25. 7/9/2019 25 Let's imagine that we created an application that extracted the <to>, <from>, and <body> elements from the XML document to produce this output: MESSAGE To: Tove From: Jani Don't forget me this weekend! Imagine that the author of the XML document added some extra information to it <note> <date>2008-01-10</date> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note> Prepared By: Dr.Saranya.K.G • Should the application break or crash? • No. The application should still be able to find the <to>, <from>, and <body> elements in the XML document and produce the same output. • This is one of the beauties of XML. It can be extended without breaking applications. Prepared By: Dr.Saranya.K.G
  • 26. 7/9/2019 26 XML Attributes • Attributes are designed to contain data related to a specific element. • XML attributes are used to describe XML elements or to provide additional information about elements. • Attributes provide additional information that is not part of the data. Ex: <Book no=“99-2456” media=“CD”></Book> Prepared By: Dr.Saranya.K.G XML Attributes Must be Quoted • Attribute values must always be quoted. Either single or double quotes can be used. • For a person's gender, the <person> element can be written like this: <person gender="female"> or like this: <person gender='female'> Prepared By: Dr.Saranya.K.G
  • 27. 7/9/2019 27 If the attribute value itself contains double quotes you can use single quotes, like in this example: <gangster name='George "Shotgun" Ziegler'> or you can use character entities: <gangster name="George &quot;Shotgun&quot; Ziegler"> Prepared By: Dr.Saranya.K.G XML Elements vs. Attributes <person gender="female"> <firstname>Anna</firstname> <lastname>Smith</lastname> </person> <person> <gender>female</gender> <firstname>Anna</firstname> <lastname>Smith</lastname> </person> • In the first example gender is an attribute. In the last, gender is an element. Both examples provide the same information. • There are no rules about when to use attributes or when to use elements in XML. Prepared By: Dr.Saranya.K.G
  • 28. 7/9/2019 28 Consider the following three XML documents contain exactly the same information: A date attribute is used in the first example: <note date="2008-01-10"> <to>Tove</to> <from>Jani</from> </note> A <date> element is used in the second example: <note> <date>2008-01-10</date> <to>Tove</to> <from>Jani</from> </note> An expanded <date> element is used in the third example: <note> <date> <year>2008</year> <month>01</month> <day>10</day> </date> <to>Tove</to> <from>Jani</from> </note> Prepared By: Dr.Saranya.K.G Avoid XML Attributes? Some things to consider when using attributes are: • attributes cannot contain multiple values (elements can) • attributes cannot contain tree structures (elements can) • attributes are not easily expandable (for future changes) Don't end up like this: <note day="10" month="01" year="2008" to="Tove" from="Jani" heading="Reminder" body="Don't forget me this weekend!"> </note> Prepared By: Dr.Saranya.K.G
  • 29. 7/9/2019 29 XML Attributes for Metadata • Sometimes ID references are assigned to elements. These IDs can be used to identify XML elements in much the same way as the id attribute in HTML. This example demonstrates this: <messages> <note id="501"> <to>Tove</to> <from>Jani</from> Prepared By: Dr.Saranya.K.G <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note> <note id="502"> <to>Jani</to> <from>Tove</from> <heading>Re: Reminder</heading> <body>I will not</body> </note> </messages> The id attributes above are for identifying the different notes. It is not a part of the note itself. Metadata (data about data) should be stored as attributes, and the data itself should be stored as elements. Prepared By: Dr.Saranya.K.G
  • 30. 7/9/2019 30 XML Specifications • XML 1.0 Defines the syntax of XML • XPointer, XLink Defines a standard way to represent links between resources • XSL Defines the standard stylesheet language for XML Prepared By: Dr.Saranya.K.G XML Validation There are two types of XML documents • "Well Formed" XML document --correct XML syntax • "Valid" XML document • “well formed” • Conforms to the rules of a DTD (Document Type Definition) • XML DTD • defines the legal building blocks of an XML document • Can be inline in XML or as an external reference • XML Schema • an XML based alternative to DTD, more powerful • Support namespace and data types Prepared By: Dr.Saranya.K.G
  • 31. 7/9/2019 31 Displaying XML • XML documents do not carry information about how to display the data • We can add display information to XML with • CSS (Cascading Style Sheets) • XSL (eXtensible Stylesheet Language) --- preferred Prepared By: Dr.Saranya.K.G XML support in IE 5.0+ Internet Explorer 5.0 has the following XML support: • Viewing of XML documents • Full support for W3C DTD standards • Binding XML data to HTML elements • Transforming and displaying XML with XSL • Displaying XML with CSS • Access to the XML DOM (Document Object Model) *Netscape 6.0 also have full XML support Prepared By: Dr.Saranya.K.G
  • 32. 7/9/2019 32 XML features • XML uses the concept of document type and hence a DTD (Document Type Definition) to describe data • XML with DTD is self descriptive • XML separates data from display formats • XML can be used as a format to exchange data Prepared By: Dr.Saranya.K.G XML Syntax consists of • XML Declaration • XML Elements • XML Attributes • The first line of an XML document should always consist of an XML declaration defining the version of XML Prepared By: Dr.Saranya.K.G
  • 33. 7/9/2019 33 General Structure <root> <child> <subchild>…….</subchild> </child> </root> Prepared By: Dr.Saranya.K.G Main Components of an XML Document • Elements: <hello> • Attributes: <item id=“33905”> • Entities: &lt; (<) • Advanced Components • CData Sections • Processing Instructions Prepared By: Dr.Saranya.K.G
  • 34. 7/9/2019 34 XML strengths • Its ability to describe data • Its ability to structure data • Separate display from structure • Supported by industry • Availability of tools Prepared By: Dr.Saranya.K.G XML applications • B2B • EDI • Journal publishing • Database development Prepared By: Dr.Saranya.K.G
  • 35. 7/9/2019 35 An example of XML <?xml version="1.0" encoding="ISO-8859-1"?> <note> <to>XXX</to> <from>YYY</from> <heading>XML</heading> <body> Extensible Markup Language </body> </note> Prepared By: Dr.Saranya.K.G Contents of the ProductList.xml Document Prepared By: Dr.Saranya.K.G
  • 36. 7/9/2019 36 • The first line represents the XML document declaration and it is mandatory. • Every XML has a root element. In our example, the second line is the root element - <ProductList> • The root element can contain child elements. In our example, Product is the child element of ProductList • Each element can contain sub-elements. • <P_CODE>,<P_PRICE> are sub-elements. Prepared By: Dr.Saranya.K.G Example <?xml version="1.0" encoding= "ISO-8859-1" ?> <book> <title> XML </title> <chapter> introduction to xml <para>Markup languages</para> <para>Features of XML</para> </chapter> <chapter>XML syntax <para>Elements must be enclosed in tags</para> <para>Elements must be properly nested</para> </chapter> </book> Prepared By: Dr.Saranya.K.G
  • 37. 7/9/2019 37 XML Architecture Prepared By: Dr.Saranya.K.G How do you get the data? XML data Parser Information structure (tree+links) Documents, stylesheets, and other data can all be expressed in XML. DOM Interface Any application can plug in via an API called “Document Object Model” DTD/Schema This model can work locally or over a network. Parsing, tree-building, and access can shift between client/server Prepared By: Dr.Saranya.K.G
  • 38. 7/9/2019 38 XML Parser • All modern browsers have a built-in XML parser. • An XML parser converts an XML document into an XML DOM object - which can then be manipulated with a JavaScript. XML DOM • A DOM (Document Object Model) defines a standard way for accessing and manipulating XML documents. Prepared By: Dr.Saranya.K.G XML Namespaces • XML Namespaces provide a method to avoid element name conflicts. • This XML carries HTML table information: <table> <tr> <td>Apples</td> <td>Bananas</td> </tr> </table> Prepared By: Dr.Saranya.K.G
  • 39. 7/9/2019 39 • This XML carries information about a table (a piece of furniture): <table> <name>African Coffee Table</name> <width>80</width> <length>120</length> </table> • If these XML fragments were added together, there would be a name conflict. • Both contain a <table>element, but the elements have different content and meaning. • An XML parser will not know how to handle these differences. Prepared By: Dr.Saranya.K.G Solving the Name Conflict Using a Prefix • Name conflicts in XML can easily be avoided using a name prefix. • This XML carries information about an HTML table, and a piece of furniture: <h:table> <h:tr> <h:td>Apples</h:td> <h:td>Bananas</h:td> </h:tr> </h:table> <f:table> <f:name>African Coffee Table</f:name> <f:width>80</f:width> <f:length>120</f:length> </f:table> Prepared By: Dr.Saranya.K.G
  • 40. 7/9/2019 40 • In the example above, there will be no conflict because the two <table> elements have different names. Prepared By: Dr.Saranya.K.G XML Namespaces - The xmlns Attribute • When using prefixes in XML, a so-called namespace for the prefix must be defined. • The namespace is defined by the xmlns attribute in the start tag of an element. • The namespace declaration has the following syntax. xmlns:prefix="URI". Prepared By: Dr.Saranya.K.G
  • 41. 7/9/2019 41 <root> <h:table xmlns:h="http://www.w3.org/TR/html4/"> <h:tr> <h:td>Apples</h:td> <h:td>Bananas</h:td> </h:tr> </h:table> <f:table xmlns:f="http://www.w3schools.com/furniture"> <f:name>African Coffee Table</f:name> <f:width>80</f:width> <f:length>120</f:length> </f:table> </root> XML Namespaces - The xmlns Attribute Prepared By: Dr.Saranya.K.G • In the example above, the xmlns attribute in the <table> tag give the h: and f: prefixes a qualified namespace. • When a namespace is defined for an element, all child elements with the same prefix are associated with the same namespace. • Namespaces can be declared in the elements where they are used or in the XML root element: Prepared By: Dr.Saranya.K.G
  • 42. 7/9/2019 42 URI • Uniform Resource Identifier (URI) • A Uniform Resource Identifier (URI) is a string of characters which identifies an Internet Resource. • The most common URI is the Uniform Resource Locator (URL) which identifies an Internet domain address. Another, not so common type of URI is the Universal Resource Name (URN). Prepared By: Dr.Saranya.K.G PCDATA - Parsed Character Data • XML parsers normally parse all the text in an XML document. • When an XML element is parsed, the text between the XML tags is also parsed: <message>This text is also parsed</message> Prepared By: Dr.Saranya.K.G
  • 43. 7/9/2019 43 <name><first>Bill</first><last>Gates</last></name> The parser does this because XML elements can contain other elements, as in this example, where the <name> element contains two other elements (first and last): and the parser will break it up into sub-elements like this: <name> <first>Bill</first> <last>Gates</last> </name Parsed Character Data (PCDATA) is a term used about text data that will be parsed by the XML parser. Prepared By: Dr.Saranya.K.G CDATA - (Unparsed) Character Data • The term CDATA is used about text data that should not be parsed by the XML parser. • Characters like "<" and "&" are illegal in XML elements. • "<" will generate an error because the parser interprets it as the start of a new element. • "&" will generate an error because the parser interprets it as the start of an character entity. • Some text, like JavaScript code, contains a lot of "<" or "&" characters. To avoid errors script code can be defined as CDATA. Prepared By: Dr.Saranya.K.G
  • 44. 7/9/2019 44 • Everything inside a CDATA section is ignored by the parser. • A CDATA section starts with "<![CDATA[" and ends with "]]>": <script> <![CDATA[ function matchwo(a,b) { if (a < b && a < 0) then { return 1; } else { return 0; } } ]]> </script> In this example, everything inside the CDATA section is ignored by the parser Prepared By: Dr.Saranya.K.G Conclusion • XML is a self-descriptive language • XML is a powerful language to describe structure data for web application • XML is currently applied in many fields • Many vendors already supports or will support XML • XML Documents can be validated through the use of DTD and XSD documents • XML impacts B2B data exchanges, legacy system integration, web page development, database system integration. Prepared By: Dr.Saranya.K.G