- From: Ian Hickson via cvs-syncmail <cvsmail@w3.org>
- Date: Mon, 11 May 2009 10:21:58 +0000
- To: public-html-commits@w3.org
Update of /sources/public/html5/spec In directory hutz:/tmp/cvs-serv6976 Modified Files: Overview.html Log Message: Finish off the microdata intro, and define the order and duplicate handling for property names. (whatwg r3084) Index: Overview.html =================================================================== RCS file: /sources/public/html5/spec/Overview.html,v retrieving revision 1.2241 retrieving revision 1.2242 diff -u -d -r1.2241 -r1.2242 --- Overview.html 11 May 2009 09:06:10 -0000 1.2241 +++ Overview.html 11 May 2009 10:21:55 -0000 1.2242 @@ -5953,8 +5953,10 @@ <p>The <dfn id="dom-htmlpropertycollection-names" title="dom-HTMLPropertyCollection-names"><code>names</code></dfn> attribute must return a live <code>DOMStringList</code> object giving the <a href="#property-names">property names</a> of all the elements - <a href="#represented-by-the-collection">represented by the collection</a>. The same object must be - returned each time.</p> + <a href="#represented-by-the-collection">represented by the collection</a>, listed in <a href="#tree-order">tree + order</a>, but with duplicates removed, leaving only the first + occurrence of each name. The same object must be returned each + time.</p> <p>The <dfn id="dom-htmlpropertycollection-item" title="dom-HTMLPropertyCollection-item"><code>item(<var title="">index</var>)</code></dfn> method must return the <var title="">index</var>th node in the collection. If there is no <var title="">index</var>th node in the collection, then the method must return null.</p> @@ -36428,7 +36430,8 @@ expose information to the user, for example offering it in a form that can be used by other applications.<p>The <code title="dom-document-items"><a href="#dom-document-items">document.items</a></code> DOM attribute provides access to all the <a href="#top-level-microdata-items">top-level microdata - items</a>.<p>Each <a href="#concept-item" title="concept-item">item</a> is represented in the + items</a>. This attribute returns an <code><a href="#htmlcollection-0">HTMLCollection</a></code>, + which can be enumerated.<p>Each <a href="#concept-item" title="concept-item">item</a> is represented in the DOM by the element on which the relevant <code title="attr-item"><a href="#items:-the-item-attribute">item</a></code> attribute is found. The various types that the element has can be obtained using the <code title="dom-item"><a href="#dom-item">element.item</a></code> DOM attribute, which returns a <code><a href="#domsettabletokenlist-0">DOMSettableTokenList</a></code> object.<div class="example"> @@ -36450,7 +36453,83 @@ <pre>var cats = getItems("com.example.feline");</pre> - </div><!-- XXX ... --><h3 id="encoding-microdata"><span class="secno">5.2 </span>Encoding microdata</h3><h4 id="the-microdata-model"><span class="secno">5.2.1 </span>The microdata model</h4><p>The microdata model consists of groups of name-value pairs known + </div><p>Once an element representing an <a href="#concept-item" title="concept-item">item</a> has been obtained, its properties + can be extracted using the <code title="dom-properties"><a href="#dom-properties">properties</a></code> DOM attribute. This + attribute returns an <code><a href="#htmlpropertycollection-0">HTMLPropertyCollection</a></code>, which can + be enumerated to go through each element that adds one or more + properties to the item. It can also be indexed by name, which will + return the property with that name (if there is just one).<p>Each element that adds a property also has a <code title="dom-content"><a href="#dom-content">content</a></code> DOM attribute that returns its + value. + + <div class="example"> + + <p>This sample uses the function above to get the first item of + type "net.example.user" and then pops up an alert using the + "net.example.name" property from that item.</p> + + <pre>var user = getItems('net.example.user')[0]; +alert('Hello ' + user.properties['net.example.name'].content + '!');</pre> + + </div><p>When an item has multiple properties with the same name, the + <code><a href="#htmlpropertycollection-0">HTMLPropertyCollection</a></code> returns a + <code><a href="#propertynodelist">PropertyNodeList</a></code> object with all those properties + instead of returning just one. The <code><a href="#propertynodelist">PropertyNodeList</a></code> + object can be used to obtained all the values at once using + <em>its</em> <code title="dom-PropertyNodeList-content"><a href="#dom-propertynodelist-content">content</a></code> attribute, which + returns an array of all the values.<div class="example"> + + <p>In an earlier example, a "com.example.feline" item had two + "com.example.color" values. This script looks up such items and + then lists all their values. Because it doesn't know ahead of time + if the item has zero, one, or more colors, it checks whether the + value returned from the <code><a href="#htmlpropertycollection-0">HTMLPropertyCollection</a></code> is a + <code><a href="#propertynodelist">PropertyNodeList</a></code> (multiple colors), just a regular + element (one color), or null (no colors) before using it.</p> + + <pre>var cat = getItems('com.example.feline')[0]; +var colors = cat.properties['com.example.color']; +var result; +if (!colors) { + result = 'Color unknown.'; +} else if (colors instanceof PropertyNodeList) { + result = 'Colors:'; + for (var i = 0; i + + </pre></div><p>It's also possible to get a list of all the <a href="#property-names">property + names</a> using the object's <code title="dom-HTMLPropertyCollection-names"><a href="#dom-htmlpropertycollection-names">names</a></code> DOM + attribute.<div class="example"> + + <p>This example creates a big list with a nested list for each item + on the page, each with of all the property names used in that + item./p> + + <pre>var outer = document.createElement('ul'); +for (var item = 0; item + + <p>If faced with the following from an earlier example:</p> + + <pre><section item="org.example.animal.cat com.example.feline"> + <h1 property="org.example.name com.example.fn">Hedral</h1> + <p property="org.example.desc">Hedral is a male american domestic + shorthair, with a fluffy <span + property="com.example.color">black</span> fur with <span + property="com.example.color">white</span> paws and belly.</p> + <img property="org.example.img" src="hedral.jpeg" alt="" title="Hedral, age 18 months"> +</section></pre> + + <p>...it would result in the following output:</p> + + </pre><ul><li> + <ul><li>org.example.name</li> + <li>com.example.fn</li> + <li>org.example.desc</li> + <li>com.example.color</li> + <li>org.example.img</li> + </ul></li> + </ul><p>(The duplicate occurrence of "com.example.color" is not included + in the list.)</p> + + </div><h3 id="encoding-microdata"><span class="secno">5.2 </span>Encoding microdata</h3><h4 id="the-microdata-model"><span class="secno">5.2.1 </span>The microdata model</h4><p>The microdata model consists of groups of name-value pairs known as <dfn id="concept-item" title="concept-item">items</dfn>.<p>Each group has zero or more types, each name has one or more values, and each value is either a string or another group of name-value pairs.<h4 id="items:-the-item-attribute"><span class="secno">5.2.2 </span>Items: the <dfn title="attr-item"><code>item</code></dfn> attribute</h4><p>Every <a href="#html-elements" title="HTML elements">HTML element</a> may have an @@ -36531,7 +36610,9 @@ </ul><p>The <dfn id="property-names">property names</dfn> of an element are the tokens that the element's <code title="attr-property"><a href="#names:-the-property-attribute">property</a></code> attribute is found to contain when its value is <a href="#split-a-string-on-spaces" title="split a string on - spaces">split on spaces</a>.<h4 id="values"><span class="secno">5.2.5 </span>Values</h4><p>The <dfn id="concept-property-value" title="concept-property-value">property value</dfn> of a + spaces">split on spaces</a>, with the order preserved but with + duplicates removed (leaving only the first occurrence of each + name).<h4 id="values"><span class="secno">5.2.5 </span>Values</h4><p>The <dfn id="concept-property-value" title="concept-property-value">property value</dfn> of a name-value pair added by an element with a <code title="attr-property"><a href="#names:-the-property-attribute">property</a></code> attribute depends on the element, as follows:<dl><dt>If the element also has an <code title="attr-item"><a href="#items:-the-item-attribute">item</a></code> attribute</dt>
Received on Monday, 11 May 2009 10:22:08 UTC