You are on page 1of 6

JSON & XML

Juan Antonio Snchez Arbs

XML and JSON Similarities

Are a data-description language Information about the elements Easy to understand the content
Standards for exchange information Can be used on all applications independent of the platform Mostly used for exchange web messages

XML Structure

Elements, Tags, Nodes, Attributes

Well Formed and Validity Access by XML DOM of JavaScript

JSON Structure

Based on Javascript Objects and Arrays

Returned like a plain text Parsed to Array with:


Eval(text) Text.parseJSON()

Strengths and Weaknesses

JSON Strengths against XML


Automated serializing of objects Concise Format (Name/Value) Supported by many AJAX toolkits Type check No namespace support Difficult to create nested objects Limited development tools Narrow Focus -> RPC only

JSON Weaknesses against XML


JSON & XML

Example: Book Store HTML Page to show the data JavaScript + Ajax to get the XML / JSON

PHP Server to create a JSON or XML response.

You might also like