Recent Posts

Friday, 2 September 2016

XML Tutorial


What is XML? 
1. XML stands for Extensible Markup Language
2. XML is a markup language much like HTML.
3. XML also a specification {From W3C {World Wide Web Consortium}]
4. XML was designed to describe data.
5. XML is self describing.

What is markup?
     Enclosing textual content with in textual codes (tags) is nothing but markup. Markup is also called tagging.

Similarities between HTML and XML?
1. Both are languages of web.
2. Both are markup languages.
3. Both are originated from SGML. [Standardized General Markup Language]
4. Tags are basic building blocks of both HTML and XML documents.

Differences between HTML and XML
1. HTML tags are predefined tags where as XML tags are user defined tags.
2. HTML tags are limited number of tags where as XML tags are extensible.
3. HTML tags are case insensitive where as XML tags are sensitive.
4. HTML tags are meant for displaying the data but not for describing the data where as XML tags are meant for describing the data.
5. HTML focuses on how data looks where as XML focuses on what data is.

Purpose of XML
1. XML is used to exchange the information between applications in language (jav, .net, PHP) independent, vendor independent and platform independent manner over web.
2. XML documents are used as textual databases.
3. XML documents are used as deployment descriptors
4. XML is used to create new Internet languages(XHTML, WSDL, WAP, SMIL...etc)

What XML does?
1. Nothing
2. Just XML was created to structure, store and transport the data.
The following example is a email to Vinod from Ashok, stored as XML.
<email>
   <to>Vinod</to>
   <from>Ashok</from>
   <subject>Reminder(Party)</subject>
   <body>Don't forget me this weekend!</body>
</email>
     The email above is quite self descriptive. It has sender and receiver information, it also has a subject and a message body.

     But still, this XML document does not DO anything. It is just information wrapped in tags. Someone must write a piece of software to send, receive or display it.

Who invented XML tags?
* With XML You Invent Your Own 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. I

* That is because the XML language has no predefined tags.

* The tags used in HTML are predefined. HTML documents can only use tags defined in the HTML standard (like <p>, <hi>, etc.).

What is an XML document?
     Any text file that is developed with .xml extension is an xrnl document.

What is XML application?
1. Any computer application that works with an xrnl document is nothing but an XML application.
2. Working with XML document means, perform CRUD operations on the XML.

XML Syntax

An Example XML document
<?xml version="1.0"?>
<email>
   <to>Vinod</to>
   <from>Ashok</from>
   <subject>Reminder(Party)</subject>
   <body>Don't forget me this weekend!</body>
</email>
     The first line in the document: The XML declaration should always be included. It defines the XML version of the document. In this case the document conforms to the 1.0 specification of XML
<?xml version="1.0"?>
     The next line defines the first element of the document (the root element).
<email>
     The next lines defines 4 child elements of the root (to, from, subject, and body)
<to>Vinod</to>
<from>Ashok</from>
<subject>Reminder(Party)</subject>
<body>Don't forget me this weekend!</body>
     The last line defines the end of the root element
</email>
Note
1. All XML elements must have a closing tag
2. In HTML some elements do not have to have a closing tag. The following code is legal in HTML
<p>This i s a paragraph
<p>This is another paragraph
     In XML all elements must have a closing tag like this
<p>This is a paragraph</p>
<p>This is another paragraph</p>
XML tags are case sensitive
1. XML tags are case sensitive The tag <Letter> IS different from the tag <letter>.
2. Opening and closing tags must therefore be written with the same case.
E.g
<Message>This is incorrect tag</message>
<message>This is correct tag</message>
All XML elements must be properly nested
1. In HTML some elements can be improperly nested within each other like this: I
<b><i>This text is bold and italic</b></i>
2. In XML all elements must be properly nested within each other like this
<b><i>This is text is bold and italic</i></b>
All XML documents must have a root tag
     All XML documents must contain a single tag pair to define the root element. All other elements must be nested within the root element. All elements can have sub (children) elements. Sub elements must be in pairs and correctly nested within their parent element
<root>
   <child>
      <subchild>
      </subchild>
   </child>
</root>
Attribute values must always be quoted
     XML elements can have attributes in name/value pairs just like in HTML. In XML the attribute value must always be quoted. Study the two XML documents below. The first one is incorrect, the second is correct
<?xml version="1.0"?>
<email date=25-08-2016>
   <to>Vinod</to>
   <from>Ashok</from>
   <subject>Reminder(Party)</subject>
   <body>Don't forget me this weekend!</body>
</email>
<?xml version="1.0"?>
<email date="25-08-2016">
   <to>Vinod</to>
   <from>Ashok</from>
   <subject>Reminder(Party)</subject>
   <body>Don't forget me this weekend!</body>
</email>
Next Tutorial  XML Entity References

15 comments:

  1. Hi Ashok
    You have written great content about xml tutorials. I learn few important things from this. And, this will great help for beginners specially to learn xml

    Thank you
    Haresh

    ReplyDelete
  2. Such a nice post for xml tutorials, I am working on one xml project at the moment. So I am sure this will help me.

    ReplyDelete
  3. Hello Ashok, this is great xml tutorial I found. Thank you for posting such a nice content.

    ReplyDelete
  4. Dear Sir
    Publishing this xml tutorial is great work you did it, no one can write easily this type of tutorial without having proper expertise on xml tutorial
    Thank you so much for your time.

    ReplyDelete
  5. Great blog thanks for sharing Instagram and Facebook have provided an amazing place for new brands to grow and flourish. We can find the perfect niche for your brand on the best social media marketing company in chennai.

    ReplyDelete
  6. Nice blog thanks for sharing Set up a aesthetic work environment that employees love to spend time in and relieve their stress. Your company needs the best corporate gardening service in Chennai and Karuna Nursery Gardens in happy to oblige you in the endeavour to make your infrastructure something worth flaunting about.

    ReplyDelete
  7. Excellent blog thanks for sharing Run your salon business successfully by tying up with the best beauty shop in Chennai - The Pixies Beauty Shop. With tons of prestigious brands to choose from, and amazing offers we’ll have you amazed.

    ReplyDelete
  8. Awesome blog thanks for sharing With over a three decade of beauty expertise at our fingertips, we believed that everyone has the right to be beautiful. And so began the journey of our very own Pearl’s Beautician course in Chennai.

    ReplyDelete
  9. Excellent blog thanks for sharing While choosing your perfect ride for driving, Accord Cars comes with and the best packages for you to pick from. Car rentals for self drive in Chennai are done the easier. Just pick out your plan from hourly, daily, weekly and even monthly plans available.

    ReplyDelete
  10. Excellent blog post to understand xml. Here, you can find some more about how to write file in C#

    ReplyDelete