ツリー-JSON、XML、YAMLなどのキラー

こんにちは、私の名前はDmitry Karlovskyです。 バカなJSONのために、XMLの何が間違っていたのか、なぜ最近XMLが取引されたのかを考えました。 これらの推測の結果は、XMLの柔軟性、JSONのシンプルさ、YAMLの可視性を組み込んだ新しい標準データ形式でした。

画像 ツリーは、構造化データを表すための2次元バイナリセーフ形式です。 人間とコンピューターの両方で読みやすい。 シンプル、コンパクト、高速、表現力豊か、拡張可能。 他の一般的な形式と比較して、次の比較表を作成できます。
多いほど良いジョンソンXMLヤムルイニ樹木
人間の理解度31455
編集のしやすさ31455
カスタム階層33315
実装のしやすさ32155
解析/シリアル化速度31155
シリアル化されたサイズ31455
ストリーム処理のサポート00555
バイナリセキュリティ30005
有病率55330
編集者のサポート55351
プログラミング言語のサポート55351

フォーマット比較


人間の理解度

JSONとXMLを使用すると、出力をスペースと改行で任意にフォーマットできます。 ただし、多くの場合、さまざまな理由(主な理由は小さく、実装は簡単です)で1行にフォーマットされ、非常に読みにくくなります。

{ "users" : [ { "name" : "Alice" , age : 20 } ] }

<users><user><name>Alice</name><age>20</age></user></users>

, JSON — , escape- .

{ "description" : "Hello, Alice!\nHow do you do?" }

, XML , « », «» .

<greeting>
    Hello, <b>Alice</b>!<br/>
    How do you do?
</greeting>

<greeting>
    Hello, <a href="http://example.org/user/alice?ref=xe3o7rubvo283xb">Alice</a>!<br/>
    How do you do?
</greeting>

« », escape-. XML . Tree, , .

<title>"Rock&roll" = life</title>

{ "title" : "\"Rock&roll\" = life" }

image


JSON XML , . . — , . , , Tree, .


INI .

XML — , , , .

JSON YAML «» «». . , AST, .

Tree . , .


JSON

(30 ), .

XML

(90 ), , sgml.

YAML

(210 ). , , , .

INI

(8 ), , (--).

Tree

(10 ), , , .

/

, .

. YAML , JSON, XML - .

Tree — .


: github.com/nin-jin/tree.d/tree/master/formats

, XML, . JSON YAML - . — INI, Tree JSON.


, , . — . — , .

XML JSON — , .


. Tree — , ( unix- , , ).


XML , . JSON, , . INI , . YAML , « , , ». Tree .


XML JSON . YAML . INI , . Tree , IDEA .


, . Tree — D TypeScript/JavaScript.

Tree



. .
. Tree .
. API Tree.


Tree — , : , , . , 3 :
— . . , .
— . . — .
— , . . , .

Tree , XML. JSON YAML. , INI. , Tree.


Tree- , (0x0D). , . . . - . - – , .
-, - , . . – -. , - .
, .

, , …

Tree



Tree , , Tree:

image

grammar.tree
, .

is

. , .

image

STATEMENT «», « ».

octet

(8 ) .

image

SEMICOLON . , .

optional

.

image

: . .

any-of

.

image

list-of

( ).

image

DELIMITER .

except

. , , .

image

EXPRESSION « ».

image

( « »), « ».

with-delimiter

, .

image

SCRIPT , .

-

. , .

image


"---" , .

image

-

DSL Tree XML . xml.tree xml «@», «!» «?» , .

image

xml.tree
QName – . – .

image

     <html>
        <head>
            <title> & </title>
        </head>
        <body>
            <h1>!</h1>
            <p>,    ?</p>
        </body>
    </html>

QName , «@».

image

    <script type="text/javascript" src="index.js" />

. , , XML .

Tree , c «%». , XML. XML .

image

    <link
        rel="canonical"
        href="/?article=rock%26roll&author=Nin+Jin"
    />

"--". , , xml.tree.

image

    <!--<a href="/">top</a>-->

"?" - , -.

image

    <?xml version="1.0" stanalone="yes" ololo?>


, . , DSL .

image


. NodeJS AST — JSON.

, JS:

function getEl( id ){
	return document.getElementById( id )
}

, AST - :

[
	{ "function": {
		"name": "getEl",
		"args": [ "id" ],
		"body": [
			{ "return": [
				{ "get": "document" },
				{ "call": {
					"name": "getElementById",
					"args": [
					 	{ "get": "id" }
					]
				}}
			]}
		]
	}}
]

, , . , , , — :

[ [ "function",
    "getEl",
    [ "id" ],
    [ "return",
      [ [ "get",
          "document" ],
        [ "call",
          "getElementById",
          [ "get", "id" ]
        ]
      ]
    ]
  ]
]

Tree :

image

, Tree

Tree , . , XML — Tree.

? , Tree . , , , , XML , xml.tree , , , XML.

UNIX-

JSON "JSON pipes ". : linux , . JSON, , . Tree , .


Tree Lisp — . Lisp , Tree — . AST, DSL , .


D 50 , — 20. — 15. , 100 : github.com/nin-jin/tree.d

:
    string data = cast(string) read( "path/to/file.tree" ); // read from file
    Tree tree = Tree.parse( data , "http://example.org/source/uri" ); // parse to tree

:
    Tree userNames = tree.select( "user name" ); // returns name-nodes
    Tree userNamesValues = tree.select( "user name " ); // returns value-nodes

:
    string name = userNames[0].name; // get node name
    string stringValue = userNames[0].value; // get value as string with "\n" as delimiter
    uint intValue =  userNames[0].value!uint; // get value converted from string to another type

    Tree[] childs = tree.childs; // get child nodes array
    string uri = tree.uri; // get uri like "http://example.org/source/uri#3:2"

:
    string data = tree.toString(); // returns string representation of tree
    tree.pipe( stdout ); // prints tree to output buffer


Tree IDEA, , . Tree , .

, Alex222 SynWrite


Tree. . . . — . .

2016-09-11



( , ), .

:
! City : table
	ID : field
		type : int 11
		null : false
		unique : true
	Name : field
		type : char 35
		null : true
		unique : false
City
	ID : 1
	Name : \Kabul
City
	ID : 4079
	Name : \Rafah
City
	ID : 23023
	Name : \Moscow


":", "\".


Source: https://habr.com/ru/post/J248147/


All Articles