0% found this document useful (0 votes)
135 views7 pages

XML and JSON

The document compares XML and JSON data formats. XML uses tags to identify parts of a document and how they relate, and was designed to store and transport data. XML is human- and machine-readable. JSON is an alternative to XML that uses JavaScript object notation to store and exchange data. It does not use tags and is easier for machines to parse and generate. The key differences are that XML uses tags and is document-oriented, while JSON does not use tags and is data-oriented and supports arrays.

Uploaded by

Prakash
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
135 views7 pages

XML and JSON

The document compares XML and JSON data formats. XML uses tags to identify parts of a document and how they relate, and was designed to store and transport data. XML is human- and machine-readable. JSON is an alternative to XML that uses JavaScript object notation to store and exchange data. It does not use tags and is easier for machines to parse and generate. The key differences are that XML uses tags and is document-oriented, while JSON does not use tags and is data-oriented and supports arrays.

Uploaded by

Prakash
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 7

XML and JSON

XML
XML stands for eXtensible Markup Language.
• Markup is information added to a document that enhances its
meaning in certain ways, in that it identifies the parts and how they
relate to each other.

• XML was designed to store and transport data.


-XML is extremely useful for keeping track of small to medium
amounts of data without requiring a SQL-based backbone.
• XML was designed to be both human- and machine-readable.
• XML was designed to be self-descriptive
• Open source
• XML is not a replacement to HTML

Is XML a Programming Language?

XML does not qualify to be a programming language as it does not perform any
computation or algorithms.
It is usually stored in a simple text file and is processed by special software that is
capable of interpreting XML.
Example
<?xml version = "1.0"?>
<Students>
<student id=‘1’>
<name>Guru</name>
<course>M.Sc</course>
<subject>Computer Science</subject>
</student>
<student id=‘2’>
<name>John</name>
<course>M.Sc</course>
<subject>Physics</subject>
</student>
.
.
.

</Students>
</xml>
Parsing a XML
• (DOM)Document Object Model: defines a standard for accessing and
manipulating documents.
• The XML DOM defines a standard way for accessing and manipulating XML
documents.

From xml.dom.minidom import parse


dom=parse(“test.xml”)
for node in dom.getElementByTagName(“student”):
id=node.getAttribute(“id”)
name=node.getElementbyTagName(“name”)
[0].ChildNodes[0].nodeValue
print(“Student id:”,id)
print(“Student Name:”,name)
JSON
•Stands for JavaScript Object Notation.
•It is a syntax for storing and exchanging data.
•Used as alternative to XML.
• It is text, written with JavaScript object notation.
•Easy for machine to parse and generate.
•It doesn’t use any tag.

{
“Students": [
{ "id":"01", “name": “Guru", “course": “M.Sc", “subject": “Computer
Science" },
{ "id":“02", “name": “John", " course ": " M.Sc ", " subject ": “Physics" }]
}
Parsing JSON

Example: Convert a string into a date:

var text = '{ "name":"John", "birth":"1986-


12-14", "city":"New York"}';

var obj = JSON.parse(text);

obj.birth = new Date(obj.birth);


Differences between XML and JSON

XML JSON
1. XML is less simple than JSON. 1. JSON is simple to read and write.

2. Uses tags 2. Doesn’t use any tags

3. XML is document-oriented. 3. JSON is data-oriented.

4. XML doesn't support array. 4. JSON supports array.

5. XML is more secured. 5. JSON is less secured than XML.

6. Not so light weighted so it is bit 6. Light weighted so faster


slower

You might also like