0% found this document useful (0 votes)
10 views

XML Intro

Uploaded by

Mudit Rajput
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

XML Intro

Uploaded by

Mudit Rajput
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 37

XML

Extensible Markup Langauge


XML - Introduction 1
XML stands for Extensible Markup Language.

XML is not used to display the Data.

XML tags are not predefined. You have to define your


own tag.

XML was designed to transport and store data.

XML is designed to be self descriptive.

XML is a w3c recommendation.


XML - Facts 2
XML is not the replacement of HTML.

HTML was designed to display the data, focus is


on how the data looks?

XML was designed to carry and store the data


with focus on what the data is?

XML does not do Anything.

It is self descriptive and structured document.


XML - Facts 3
XML is Not a Replacement for HTML

XML is a complement to HTML.

Best way to describe XML is :

XML is a software- and hardware-independent tool for


carrying information.

XML is most common tool for data transmission


between all sort of application.
XML - Fact 4
XML Separates Data from HTML.

XML simplify Data Sharing.

XML simplifies Data transport.

XML simplifies platform changes.

XML makes your data more available.

XML is used to create new Internet Languages.


e.g. WML , XHTML , RSS , RDF , OWL ,SMIL
XML - Tree 5
XML Documents Form a Tree Structure

XML documents must contain a root element. This element


"the parent" of all other elements.

The elements in an XML document form a document tree.

The tree starts at the root and branches to the lowest level
of the tree.

All elements can have sub elements (child elements).


XML - Tree
6
<root> <?xml version="1.0"
encoding="ISO-8859-1"?>
<child>
<note> // Root
<subchild>...</subchild>
<to>Tove</to> // child 1
<from>Jani</from> // child2
</child> <heading>Reminder</heading>//child3
<body>Don't forget me!</body>//child4

</root> </note>
XML – Syntax Rule 7
All XML Elements Must Have a Closing Tag.

HTML syntax:

<p>This is a paragraph
<p>This is another paragraph

In XML syntax :

<p>This is a paragraph</p>
<p>This is another paragraph</p>
XML – Syntax Rule 8
XML Tags are Case Sensitive.

XML tags are case sensitive. The tag <Letter> is


different from the tag <letter>.

<Message>This is incorrect</message>

<message>This is correct</message>
XML – Syntax Rule 9
XML Elements Must be Properly Nested.

In HTML

<b><i>This text is bold and italic</b></i>

In XML

<b><i>This text is bold and italic</i></b>


XML – Syntax Rule 10
XML Documents Must Have a Root Element

XML documents must contain one element that is the parent


of all other elements. This element is called the root element.

<root>
<child>
<subchild>.....</subchild>
</child>
</root>
XML – Syntax Rule 11
XML Attribute Values Must be Quoted.

XML elements can have attributes in name/value pairs


just like in HTML.

In XML, the attribute values must always be quoted.


Study the two XML documents below. The first one is
incorrect, the second is correct:
<note date=12/11/2007> <note date="12/11/2007">
<to>Tove</to> <to>Tove</to>
<from>Jani</from> <from>Jani</from>
</note> </note>
XML – Syntax Rule 12
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.
&lt; < less than
&gt; > greater than
&amp; & ampersand
&apos; ' apostrophe
&quot; " quotation mark
XML – Syntax Rule 13
Entity References

This is incorrect one.

<message>if salary < 1000 then</message>

Correct One :

<message>if salary &lt; 1000 then</message>


14
There are 5 predefined entity references in XML:

XML – Syntax Rule


Comments in XML.

The syntax for writing comments in XML is


similar to that of HTML.

<!-- This is a comment -->


15
There are 5 predefined entity references in XML:

XML – Elements
XML Elements

An XML Document contains XML Elements.

An XML element is everything from (including) the


element's start tag to (including) the element's end tag.

An element can contain:

other elements
text
attributes
or a mix of all of the above...
16
There are 5 predefined entity references in XML:

XML – Elements
<bookstore>

<book category="CHILDREN">
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
</book>
<book category="WEB">
<title>Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
</book>
</bookstore>
XML – Elements 17
XML Naming Rules

Names can contain letters, numbers, and other


characters

Names cannot start with a number or punctuation


character.

Names cannot start with the letters xml (or XML, or Xml,
etc)

Names cannot contain spaces.


XML – Elements 18
XML Naming Rules – Best Practice

Make names descriptive. Names with an underscore


separator are nice: <first_name>, <last_name>.

Names should be short and simple, like this:


<book_title> not like this: <the_title_of_the_book>.

Avoid "-" characters. If you name something "first-


name," some software may think you want to subtract
name from first.
XML – Elements 19
XML Naming Rules – Best Practice

Avoid "." characters. If you name something "first.name,"


some software may think that "name" is a property of the
object "first.“

Avoid ":" characters. Colons are reserved to be used for


something called namespaces (more later).

XML documents often have a corresponding database.

A good practice is to use the naming rules of your database


for the elements in the XML documents.
XML – Elements 20
XML Elements are Extensible

XML elements can be extended to carry more information.

<note>
<note> <to>Tove</to>
<to>Tove</to> <from>Jani</from>
<from>Jani</from> <body>Don't forget me<body>
<body>Don't forget me <body> <mes> Its ok </mes>
</note> </note>
XML – Attributes 21
XML elements can have attributes, just like HTML.

Attributes provide additional information about an


element.

XML attributes must be quoted.

<person age=“18” > // 18

<person age=‘18’ > //18

<person age=“my age is &quot;18&quot;”>


// my age is “18”
XML – Attributes 22
XML Elements vs. Attributes

<person gender="female"> <person>

<firstname>Anna</firstname> <gender>female</gender>

<lastname>Smith</lastname> <firstname>Anna</firstname>

</person> <lastname>Smith</lastname>

</person>
XML – Attributes 23
<note date="10/01/2008"> <note>
<to>Tove</to> <date>
<from>Jani</from> <day>10</day>
<heading>Reminder</heading> <month>01</month>
<body>Don't forget me !</body> <year>2008</year>
</note> </date>
<note> <to>Tove</to>
<date>10/01/2008</date> <from>Jani</from>
<to>Tove</to> <heading>Reminder</heading>
<from>Jani</from> <body>Don't forget me </body>
<heading>Reminder</heading> </note>
<body>Don't forget me!</body>
</note>
XML – Validation 24
"Well Formed" XML

"Valid" XML.

XML with correct syntax is "Well Formed" XML.

XML validated against a DTD is "Valid" XML.


XML – Validation 25
"Well Formed" XML

A "Well Formed" XML document has correct XML syntax.

XML documents must have a root element.


XML elements must have a closing tag.
XML tags are case sensitive.
XML elements must be properly nested.
XML attribute values must be quoted.
XML – Validation 26
"Well Formed" XML document

<?xml version="1.0" encoding="ISO-8859-1"?>

<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me!</body>
</note>
XML – Validation 27
“Valid “ XML document

A "Valid" XML document is a "Well Formed" XML


document, which also conforms to the rules of a
Document Type Definition (DTD).
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE note SYSTEM "Note.dtd">
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
XML – Validation 28
XML DTD

The purpose of a DTD is to define the structure of an XML


document. It defines the structure with a list of legal
elements.
<!DOCTYPE note
[
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
]>
XML – Validation 29
XML Schema

W3C supports an XML-based alternative to DTD, called


XML Schema
<xs:element name="note">

<xs:complexType>
<xs:sequence>
<xs:element name="to" type="xs:string"/>
<xs:element name="from" type="xs:string"/>
<xs:element name="heading" type="xs:string"/>
<xs:element name="body" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
XML – Viewing 30
Viewing XML Files

Raw XML files can be viewed in all major browsers.

Don't expect XML files to be displayed as HTML


pages.

XML document carries only data, it does not carray


any information to display these data.
XML – Viewing 31
Viewing XML Files
XML – Viewing 32
Viewing XML Files with Error in XML Document
XML – Example 33

BOOK DETAILS

Book ID BookName Author


TERI101 C Programming Dennis Ritche
TERI102 Java Complete Ref Pattrick Naughton
TERI103 Let us C Yashwant Kanitkar
XML – Example 34
<?xml version="1.0" ?>

<BOOKDETAILS>
<BOOK ID="TERI101">
<BOOKNAME>C PROGRAMMING</BOOKNAME>
<AUTHOR> DENNIS RITCHE</AUTHOR>
</BOOK>
<BOOK ID="TERI102">
<BOOKNAME>JAVA COMPLETE REFERENCE</BOOKNAME
<AUTHOR> PATTRICK NAUGHTON</AUTHOR>
</BOOK>
<BOOK ID="TERI103">
<BOOKNAME>LET US C</BOOKNAME>
<AUTHOR> YASHWANT KANITKAR</AUTHOR>
</BOOK>
</BOOKDETAILS>
Queries
&
Suggestions
Thanks

You might also like