Ajax without X and microformat without angle brackets (1)

Source: Internet
Author: User

With the rise of AJAX and microformats, are these formats still usable? Or is the micro-style "light" enough? See how to use MochiKit for AJAX (without X) in JSON (more lightweight than YAML) and how to use reStructured Text in microfile generation tasks.

XML is used to mark both documents and structured data. There are different interpretations of good and bad. It depends on your opinion. XML may be the winner in the case of vague document and data boundaries, but as a general solution, XML may be more complex than any given solution for a problem. David has previously discussed YAML (see references ). YAML Ain't Markup Language or Yet Another Markup Language (YAML) is a dialect that provides simpler data (numbers, strings, lists, and simple structures) than XML) transfer as the target. In this article, we will discuss JSON (JavaScript Object Notation), which is a real subset of YAML, but is easier to create and parse. In JavaScript and Python, if the JSON source is reliable, you can directly use the script engine to evaluate the value, and the corresponding parser is available for the JSON source that is unreliable.

Although JSON applications are close to the data end in the document-data lineage, structured text formats can also be used to process documents with high colors. There are three main Structured Text methods (not a wide variety of Wiki tags): reStructured Text, Markdown, and Textile. We will analyze these three formats, at least theoretically looking at how they handle microformats.

What are the microformats?

What kind of data is contained in a micro-mode? The purpose of the micro-mode is to put (usually) a small amount of data into a format that is easy for human or machine processing, if we ignore this restriction and encode the data according to human reading or machine processing (but not at the same time), then processing it to get a microfile version will bring some benefits. Common examples of hCalendar include the following information:

  • Summary/Title
  • Location
  • URL
  • Start date (and optional time)
  • End Date (and optional time)
  • Time Zone
  • Description

So many codes are required. Listing 1 shows an example of a hCalendar event:

Listing 1. hCalendar event


Href = "http://www.vanpyz.org/conference/keynotes.html">

August 4, 2006-19: 00
-


-

Vancouver Python Workshop Keynotes
-

Fletcher Challenge Canada Theatre,
SFU Harbour Center,
Downtown Vancouver



The Vancouver Python Workshop keynote address is
Opportunity to hear from leading members of the Python
Community. This years speakers are Guido van rosum
Google and Jim Hugunin from Microsoft.



If only basic data is left, the same event can be encoded in JSON format. Note that the date, time, and time zone are all encoded in ISO8601, which is the standard format for formatting the date and time. It is also a microformat. The example in Listing 2 is legal code in JavaScript or Python:

List 2. JSON Encoding

Event = {
'Title': 'vancouver Python Workshop keynote ',
'Location': 'fletcher Challenge Canada Theatre ,\
SFU Harbour Center, Downtown Vancouver ',
'Url': 'http: // www.vanpyz.org/conference/keynotes.html ',
'Start': '2017-08-04T19: 00-0700 ',
'End': '2017-08-04T21: 00-0700 ',
'Description': 'The Vancouver Python Workshop keynote address \
Is an opportunity to hear from leading members of the Python \
Community. This years speakers are Guido van rosum of Google \
And Jim Hugunin from Microsoft .'};

If only basic data is left, the same event can be encoded in JSON format. Note that the date, time, and time zone are all encoded in ISO8601, which is the standard format for formatting the date and time. It is also a microformat. The example in Listing 2 is legal code in JavaScript or Python:

List 2. JSON Encoding

Event = {
'Title': 'vancouver Python Workshop keynote ',
'Location': 'fletcher Challenge Canada Theatre ,\
SFU Harbour Center, Downtown Vancouver ',
'Url': 'http: // www.vanpyz.org/conference/keynotes.html ',
'Start': '2017-08-04T19: 00-0700 ',
'End': '2017-08-04T21: 00-0700 ',
'Description': 'The Vancouver Python Workshop keynote address \
Is an opportunity to hear from leading members of the Python \
Community. This years speakers are Guido van rosum of Google \
And Jim Hugunin from Microsoft .'};

As shown in the following figure, this format can be easily transmitted on the Web.

You have obtained data from my documents!

JSON is used to represent the data end. For documents, we can start from structured text to microformat. What is hCalendar written using reStructured Text? Of course, reST allows the use of commands to create plug-in extensions, so the commands for parsing hCalendar data can be as follows:

.. Event ::

LOCATION: Fletcher Challenge Canada Theatre,
SFU Harbour Center, Downtown Vancouver
DTSTART: TZID = America/Vancouver: 20060804T190000
DTEND: TZID = America/Vancouver: 20060804T210000
SUMMARY: Vancouver Python Workshop Keynotes
DESCRIPTION: The Vancouver Python Workshop keynote address
Is an opportunity to hear from leading members of the Python
Community. This years speakers are Guido van rosum of Google
And Jim Hugunin from Microsoft.

What's interesting about this idea is that the hCalendar specification is a ing from the original iCalendar standard to an HTML subset. What does this mysterious iCalendar look like? Listing 3 shows the same events in iCalendar:

Listing 3. Events in iCalendar

BEGIN:VCALENDARVERSION:2.0PRODID:-//Apple Computer\, Inc//iCal 2.0//ENBEGIN:VEVENTDURATION:PT3HLOCATION: Fletcher Challenge Canada Theatre,SFU Harbour Center, Downtown VancouverDTSTAMP:20060615T034522ZUID:FE31377A-AB78-4D99-BC25-3F09C99E5928DTSTART;TZID=America/Vancouver:20060704T100000SUMMARY:Vancouver Python Workshop KeynotesDESCRIPTION:The Vancouver Python Workshop keynote addressis an opportunity to hear from leading members of the Pythoncommunity. This years speakers are Guido van Rossum of Googleand Jim Hugunin from Microsoft.END:VEVENTEND:VCALENDAR

Yes, iCalendar is a text-based format, which is relatively simple to parse. You can find the library that parses this format and the operation results can be obtained in any language you choose. Therefore, if you implement the reStructured Text command to obtain all the data elements of hCalendar, you only need to modify the. include: Command to directly format the content of iCalendar to hCalendar. Because there are a lot of tools for importing and exporting iCalendar formats, such as Apple's iCal, directly reusing this format may be better. We are not going to discuss in detail how to add or modify the commands in reStructured Text, not only for simplicity, but also because Dethe has worked with primary reStructured Text developers David Goodger to write that tutorial.

Lighter than air, but hard to breathe

Although JSON provides a data format that is simpler than YAML or XML, reStructured Text is a very complex tool. The reStructured Text document may be easier to read than the XML document. It is easier if you do not plan to take advantage of all its features. However, if many commands, tables, and other features are added, the Complexity Meter of Dethe becomes more difficult. Since JSON is simplified by standardizing a common compromise, it leads to the emergence of Domain Specific Language (DSL, if you are willing to sacrifice some features and flexibility of reStructured Text, you can further simplify structured Text. In addition, this more lightweight format than the lightweight document-centric format already exists.

We will discuss Textile and MarkDown. These two lightweight structured text formats simplify the creation of micro-formatted data. Unfortunately, the features that make these two tools successful in creating document-centric content are not helpful for more data-oriented jobs such as hCalendar. Textile has no <DIV> or tag, and there is no way to add classes. Although it is flexible, it is easy to add the class, id, and style attributes, but cannot add the title attribute. Markdown does not add attributes at all. Although PyMarkdown supports attribute extension, there is no <DIV> or such structure. Both systems can pass pre-formatted HTML, but this completely loses the benefit of using a lightweight format.

These lightweight Markup languages lack support for microformats. In essence, microformats are data, while Textile and MarkDown are both tools used for Web creation. Their goal is to help you easily find the words you need and add a bit of format, but ignore the problem of inserting machine-readable data. One of the old problems with XML is that it is used for both machine-readable information of data) and human-understandable text of content ). The structured text format is close to the content end, while the YAML and JSON are at the data end. Each format may be better or better than XML, but the boundaries between data and content are not so clear, such as microformats, which are hard to go beyond the boundaries.


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.