diff --git a/index.html b/index.html index 0873c33..fb99d66 100644 --- a/index.html +++ b/index.html @@ -1238,6 +1238,192 @@

Associating names with items

Converting Microdata to other formats

+
+

JSON-LD

+ +

Given a list of nodes nodes in a Document, a user agent must + run the following algorithm to extract the Microdata from those nodes into a JSON-LD:

+ +
    + +
  1. Let result be an empty object.

  2. + +
  3. Let items be an empty array.

  4. + +
  5. For each node in nodes, check if the element is a + top-level Microdata item, and if it is then get the object for that element and add it to items.

  6. + +
  7. Add an entry to result called "items" whose + value is the array items.

  8. + +
  9. Add an entry to result called "@context" whose value is the following object:

    +
    { "@vocab" : "" }
  10. + +
  11. Return the result of serializing result to JSON. [[JSON]]

  12. + +
+ +

This algorithm returns an object with a single property that is an array, instead + of just returning an array, so that it is possible to extend the algorithm in the future if + necessary.

+ +

When the user agent is to get the object for an item item, + potentially together with a list of elements memory, it must run the following + substeps:

+ +
    + +
  1. Let result be an empty object.

  2. + +
  3. If no memory was passed to the algorithm, let memory be an empty list.

  4. + +
  5. Add item to memory.

  6. + +
  7. If the item has any item types, add an entry to result + called "@type" whose value is an array listing the + item types of item, in the order they were specified on the + itemtype attribute.

    + +
  8. If the item has a global identifier, add an entry to + result called "@id" whose value is the global + identifier of item.

  9. + +
  10. Let properties be an empty object.

  11. + +
  12. + +

    For each element element that has one or more property names + and is one of the properties of the item + item, in the order those elements are given by the algorithm that returns + the properties of an item, run the following substeps:

    + +
      + +
    1. Let value be the + property value of element.

    2. + +
    3. If value is an item, then: + If value is in memory, then let value be + the string "ERROR". Otherwise, get the object for + value, passing a copy of memory, and then replace value + with the object returned from those steps.

    4. + +
    5. + +

      For each name name in element's + property names, run the following substeps:

      + +
        + +
      1. If there is no entry named name in result, + then add an entry named name to result whose + value is an empty array.

      2. + +
      3. Append value to the entry named name in result.

      4. + +
      + +
    6. + +
    + +
  13. + +
  14. Return result.

  15. + +
+ +
+ +

For example, take this markup:

+ +
<!DOCTYPE HTML>
+<title>My Blog</title>
+<article itemscope itemtype="https://schema.org/BlogPosting">
+ <header>
+  <h1 itemprop="headline">Progress report</h1>
+  <p><time itemprop="datePublished" datetime="2013-08-29">today</time></p>
+  <link itemprop="url" href="?comments=0">
+ </header>
+ <p>All in all, he's doing well with his swim lessons. The biggest thing was he had trouble
+ putting his head in, but we got it down.</p>
+ <section>
+  <h1>Comments</h1>
+  <article itemprop="comment" itemscope itemtype="https://schema.org/Comment" id="c1">
+   <link itemprop="url" href="#c1">
+   <footer>
+    <p>Posted by: <span itemprop="creator" itemscope itemtype="https://schema.org/Person">
+     <span itemprop="name">Greg</span>
+    </span></p>
+    <p><time itemprop="dateCreated" datetime="2013-08-29">15 minutes ago</time></p>
+   </footer>
+   <p>Ha!</p>
+  </article>
+  <article itemprop="comment" itemscope itemtype="https://schema.org/Comment" id="c2">
+   <link itemprop="url" href="#c2">
+   <footer>
+    <p>Posted by: <span itemprop="creator" itemscope itemtype="https://schema.org/Person">
+     <span itemprop="name">Charlotte</span>
+    </span></p>
+    <p><time itemprop="dateCreated" datetime="2013-08-29">5 minutes ago</time></p>
+   </footer>
+   <p>When you say "we got it down"...</p>
+  </article>
+ </section>
+</article>
+ +

It would be turned into the following JSON by the algorithm above (supposing that the page's + URL was http://blog.example.com/progress-report):

+ +
{
+  "items": [
+    {
+      "type": [ "https://schema.org/BlogPosting" ],
+      "properties": {
+        "headline": [ "Progress report" ],
+        "datePublished": [ "2013-08-29" ],
+        "url": [ "http://blog.example.com/progress-report?comments=0" ],
+        "comment": [
+          {
+            "type": [ "https://schema.org/Comment" ],
+            "properties": {
+              "url": [ "http://blog.example.com/progress-report#c1" ],
+              "creator": [
+                {
+                  "type": [ "https://schema.org/Person" ],
+                  "properties": {
+                    "name": [ "Greg" ]
+                  }
+                }
+              ],
+              "dateCreated": [ "2013-08-29" ]
+            }
+          },
+          {
+            "type": [ "https://schema.org/Comment" ],
+            "properties": {
+              "url": [ "http://blog.example.com/progress-report#c2" ],
+              "creator": [
+                {
+                  "type": [ "https://schema.org/Person" ],
+                  "properties": {
+                    "name": [ "Charlotte" ]
+                  }
+                }
+              ],
+              "dateCreated": [ "2013-08-29" ]
+            }
+          }
+        ]
+      }
+    }
+  ]
+}
+ +
+
+ +

JSON

@@ -1653,6 +1839,7 @@

Changes

and the second Working Draft:

@@ -1699,14 +1886,17 @@

Acknowledgements

Christine Runnegar, Gregg Kellogg, Ivan Herman, +Jeni Tennison, Jens Oliver Meiert, Léonie Watson, Manu Sporny, -Marcos Caceres, +Marcos Cáceres, +Markus Lanthaler, Nick Doty, Philippe Le Hégaret, Ralph Swick, Robin Berjon, +Shane McCarron, Tab Atkins, Tavis Tucker, Tobie Langel,