HTML and CSS Reference
In-Depth Information
</h1>
<img itemprop="photo" alt="AJ"
src="http://www.userfriendly.org/cartoons/
cartoons/aj/headshot_aj.gif" >
<span itemprop="email">
<a href="mailto:aj@userfriendly.org">
aj@userfriendly.org
</a>
</span>
You can see the full code in ch05/microdata-api-1a.html. Here are the
results of running the same extraction loop used earlier:
Found: http://microformats.org/profile/hcard
fn: A. J.
n: [object HTMLElement]
photo: http://www.userfriendly.org/cartoons/cartoons/aj/
headshot_aj.gif
email: aj@userfriendly.org
The email is fixed, but now there's something wrong with the n value.
It's no longer a simple string, it's an HTMLElement . This is because if an
item has child properties, itemValue doesn't contain a string; instead it
contains another NodeList object. You can loop through that one the
same way as before, but it's easier to define a recursive function:
function getMDProperties(name, props) {
if (name.length > 0) name += '/';
for (var i = 0; i < props.length; i++) {
if (typeof(props[i].itemValue) == 'object') {
getMDProperties(props.names[i],
props[i].itemValue.properties);
} else {
log(name + props.names[i] + ': '
+ props[i].itemValue);
}
}
}
This function is modeled on the loop used before, but it checks to see
whether itemValue is an object. If it is, then the properties of the child
object are passed recursively to the function. The name of the parent
Search WWH ::




Custom Search