+ All Categories

XML-ppt

Date post: 07-Apr-2015
Category:
Upload: aryaaccent
View: 110 times
Download: 0 times
Share this document with a friend
33
e X Xtensible M Markup L Language (XML) By: Anupam Kumar
Transcript
Page 1: XML-ppt

eXXtensible MMarkup LLanguage (XML)

By:

Anupam Kumar

Page 2: XML-ppt

Outline of Presentation Introduction Comparison between XML and HTML Building Blocks of XML. XML Elements XML Tree XML Data Island DTD Summary.

Page 3: XML-ppt

What is XML?

XML stands for eXtensible Markup Language 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.

Page 4: XML-ppt

XML…. 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

Page 5: XML-ppt

Comparisons

Extensible set of tags XML was designed to

transport and store data, with focus on what data is.

Standard Data infrastructure

Allows multiple output forms

White-space is Preserved in XML.

Fixed set of tags HTML was designed

to display data, with focus on how data looks

No data validation capabilities

Single presentation Not in HTML.

XML HTML

Page 6: XML-ppt

Building blocks for XMLElements : are the main building blocks

of both XML and HTML documents .Attributes : provide extra information

about elements .PCDATA : Parsed character data, will be

examined by parser for entities & markup.CDATA : Character data is used about

text data that should not be parsed by the XML parser.

Page 7: XML-ppt

XML Elements 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: <CITY> <City> <city> XML can abbreviate empty elements, for example: <married> </married> can be abbreviated to <married/>

Page 8: XML-ppt

XML Elements(Cont’d)Entity References

There are 5 predefined entity references in XML:

Page 9: XML-ppt

XML Elements (cont’d)

All elements must have an end tag. All elements must be cleanly nested

(overlapping elements are not allowed).

Page 10: XML-ppt

XML AttributesAn attribute is a name-value pair

separated by an equal sign (=) and attribute value must be in “ ”.

Example:

<City ZIP=“94608”> Hyderabad </City>Attributes are used to attach additional,

secondary information to an element.

Page 11: XML-ppt

Use of Elements vs. Attributes

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

Page 12: XML-ppt

Use of Elements vs. Attributes(Cont’d)

<person>  <sex>female</sex>  <firstname>Anna</firstname>  <lastname>Smith</lastname></person>

Page 13: XML-ppt

Avoid 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.

Page 14: XML-ppt

XML Tree

Page 15: XML-ppt

XML Tree(Cont’d)

<bookstore>  <book category=“programming">    <title lang ="en">Complete Reference

To Java</title>    <author> Balagurswamy</author>    <year>2005</year>    <price>250.00</price>  </book>

Page 16: XML-ppt

XML Tree(Cont’d)

<book category="CHILDREN">    <title lang="en">Harry Potter</title>    <author>J K. Rowling</author>    <year>2005</year>    <price>600.00</price>  </book>

Page 17: XML-ppt

XML Tree(Cont’d)

<book category="WEB">    <title lang ="en">Learning XML</title>    <author>Erik T. Ray</author>    <year>2003</year>    <price>500.00</price>  </book></bookstore>

Page 18: XML-ppt

XML Data 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 ID attribute provides a name that you can use to reference the data island.

Page 19: XML-ppt

XML Data Islands (Cont’d) Example:

<XML ID=“XMLID”>

<customer>

<name> Anupam Kumar</name>

<custID> 1500712</custID>

</customer>

</XML>

Page 20: XML-ppt

XML 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)

Page 21: XML-ppt

Document Type Definitions (DTD)

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]>

Page 22: XML-ppt

DTD (cont’d)

Consider an XML document:

<db>

<person gender =“male”>

<name>Anupam</name>

<age>24</age>

<email>[email protected]</email>

</person>

<person>………</person>

</db>

Page 23: XML-ppt

DTD (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)><!ATTLIST person gender CDATA

#REQUIRED> ]>

Page 24: XML-ppt

DTD(Cont’d)

A DTD can be declared inline inside an XML document, or as an external reference. Internal DTD Declaration

External DTD Declaration

Page 25: XML-ppt

DTD(Cont’d) Internal DTD Declaration

If 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]>

Example:-

Page 26: XML-ppt

DTD(Cont’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>

Page 27: XML-ppt

DTD(Cont’d)External DTD Declaration

If 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">

Example:-

Page 28: XML-ppt

DTD(Cont’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)>

Page 29: XML-ppt

DTD (cont’d)Occurrence Indicator:Indicator Occurrence

(no indicator) Required One and only one

? Optional None or one

* Optional, repeatable

None, one, or more

+ Required, repeatable

One or more

Page 30: XML-ppt

DTD Declaring contentDeclaring either/or Content

<!ELEMENT note (to,from,header,(message|body))>

i.e. either message or bodyDeclaring Mixed Content

<!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

Page 31: XML-ppt

DTD Attributes<!ATTLIST element-name attribute-name

attribute-type default-value> In a DTD, attributes are declared with an

ATTLIST declaration.Example:

<!ATTLIST payment type CDATA "check">

Then the XML example can be as follows: <payment type="check" />

Page 32: XML-ppt

DTD Attributes cont..

Page 33: XML-ppt

XML 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.


Recommended