parsing-microformats: Difference between revisions

From Microformats Wiki
Jump to navigation Jump to search
m (→‎See Also: wiki syntax)
(→‎Microformat Parsing: Parsing class values)
Line 7: Line 7:


Developers can use tools like XPATH that assume well-formedness on well-formed content (from the web or by using tidy).  Mark Pilgrim's example [http://sourceforge.net/projects/feedparser/ universal feed parser] suggests that it may be possible to sanitize user html to an extent that it is suitable for later processing as xml.
Developers can use tools like XPATH that assume well-formedness on well-formed content (from the web or by using tidy).  Mark Pilgrim's example [http://sourceforge.net/projects/feedparser/ universal feed parser] suggests that it may be possible to sanitize user html to an extent that it is suitable for later processing as xml.
== Parsing class values ==
When parsing class values care must be taken:
# Class attributes may contain multiple class names, e.g: <code>class="foo vcard bar"</code>
# Class attributes may contain class names which contain the class name used by a microformat, e.g: <code>class="abc<strong>vcard</strong>def"</code>
# Multiple class names are seperated by one or more whitespace charchters.
# Class names are case sensitive.
See http://www.w3.org/TR/html401/struct/global.html#h-7.5.2.
=== JavaScript example ===
<code>
if (<em>elemenent</em>.className.match(/\b<strong>vcard</strong>\b/)) ...
</code>
=== XSLT example ===
<code>
&lt;xsl:if test="contains(normalize-whitespace(concat(@class,' ')),'<strong>vcard</strong> ')"&gt; ...
</code>


== See Also ==
== See Also ==


* [[xmdp-brainstorming]]
* [[xmdp-brainstorming]]

Revision as of 13:21, 1 November 2005

Microformat Parsing

Microformat parsing mechanisms that depend on documents having even minimal xml properties like well-formedness may fail when consuming non-well-formed content. Tidy or even better CyberNeko may be a useful work around. In particular Brian Suda's frequently cited X2V hCard and hCalendar discovery and transformation prototypes use XSLT, and "tidy" any non-well-formed input before processing it.

Most microformats tend to be agnostic about things like exact element type used.

Developers can use tools like XPATH that assume well-formedness on well-formed content (from the web or by using tidy). Mark Pilgrim's example universal feed parser suggests that it may be possible to sanitize user html to an extent that it is suitable for later processing as xml.

Parsing class values

When parsing class values care must be taken:

  1. Class attributes may contain multiple class names, e.g: class="foo vcard bar"
  2. Class attributes may contain class names which contain the class name used by a microformat, e.g: class="abcvcarddef"
  3. Multiple class names are seperated by one or more whitespace charchters.
  4. Class names are case sensitive.

See http://www.w3.org/TR/html401/struct/global.html#h-7.5.2.

JavaScript example

if (elemenent.className.match(/\bvcard\b/)) ...

XSLT example

<xsl:if test="contains(normalize-whitespace(concat(@class,' ')),'vcard ')"> ...

See Also