You are on page 1of 33

m6 mm 

  m (XML)

By:
Anupam Kumar
Outline of Presentation
 6ntroduction
 Comparison between XML and HTML
 Building Blocks of XML.
 XML Elements
 XML Tree
 XML Data 6sland
 DTD
 Summary.
„ at is 6 
 6  stands for m6 mm 
  m
 Markup language for documents containing
structured information
 XML is a markup language much like HTML
 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.
6 
 Based on Standard Generalized Markup
Language (SGML)
 Version 1.0 introduced by World Wide Web
Consortium (W3C) in 1998
 Bridge for data exchange on
the Web
{omparisons
6   
 Extensible set of tags  Fixed set of tags
 XML was designed to  HTML was designed
transport and store
data, with focus on to display data, with
what data is. focus on how data
 Standard Data looks
infrastructure  No data validation
 Allows multiple output capabilities
forms
 Single presentation
 White-space is
Preserved in XML.  Not in HTML.
9uilding blocks for 6 
 lements : are the main building blocks of
both XML and HTML documents .
 ~ttributes : provide extra information
about elements .
 P{ ~~ : Parsed character data, will be
examined by parser for entities & markup.
 { ~~ : Character data is used about
text data that should not be parsed by the
6  parser.
6  lements
 XML document must contain a root element. This
element is parent of all other elements.
 An XML element is made up of a start tag, an end tag,
and data in between.
 Example:
<director> Matthew Dunn </director>
 Children on the same level are called siblings (brothers
or sisters).
 XML tags are case-sensitive:
<C6TY> <City> <city>
 XML can abbreviate empty elements, for example:
<married> </married> can be abbreviated to
<married/>
6  lements({ont¶d)
 ntity References
There are 5 predefined entity references in
XML:
6  lements
(cont¶d)
 All elements must have an end tag.
 All elements must be cleanly nested
(overlapping elements are not allowed).
6  ~ttributes
 An attribute is a name-value pair
separated by an equal sign (=) and
attribute value must be in ³ ´.
 Example:
<City Z6P=³94608´> Hyderabad </City>
 Attributes are used to attach additional,
secondary information to an element.
ase of lements vs
~ttributes

 Data can be stored in child elements or in


attributes.
Example:-
<person sex="male">
<firstname>Anupam</firstname>
<lastname>Kumar</lastname>
</person>
This is same as
ase of lements vs
~ttributes({ont¶d)
<person>
<sex>female</sex>
<firstname>Anna</firstname>
<lastname>Smith</lastname>
</person>
~void using attributes
 Some of the problems with attributes are:
 attributes cannot contain multiple values
(child elements can).
 attributes are not easily expandable (for
future changes).
 attributes cannot describe structures (child
elements can).
 attributes are more difficult to manipulate by
program code.
 attribute values are not easy to test against
a DTD.
6  ree
6  ree({ont¶d)
<bookstore>
<book category=³programming">
<title lang ="en">Complete Reference
To Java</title>
<author> Balagurswamy</author>
<year>2005</year>
<price>250.00</price>
</book>
6  ree({ont¶d)
<book category="CH6LDREN">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>600.00</price>
</book>
6  ree({ont¶d)
<book category="WEB">
<title lang ="en">Learning
XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>500.00</price>
</book>
</bookstore>
6  ata Islands
 A data island is an XML document that exists
within an HTML page.

 The <XML> element marks the beginning of


the data island, and its 6D attribute provides a
name that you can use to reference the data
island.
6  ata Islands
({ont¶d)
 Example:
<XML 6D=³XML6D´>
<customer>
<name> Anupam Kumar</name>
<cust6D> 1500712</cust6D>
</customer>
</XML>
6  Validation

 XML with correct syntax is "Well Formed"


XML.
 XML validated against a DTD is "Valid"
XML.
 A "Valid" XML document is a "Well
Formed" XML document, which also
conforms to the rules of a Document
Type Definition (DTD)
ocument ype
efinitions (  )
 An XML document may have an optional
DTD.
 DTD serves as grammar for the underlying
XML document, and it is part of XML
language.
 DTD has the form:
<!DOCTYPE name [mark up declaration]>
 (cont¶d)
Consider an XML document:
<db>
<person gender =³male´>
<name>Anupam</name>
<age>24</age>
<email>aryaaccent@gmail.com</email>
</person>
<person>«««</person>
</db>
 (cont¶d)
DTD for it might be:
<!DOCTYPE db [
<!ELEMENT db (person*)>
<!ELEMENT person (name, age, email)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT age (#PCDATA)>
<!ELEMENT email (#PCDATA)>
<!ATTL6ST person gender CDATA
#REQU6RED>
]>
 ({ont¶d)

 A DTD can be declared inline inside an


XML document, or as an external
reference.
 Internal  eclaration

 ternal  eclaration
 ({ont¶d)
 Internal  eclaration
6f the DTD is declared inside the XML file,
it should be wrapped in a DOCTYPE
definition with the following syntax:
<!DOCTYPE root-element [element-
declarations]>

ample:-
 ({ont¶d)
 <?xml version="1.0"?>
<!DOCTYPE note [
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
]>
<note>
<to>Hari</to>
<from>Anupam</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend</body>
</note>
 ({ont¶d)
 ternal  eclaration
6f the DTD is declared in an external file, it
should be wrapped in a DOCTYPE
definition with the following syntax:
<!DOCTYPE root-element SYSTEM
"filename">

ample:-
 ({ont¶d)
<?xml version="1.0"?>
<!DOCTYPE note SYSTEM "note.dtd">
<note>
<to>Hari</to>
<from>Anupam</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
And this is the file "note.dtd" which contains the DTD:
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
 (cont¶d)
Occurrence 6ndicator:
Indicator Occurrence

(no indicator) Required One and only


one
? Optional None or one

* Optional, None, one, or


repeatable more
+ Required, One or more
repeatable
 eclaring content
 eclaring eit er/or {ontent
 <!ELEMENT note
(to,from,header,(message|body))>
 i.e. either message or body
 eclaring ied {ontent
 <!ELEMENT note
(#PCDATA|to|from|header|message)*>
 note element can contain zero or more
occurrences of parsed character data, "to",
"from", "header", or "message" elements
 ~ttributes
 <!ATTL6ST element-name attribute-name
attribute-type default-value>
 6n a DTD, attributes are declared with an
ATTL6ST declaration.
 Example:
<!ATTL6ST payment type CDATA "check">
Then the XML example can be as follows:
<payment type="check" />
 ~ttributes cont
6  Summary
 XML can be used to exchange, share, and store
data.
 XML documents form a tree structure that starts at
"the root" and branches to "the leaves".
 XML has very simple syntax rules. XML with
correct syntax is "Well Formed". Valid XML also
validates against a DTD.
 All modern browsers have a built-in XML parser
that can read and manipulate XML.
 Text inside a #PCDATA section is parsed by the
parser.
 Text inside a CDATA section is ignored by the
parser.

You might also like