Comparison of XML and JSON two data structures and their respective underlying implementations

Source: Internet
Author: User

Advantages and disadvantages of the 1.XML and JSON two data structures

1> XML
Advantages:?

    • uniform format , standards-compliant?

    • Easy to interact with other systems remotely , data sharing is more convenient

? Disadvantages:

    • XML file format file is large , complex format , transmission consumption bandwidth ?

    • Both the server side and the client need to spend a lot of code parsing XML, whether the server side and client code becomes unusually complex and difficult to maintain

    • The client is different, parsing XML between browsers is inconsistent, you need to write a lot of code repeatedly?

    • Server side and client parsing XML spend resources and time

2> JSON
Advantages:?

    • Data format is relatively simple , easy to read and write , the format is compressed, the use of small bandwidth ?

    • easy to parse the language

    • support multiple languages, including ActionScript, C, C #, ColdFusion, Java, JavaScript, Perl, PHP, Python, Ruby and other languages server-side language, convenient server-side parsing?

    • Because JSON format can be used directly for server-side code, greatly simplifies the server-side and client code development , but the completion of the task is not changed, and easy to maintain?

Disadvantages:?

    • No XML format so popularized and widely used, without XML so universal ?

    • The JSON format is currently promoted in the Web service as an initial stage

2.JSON, the bottom-level implementation of XML parsing method

1> XML

XML two parsing methods,DOM and SAX.

The DOM needs to read through the entire XML document ( document-driven ), Sax is event-driven , does not need to read the entire document, and the document's read-in process is the SAX parsing process.

SAX is simply a way to make an XML document sequential scan , when scanned to document start with end , and end , is triggered by the event handler function do the corresponding action , after processing continue scanning , , parsing is complete

When the Dom parses an XML file, it reads all the contents of the XML file into memory, and then allows you to manipulate the XML tree using the DOM API . That is, theDOM reads the XML into memory in the form of a tree , and then operates the XML tree through the appropriate API . To achieve the purpose of parsing the XML file

2> JSON

The JSON underlying principle iterates through the characters in the string , and is eventually distinguished by Special help characters such as {},[],: Number , and so on,{} is a dictionary ,[] represents an array : Thenumber is the watershed of the dictionary's key and value , and finally the JSON data is converted to a dictionary , and then the dictionary is converted using KVC Model

Comparison of XML and JSON two data structures and their respective underlying implementations

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.