请输入您要查询的百科知识:

 

词条 JsonML
释义

  1. Syntax

     Example Transformation  "Object Form" Misnomer 

  2. Comparison to similar technologies

     XML/XSLT  InnerHTML  HTML message pattern/Browser-side templating 

  3. References

  4. External links

{{Ad|date=March 2014}}{{Infobox file format
| name = JSON Markup Language
| icon =
| logo =
| screenshot =
| extension =
| mime = application/jsonml+json (unofficial)
| type code =
| uniform type =
| magic =
| owner =
| genre = Markup language and Web template system
| container for =
| contained by =
| extended from = XML, JSON and JavaScript
| extended to =
| standard =confidnets
}}

JsonML, the JSON Markup Language is a lightweight markup language used to map between XML (Extensible Markup Language) and JSON (JavaScript Object Notation). It converts an XML document or fragment into a JSON data structure for ease of use within JavaScript environments such as a web browser, allowing manipulation of XML data without the overhead of an XML parser.

JsonML has greatest applicability in Ajax (Asynchronous JavaScript and XML) web applications. It is used to transport XHTML (eXtensible HyperText Markup Language) down to the client where it can be deterministically reconstructed into DOM (Document Object Model) elements. Progressive enhancement strategy can be employed during construction to bind dynamic behaviors to otherwise static elements.[1]

JsonML can also be used as the underlying structure for creating intricate client-side templates called JBST (JsonML+Browser-Side Templates).[2] Syntactically JBST looks like JSP (JavaServer Pages) or ASP.NET (Active Server Pages .NET) user controls. Interactive examples are available on the jsonml.org website.

Syntax

Conversion from XML to JsonML is partially reversible. XML Namespaces are handled by prepending the element name with the namespace prefix, e.g., <myns:myElement/> becomes ["myns:myElement"].

Example Transformation

JsonML allows any XML document to be represented uniquely as a JSON string. The syntax uses:

  • JSON arrays to represent XML elements;
  • JSON objects to represent attributes;
  • JSON strings to represent text nodes.

["person",

  {"created":"2006-11-11T19:23",   "modified":"2006-12-31T23:59"},  ["firstName", "Robert"],  ["lastName", "Smith"],  ["address", {"type":"home"},    ["street", "12345 Sixth Ave"],    ["city", "Anytown"],    ["state", "CA"],    ["postalCode", "98765-4321"]  ]

]

RobertSmith
12345 Sixth AveAnytownCA98765-4321
JsonML encodedOriginal XML

A “regular” JSON transformation produces a more compact representation, but loses some of the document structural information, in that it does not define whether a key-value pair is an attribute or a node:

{"person": {
    "address": {        "city": "Anytown",        "postalCode": "98765-4321",        "state": "CA",        "street": "12345 Sixth Ave",        "type": "home"    },    "created": "2006-11-11T19:23",    "firstName": "Robert",    "lastName": "Smith",    "modified": "2006-12-31T23:59"

}}

"Object Form" Misnomer

In a JSON user group thread, Douglas Crockford incorrectly used the term "JsonML" to describe two variants: the "array form" and "object form".[3] This was a misuse of the term JsonML which has always stood to mean what Crockford referred to as the "array form".[4]

Comparison to similar technologies

XML/XSLT

XML and XSLT (Extensible Stylesheet Language Transformations) can also produce client-side templating, and both allow caching of the template separate from the data. Many programmers however find the syntax of JBST is easier to manage due to its familiarity. JBST uses JavaScript natively in the template, rather than requiring mixing of different types of control language.

InnerHTML

While seemingly used to perform similar tasks, JsonML and innerHTML are quite different. InnerHTML requires all the markup in an exact form, meaning that either the server is rendering the markup, or the programmer is performing expensive string concatenations in JavaScript.

JsonML uses client-side templating through JBST, which means that HTML is converted into a JavaScript template at build time. At run time, the data is supplied and DOM elements are the result. The resulting DOM elements can be inserted or replace an existing element, which innerHTML cannot easily do without creating excess DOM elements. Rebinding only requires requesting additional data, which is smaller than fully expanded markup. As a result, large performance gains are often made, since the markup is requested or cached separately from the data.

HTML message pattern/Browser-side templating

For simplicity, innerHTML has been the preferred method for the HTML-Message pattern[5] style of Ajax. However, tools like JsonFx[6] aim to simplify JsonML and JBST implementation while still providing a full browser-side templating Ajax pattern.[7]

References

1. ^{{cite web|last=McKamey|first=Stephen M.|title=JsonML - Binding Behaviors to DOM Elements|url=http://jsonml.org/Ajax-UI/Binding/|work=Official website|publisher=JsonML.org|accessdate=7 January 2011|date=3 February 2007|deadurl=yes|archiveurl=https://web.archive.org/web/20100814050135/http://jsonml.org/Ajax-UI/Binding/|archivedate=14 August 2010|df=}}
2. ^{{cite web|last=McKamey|first=Stephen M.|title=JsonML + Browser-Side Templating (JBST)|url=http://jsonml.org/bst/|work=Official website|publisher=JsonML.org|accessdate=7 January 2011|date=3 August 2008}}
3. ^http://tech.groups.yahoo.com/group/json/message/1115
4. ^http://jsonml.org/syntax/
5. ^{{cite web|title=HTML Message|url=http://ajaxpatterns.org/HTML_Message|work=About AjaxPatterns.org|publisher=AjaxPatterns.org|accessdate=7 January 2011|deadurl=yes|archiveurl=https://archive.is/20120701122939/http://ajaxpatterns.org/HTML_Message|archivedate=1 July 2012|df=}}
6. ^{{cite web|title=Welcome to JsonFx.NET|url=http://jsonfx.net/|work=JsonFx.NET Official Website|publisher=Stephen M. McKamey|accessdate=7 January 2011}}
7. ^{{cite web|title=Browser-Side Templating|url=http://ajaxpatterns.org/Browser-Side_Templating|publisher=AjaxPatterns.org|accessdate=7 January 2011|deadurl=yes|archiveurl=https://archive.is/20120707073731/http://ajaxpatterns.org/Browser-Side_Templating|archivedate=7 July 2012|df=}}

External links

  • JsonML.org
  • IBM developerWorks Article
  • [https://web.archive.org/web/20090201191440/http://json.org/javadoc/org/json/JSONML.html Java JSONML implementation] - written by Douglas Crockford
  • JsonFx.NET - C#/.NET JBST Framework
  • [https://web.archive.org/web/20110511075950/https://www.p6r.com/software/jdx.html C++ JDX XPath 2.0 for XML, JSON and JsonML]

4 : JSON|Lightweight markup languages|Data serialization formats|XML markup languages

随便看

 

开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。

 

Copyright © 2023 OENC.NET All Rights Reserved
京ICP备2021023879号 更新时间:2024/9/22 10:02:04