XML vs JSON


<?xml version="1.0" encoding="utf-8"?>
<program event="openfest" year="2014">
<time start="10:15:00" end="11:00:00" >
<lecture id="2" hall="Sofia" language="en" category="social">
<title>This is our future</title>
<description>Is's about time for a cultural change. It's time to get your privacy
back.</description>
<author>
<name>CryptoParty Berlin</name>
<bio>CryptoParty started two years ago in Australia and has since spread around
the world.</bio>
<img>http://www.openfest.org/wp-content/CryptopartyGenericLogo.png</img>
</author>
</lecture>
</time>
</program>XML
+
- структурираност
- валидация
- трансформация
-
- тежест
- повече памет
- по-голяма изчислителна мощност
тагове
атрибути
Schema
XSLT
XPath
{
"program": {
"event": "openfest",
"year": 2014,
"time": {
"start": "10:15:00",
"end": "11:00:00",
"lecture": {
"id": 2,
"hall": "Sofia",
"language": "en",
"category": "social",
"title": "This is our future",
"description": "Is's about time for a cultural change. It's time to get your privacy
back.",
"author": {
"name": "CryptoParty Berlin",
"bio": "CryptoParty started two years ago in Australia and has since spread around
the world.",
"img": "http://www.openfest.org/wp-content/CryptopartyGenericLogo.png"
}
}
}
}
}JSON
+
- опростен
- лек
- лесен за парсване
-
- няма ясна структура
- ограничени типове данни
- трудно преобразуване
скоби
ключ-стойност
JavaScript
APIs
eval()
1. Синтаксис
JSON


2. Тежест
JSON

без особено значение
3. Парсване
в браузъра
JSON

4. Парсване
на сървъра
еднакво

EcmaScript for XML
5. Търсене
XML

6. Преобразуване


XML

7. Сигурност
XML
8. Разширяемост

XML


9. Споделяне на традиционни данни
JSON

10. Споделяне на документи

XML


XML или JSON?
зависи от ситуацията
XML
By Dimitrina Zlatkova
XML
- 660