Two common data interchange formats: XML and JSON

Data transfer between different programming languages, a need for a common data exchange format, it requires a simple and easy data storage, quickly read, and independently of the various programming languages. We tend to transfer text files, such as we all know csv (comma seperated values) format.

In the Internet, the transmission data structure often have many levels, not the matrix form (m × n) simple. Common are xml, json, yaml and so on. Which, yaml is "yaml is not markup language" recursive acronym, that the first letter of each word combinations just as the first word; and yaml also be interpreted as yet another markup language.

And the feeling of our nearest mainly xml and json, and is often encountered; yaml temporarily no contact. Therefore, this paper to be a little of both this summary.

(A) XML

Extensible Markup Language, Extensible Markup Language.

XML was originally designed to EDI (Electronic Data Interchange, EDI).

Long before the Web was born, SGML (Standard Generalized Markup Language, Standard Generalized Markup Language) was invented. However, it is too complicated, does not apply to the Web, the 1989 HTML (Hyper Text Markup Language, HTML) was born. And there are not describe HTML data, poor readability, long search time and other defects. In 1998, before the two as precursor, W3c (World Wide Web Consortium) released the XML 1.0 standard, marking the birth of XML.

The main grammar rules:

1, must have a declaration statement.

2, the case differently. For example, "<P>" and "<p>" tag are different.

3, XML documents and only one root element, the other element is the child of the root element, the root element of the document in full, including all the other elements.
Root element start tag needs to be before the start of all the other elements of the mark; root element end tag should be placed after the end of all the other elements of the tag.
4, the attribute value quotes.
Inside the HTML code, attribute values ​​may be quoted, may not be added. But XML requires that all attribute values ​​must be quoted (can be single quotes, double quotes can also be recommended to use double quotes), otherwise it will be considered an error.
5. All tags must have a corresponding closing tag
In HTML, you can not mark to appear, and in XML, all tags must appear in pairs, there is a start tag must have a closing tag, otherwise it will be considered an error.
6, all empty tags must be closed
Empty tag is no content between markers A Note on indicators such as "<img>" tag and the like. In XML, requiring all tags must have an end tag.
Example:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="osg.AndroidExample"
      android:installLocation="preferExternal"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:targetSdkVersion="8" android:minSdkVersion="8"></uses-sdk>
    <uses-feature android:glEsVersion="0x00020000"/> <!-- OpenGL min requierements (2.0) -->
    <uses-permission android:name="android.permission.INTERNET"/>
 
    <application android:label="@string/app_name" android:icon="@drawable/osg">
        <activity android:name=".osgViewer"
                  android:label="@string/app_name" android:screenOrientation="landscape"> <!--  Force screen to landscape -->
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
 
    </application>
</manifest>

(B) JSON

JavaScript Object Notation, JavaScript Object Notation.

JSON is a lightweight data interchange format, easy to read and write, but also easy for machines to parse and generate, in 2001 began to promote.

The main grammar rules:

1. six basic symbols (longitudinal spaces are allowed): Array '[' and ']' object '{' and '}', named delimiter ':' Separator ','.

2. The value may be an object, an array, a number, or a string of three literal (false, null, true) one. The literal value in English must be lowercase.

{
    "people": [{
            "firstName": "Brett",
            "lastName": "McLaughlin"
        },
        {
            "firstName": "Jason",
            "lastName": "Hunter"
        }
    ]
}

It is recommended online XML and JSON parser, convenient data format conversion and viewing.

Parsing XML: https://c.runoob.com/front-end/710

Parse JSON: https://www.bejson.com/


 

References:

1. https://baike.baidu.com/item/%E5%8F%AF%E6%89%A9%E5%B1%95%E6%A0%87%E8%AE%B0%E8%AF%AD % E8% A8% 80/2885849? fromtitle = xml & fromid = 86251 & fr = aladdin (Baidu Encyclopedia XML)

2. https://baike.baidu.com/item/JSON (Baidu Encyclopedia JSON)

Guess you like

Origin www.cnblogs.com/maoerbao/p/11466630.html