XML_PPT
XML_PPT
1
XML
What is XML ?
•“XML is a text that follows certain rules.” those are
very similar with html but having some
enhancement.
• It is a defector language which is used to exchange
the data over internet.
•The purpose of xml is X-extensible: (means it
is extended to meet the various requirements).
•Markup Language( used to identify the structure of
the documents and add meaning to different part of the
documents. )
2
XML
Limitation of HTML
• HTML does not provide arbitrary structure.
• It does not check the syntax.
• Unable to sort the data.
• No capability for advanced formatting.
•Having little ability to specify the meaning of
the information
• It is not readable.
• It does not support object oriented language
3
XML
Benefits of XML
• XML is used in Internet.
• It support a variety of applications.
• It prepares the document quickly and clearly.
• It minimizes the complexness of the document.
• It is designed to store, carry and exchange data over internet
but not to display data.
• It provide structured and Integrated data.
• It sort information easily and reuse the information.
• It provides self-description to data.
• It is Hierarchical
– Faster to access
– Easier to rearrange
4
XML
Need of XML
•XML is created to use user defined
structural document over the web
• It’s mainly used
To exchange the data
To share data
To store data
Separate data
Create new language
• It’s bridging the gap between SGML and
HTML
5•
It provides the structure and implementation.
XML
7
XML
XML Building blocks
• Element
Delimited by angle brackets
Identify the nature of the content they
surround General format: <element> …
</element> Empty element: <empty-
Element/>
• Attribute
Name-value pairs that occur inside start-tags after
element name, like: <element attribute=“value”>
8
XML
XML Tree
• XML documents form a tree structure that starts at "the root" and branches to
"the leaves".
9
XML
Example
<?xml version="1.0" encoding="UTF-8"?>
<bookstore>
<book category="social“ >
<title lang="en“ >Everyday
Italian</title>
<author >Giada De laury</author>
<year >2005</year>
<price >30</price>
</book>
</bookstore>
10
XML
XML
Syntax
•XML tags are case sensitive but the texts are
case insensitive.
• XML must have ending tags and every XML
document contain a root element.
• Elements are user defined in any XML document.
• One child element may have another child element.
<person><name>
<fname>xyz/Xyz</fname>
</name> </person>
• XML Elements Must be Properly Nested like
<b><i>Test Text</i></b>
11
XML
Rules for Element naming
• XML elements are naming by character.
• The tag declaration is as
<?xml Version=“1.0”?>(not part of doc)
• In place of attributes we can create child elements.
• Document must be validated and welformed
• XML elements must not have Blank space.
• <Date Of Birth>should be <Date-Of-Birth>
• Attribute value must be placed within double quotes
• <title lang=“en”>
12
XML
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.
<message>if salary < 1000 then</message>
• To avoid this error, replace the "<" character
with an entity reference:
• <message>if salary < 1000
then</message>
13
XML
Entity References
• There are 5 predefined entity references in XML:
Entity References Character
< <
> >
& &
" “
' ‘
14
XML
Displaying XML
15
XML
XML Components
XML main component is DTD and Document,
The other components are elements and Attributes
16
XML
Welformed documents
• An XML document with correct syntax is
called "Well Formed".
• It should be well organized and accurate.
• XML doc must contains at least one element
called root elements
• The root element must be unique and it
contains other child elements.
• Each start tag must have corresponding end tag
17
XML
Valid documents
• An XML document validated against a DTD.
• It requires a document type (!DOCTYPE)
• XML document refers to all rules declared in
a DTD
18
XML
DTD (Document Type Definition)
• The purpose of a DTD is to define the structure of an
XML document.
• A DTD describes the components and the guidelines
any xml vocabulary and its elements.
• It defines the various possible relationships between
these elements and how they can be nested.
• DTD are of two types :
– External DTD
– Internal DTD
19
XML
Internal DTD
• Documents are designed inside the same file
Example: “Address.xml”
<?xml version="1.0"?>
<!DOCTYPE address
[<!ELEMENT address (building,street,city)>
<!ELEMENT building (#PCDATA)>
<!ELEMENT street (#PCDATA)>
<!ELEMENT city (#PCDATA)> ]>
<Address>
<building>Sweet plaza, 29 </building>
<street> Big bazar </street>
<city> Brahmapur </city>
</Address>
20
XML
External DTD
• External DTD is used highly than internal DTD
• As it uses multiple documents which are created using
the same class
• In this case a separate file is created that defines the
elements.
2`1
XML
External DTD
Example: “Addressdoc.dtd”
<!ELEMENT address (building,street,city)>
<!ELEMENT building (#PCDATA)>
<!ELEMENT street (#PCDATA)>
<!ELEMENT city (#PCDATA)>
“Address.xml”
<?xml version="1.0"?>
<!DOCTYPE Address SYSTEM "Addressdoc.dtd">
<Address> :
<building> Sweet plaza, 29 </building>
<street> Big bazar </street>
<city> Brahmapur </city>
</Address>
22
XML
External DTD using css
“style.xml”
<?xml version="1.0"?>
<!DOCTYPE cdlib SYSTEM "cdlib.dtd">
<?xml-stylesheet href="cdlib.css"
type="text/css"?>
<cdlib> <cd>
<title>Mera Bharat</title>
<type>Mahan</type>
</cd>
</cdlib>
23
XML
External DTD
“cdlib.dtd”
24
XML
cdlib.css
“cdlib.css”
title{display : black;
color : green;
font-size : 48;
background-
color : red;
}
type { display : table;
color : red;
font-size : 44
}
25
XML
Uses of symbols in XML
( , ) : It separate the items
(|) : It indicates the occurrence of either left or right
operands or both
( ? ) : It indicates that operands may appears once or not at all
( * ) : It indicates zero or more occurrence for an element
( + ) : It indicates one or more occurrence for an element
( ) : It is used to combine the elements in mathematical way
Example:
• Separators
, both, in order foreword?, chapter+
| or section|chapter
• Grouping
() grouping (section|chapter)+
27
XML
Component of DTD
• PCDATA :-
– It parse the content of the element into character
data.
– It represent the text that found in between the begin
and end tag. It also expands the entities.
• CDATA or DOCTYPE :-
– It extracts the value of the particular text
from the respective XML tag.
– It does not parse by XML parser and does not
expand the XML entity.
28
XML
PCDATA
• PCDATA means parsed character data
• An XML parser is an API that reads the content of an
XML document
– Currently popular APIs are DOM (Document
Object Model) and SAX (Simple API for XML)
• Text found between the start tag and the end tag of an
XML element
• Text that will be parsed
• Tags inside the text will be treated as markup and
entities will be expanded
29
XML
CDATA
30
XML
Declaring DTD elements
• Root elements are declared by !ELEMENT declaration tag
Syntax: <!ELEMENT elem-name (element-
contents)>
Ex: <!ELEMENT rootelem (child1,child2,...)>
• Child elements are also created in the above method
Syntax: <!ELEMENT elem-name (#PCDATA)>
Ex: <!ELEMENT childelem (#PCDATA)>
• Creating empty elements by using the EMPTY key-word
(element with no content)
Syntax: <!ELEMENT elem-name EMPTY>
31
XML
Declaring DTD elements cont..
• Declaring only one occurrence of the same element
Syntax:
<!ELEMENT rootelem (child-name)>
• Declaring one or more occurance of the same element
Syntax:
<!ELEMENT childelem (child-name)+>
• Declaring zero or more occurrence of the same element
Syntax:
<!ELEMENT childelem (child-name)*>
32
XML
Declaring DTD elements cont..
• Entities
These are the variables use to define the short-cut for
some common text.
It is declared using ENTITY declaration tag
Syntax:
<!ELEMENT entity-name "entity-value">
Ex:
<!ELEMENT price (#PCDATA)>
<!ENTITY cost "500">
<price> $cost </price>
33
XML
A DTD Example
<!DOCTYPE novel [
<!ELEMENT novel (foreword, chapter+)>
<!ELEMENT foreword (paragraph+)>
<!ELEMENT chapter (paragraph+)>
<!ELEMENT paragraph (#PCDATA)>
<!ATTRIBUTE chapter number CDATA #REQUIRED>
]>
34
XML
Conclusion
• XML is a self-descriptive language
35
XML
Thank
You…
36