Thursday 14 May 2015

What is XML ?

A little bit about HTML

Hypertext Markup Language, a standardized system for tagging text files to achieve font, colour, graphic, and hyperlink effects on World Wide Web pages.
The tags used to markup HTML documents and the structure of HTML documents are predefined. The author of HTML documents can only use tags that are defined in the HTML standard.


What is XML

It allows the author to define his own tags and his own document structure.
It stands for EXtensible Markup Language
It is a markup language much like HTML
It was designed to describe data, not to display data
Its tags are not predefined. You must define your own tags
It is designed to be self-descriptive

The Difference Between XML and HTML

1. XML is not a replacement for HTML.
2. XML and HTML were designed with different goals:
3. XML was designed to describe data, with focus on what data is
4. HTML was designed to display data, with focus on how data looks
5. HTML is about displaying information, while XML is about carrying information.

what do XML?

XMl is use only for carrying data. Its do not do any thing esle.

Sample Example:-
  <Message>
  <to>Amit</to>
  <from>Rampal</from>
  <heading>Reminder</heading>
  <body>Don't forget me this weekend!</body>
</Message>

Defining own your tags:-
With XML You can 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.
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>, <h1>, etc.).
XML allows the author to define his/her own tags and his/her own document structure.
XML is Not a Replacement for HTML
XML is a complement to HTML.

Example 2:-

<?xml version="1.0" encoding="UTF-8" ?>
<Employee>

<Persion1>
<Name>Ramesh</Name>
                        <Gender>Male</Gender>
<EmailId>abc@gmail.com</EmailId>
<MobileNo>8861447949</MobileNo>
<Address>844 Ganesg PG Rajaji Nagar Bangluru</Address>
<City>Bangluru</City>
<Country>India</Country>
                        <Pin>560010</Pin>
</Persion1>
                <Persion2>
<Name>Kiran</Name>
                        <Gender>Female</Gender>
<EmailId>def@gmail.com</EmailId>
<MobileNo>8904801563</MobileNo>
<Address>366 Hitech city Madhavpur Hyderabad</Address>
<City>Bangluru</City>
<Country>India</Country>
                        <Pin>111003</Pin>
</Persion2>

</Employee>

Note:- It is important to understand that XML is not a replacement for HTML. In most web applications, XML is used to describe data, while HTML is used to format and display the data.
XML is a software- and hardware-independent tool for carrying information.




Wednesday 13 May 2015

What is JSON ?

Here I explained what is JSON and what is the use of it with examples

What is JSON?

JSON stands for JavaScript Object Notation
JSON is a lightweight data-interchange format
JSON is language independent 
JSON is "self-describing" and easy to understand



Keys and Values

The two primary parts that make up JSON are keys and values. Together they make a key/value pair.
Key:  A key is always a string enclosed in quotation marks.
Value:  A value can be a string, number, boolean expression, array, or object.

Key/Value Pair:  A key value pair follows a specific syntax, with the key followed by a colon                                          followed by the value. Key/value pairs are comma separated.

Types of Values

Array:  An associative array of values.
Boolean: True or false.
Number:  An integer.
Object:  An associative array of key/value pairs.
String:  Several plain text characters which usually form a word.

Syntex:-

var json = {"Name1":"Value1", "Name2":"Value2"}

OR

var json = {"Key1":"Value1", "Key2":"Value2"}

JSON is built on two structures:
A collection of name/value pairs. In various languages, this is realized as an object, record, struct, dictionary, hash table, keyed list, or associative array.
An ordered list of values. In most languages, this is realized as an array, vector, list, or sequence.
These are universal data structures. Virtually all modern programming languages support them in one form or another. It makes sense that a data format that is interchangeable with programming languages also be based on these structures.

JSON is short for JavaScript Object Notation, and is a way to store information in an organized, easy-to-access manner. In a nutshell, it gives us a human-readable collection of data that we can access in a really logical manner.
It is easy for machines to parse and generate. It is based on a subset of the JavaScript Programming Language
JSON uses JavaScript syntax, but the JSON format is text only, just like XML.
Text can be read and used as a data format by any programming language.

The following JSON example defines an Product object, with an array of 4 Product records:

Simple JSON Example
This is sample example of JSON object enclosing by curly braces

Var json=  {
                    "ProductId":"101",
                    "ProductName":"Redmi Note",
                     "Price":"9000"
                  };


JSON Array Example
Some times we need to store more records in a single variable to do this we enclose multiple objects by square braces called JSON Array.

Var json= {"ProductArray":[

                                            {"ProductId":"101", 
                                             "ProductName":"Redmi Note",
                                             "Price":"9000"},

                                              {"ProductId":"102",
                                                "ProductName":"Redmi 1S",
                                         "Price":"6000"},

                                              {"ProductId":"103",
                                                 "ProductName":"Redmi 3",
                                                 "Price":"14000"},

                                                {"ProductId":"104",
                                                 "ProductName":"Redmi 4G",
                                                  "Price":"10000"}
                                           ]}

in the above example json is variable that contains an Array of product called ProductArray.

Nested JSON

In Simple JSON Array each Key have associated with a value but in Nested JSON Array
Some of keys again contains a JSON object see in below example.

Var json=  {
                       "CellPhone": {"ProductId":"101",
                                               "ProductName":"Redmi Note",
                                               "Price":"9000"
                                                },
 
                       "Accessories": {"ProductId":"201",
                                                   "ProductName":"Earphones with Mic",
                                                   "Price":"1100"
                                                  }
};