Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 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