Comparison of XML and JSON format transmission in Ajax

Source: Internet
Author: User
Tags pepr php server

XML is a common Service-Oriented Architecture (SOA) and data transmission. Of course, many services currently exist in the soap format. However, when to use it for data transmission in AjaxCommunity.

[XML]
Advantages of using XML as the transmission format:
1. unified format, compliant with standards
2. Easy remote interaction with other systems and convenient data sharing
3. Call the existing service that uses XML for transmission.
4. You can use XSLT to dynamically convert XML. This is an ideal function in the Enterprise Service Bus (ESB) solution.

Disadvantages:
1. xml file format is large, complex, and occupies bandwidth for Transmission
2. Both the server side and the client side require a large amount of moneyCodeXML parsing, regardless of the exception, complexity, and difficulty in maintaining the server and client code
3. The method for parsing XML between different browsers on the client is inconsistent. You need to repeat a lot of code.
4. It takes resources and time for the server and client to parse XML

[JSON]
In addition to the XML format, there are no other formats. There is a lightweight data exchange format called JSON (JavaScript Object Notation) that can replace XML.

Advantages:
1. The data format is relatively simple, easy to read and write, the format is compressed, the bandwidth usage is small, and browser resolution is fast
2. It is easy to parse this language. The client javascript can simply read JSON data through eval ().
3. user-friendly structure and support for multiple languages, including ActionScript, C, C #, ColdFusion, Java, JavaScript, Perl, PHP, Python, Ruby, and other language server-side languages for server-side Parsing
4. In the PHP world, there has been a PHP-JSON and a JSON-PHP that facilitates PHP serialization afterProgramDirectly calling objects and arrays on the. php server can directly generate JSON format, which facilitates client access extraction.
In addition, the pear class of PHP has proposed support (http://pear.php.net/pepr/pepr-proposal-show.php? Id = 198)
5. JSON format can be used directly for server-side code, which greatly simplifies the development of server-side and client-side code, but the completed tasks remain unchanged and easy to maintain.
6. relatively stable. The additional content of JSON will become a superset.

Disadvantages:
1. It is widely used and widely used without the XML format. It is not as universal as XML.
2. The JSON format is still in the initial stage in Web service promotion.

 

Personal Summary: XML or JSON can be used as needed. A project can use both formats under specific circumstances.

However, this is not recommended because this method may cause trouble to the code management of the entire project. Exercise caution!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.