Why is it all against XML and is it supported using JSON?

Source: Internet
Author: User
Tags rfc

One use factor: the structure of the JSON is more easily mapped to the data structure of the general language.

The main components of XML and JSON:

    • XML is element, attribute, and element content.
    • JSON is object, array, string, Number, Boolean (true/false), and null.

The XML is meant to represent an object (the collection of Name-value pair), which may initially use element as object, each key-value pair is represented by attribute:

<student name="John" age="10"/>


But if a value is also an object, then it cannot be used as a attribute:

<student name="John" age="10">    <address>        <country>China</country>        <province>Guang Dong</province>        <city>...</city>        <district>...</district>        ...    </address></student>

Then, when to use element, when to use attribute, it is already a problem. [1] Some advantages and disadvantages are mentioned.

JSON because of the type of object, you can naturally map, do not need to consider the above problems, naturally get the following format.

{    "name": "John",    "age" : 10,    "address" : {        "country" : "China",        "province" : "Guang Dong",        "city" : "..",        "district" : "..",        ...    }}


Besides

    • XML needs to choose how to deal with the line wrap of element content, and JSON string does not have to make this choice.
    • XML has only text, there is no preset number format, and JSON has a clear numbers format, which is also safe on the locale.
    • XML map Array No big problem, is the array element tag comparison redundant redundancy. JSON is easier to read.
    • JSON's true/false/null can also be easily unified to the corresponding semantics of the general programming language.


Finally, you can focus on my C + + Open source JSON project Miloyip/rapidjson GitHub.

[1] ASC X12 REFERENCE MODEL for XML design§7.2.5 http://www. X12.org/x12org/comments/x12reference_model_for_xml_design.pdf

*************************************************************************************************************** ***************************************

The place where the cannon had to hit the mosquitoes turned out to be more comfortable for the flies. Just as Python does a lot of Web servers instead of C + + and Java. Not every code for a century, dtd/xsd not write well when my JSON API has been debugged completed.

Let's give the simplest example.

In [1]: from json import dumpsIn [2]: d = {‘name‘: "vczh", ‘rate‘: "UINT_MAX", ‘comments‘: [‘vczh is the god‘, ‘php is the god too‘]}In [3]: print(dumps(d, indent=4)){    "rate": "UINT_MAX",     "name": "vczh",     "comments": [        "vczh is the god",         "php is the god too"    ]}

Modeling with built-in types, seamlessly into JSON format, and seemingly not even familiar (even syntactically fully compatible in the above example), traditional heavy tools such as XML, such as java/c++, are not.
With the Python built-in dict/string type and the C + + std::string, Std::hash_map, JSON expresses semi-structured data, because there are several basic types built in, although there is a possibility that flexibility is limited (and only is a possibility), but the degree of convenience should be greatly improved. For more information, please refer to the @Milo YIP predecessors ' answers posted at 11:18.

As @vczh mentioned in the comments, XML can be easily mapped to C # types, and @ Shen Wanma also mentions that XML contains a variety of redundant information. In fact, these two points are mutually reinforcing.
The design of JSON is based on several very simple basic types (json.org the entire syntax in the first 5 charts), which is actually more suitable for dictionary-based dynamic types and even prototype-based languages, which is inseparable from JSON from JavaScript.

This and dynamic language built-in type seamlessly transforms the ability to match a variety of excellent REPL (Clojure REPL, IPython Notebook, etc. The previous code is the IPython interaction process, which truly embodies the power of the so-called "exploratory programming" (exploratory programming). For more on exploratory programming please refer to Paul Graham's "Hackers & Painter" excerpt, which I would not have quoted.

P.s. After having a JSON Pointer that has been RFC 6901 [1] and a large implementation of Json-schema [2], there are fewer reasons to use XML.
[1] RFC 6901-javascript Object Notation (JSON) Pointer
[2] JSON Schema software

Refrences:

http://www.zhihu.com/question/25636060

Why is it all against XML and is it supported using JSON?

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.