示例#1
0
function hresume_import($url)
{
    global $mF_roots;
    $out = null;
    $xmfp = Xmf_Parser::create_by_URI($mF_roots, $url);
    $mf = $xmfp->get_parsed_mfs();
    // hmm... what to do with errors?
    //print_r( $xmfp->get_errors() );
    if (array_key_exists('hresume', $mf)) {
        // only use first one...
        $out = hresume_slurp($mf['hresume'][0]);
    }
    return $out;
}
  the sounds of El Camino traffic.  Next door to a superb indy bookstore, 
  Cafe Borrone is an ideal spot to grab a 
  <a href="http://en.wikipedia.org/wiki/coffee" rel="tag">coffee</a> 
  or a meal to accompany a newly purchased book or imported periodical.  
  <a href="http://technorati.com/tag/soup" rel="tag">Soups</a> and 
  <a href="http://technorati.com/tag/sandwich" rel="tag">sandwich</a> 
  specials rotate daily.  The corn chowder with croutons and big chunks of cheese 
  goes especially well with a freshly toasted mini-baguette.  Evenings are 
  often crowded and may require sharing a table with a perfect stranger. 
  <a href="http://flickr.com/photos/tags/espresso" rel="tag">Espresso</a> 
  afficionados will appreciate the 
  <a href="http://en.wikipedia.org/wiki/Illy" rel="tag">Illy</a> coffee.  
  Noise levels can vary from peaceful in the late mornings to nearly overwhelming on 
  <a href="http://en.wikipedia.org/wiki/jazz" rel="tag">jazz</a> band nights.
 </p></div>
 Review (<a href="http://microformats.org/wiki/hreview"> 
  hReview v<span class="version">0.3</span></a>)
 by <span class="reviewer vcard"><span class="fn">anonymous</span></span>, 
 <abbr class="dtreviewed" title="20050428T2130-0700">April 28th, 2005</abbr>.
<a href="http://creativecommons.org/licenses/by/2.0/" rel="license">cc by 2.0</a>
 </div>

</body>
</html>
HTML;


$xmfp = Xmf_Parser::create_by_HTML($mF_roots, $html);
echo( $xmfp->get_parsed_mfs_as_XML(false, false) );
?>
	/**
	 * Test for including of a subproperty of one mf into the subproperty of another subproperty (Multiple Ocurrences).
	 *
	 */
	function test_include_of_subproperty_mf_into_a_nested_mf_subproperty() {
		$html = <<< HTML
<html><body>

	<div class="vcard">
  	<div class="fn org">The Bricklayers Arms</div>
<span class="tel" id="bricktel">
<span class="value">897898923</span>
<span class="type">work</span></span>
  	</div>


Elsewhere on the page, a number of reviews reference the hcard subproperty in the item property. Rather than repeat all the verbose detail, only the name is reprinted and the detailed hcard referenced using the include-pattern.

<div class="hreview" id="the-review">
   <h1 class="summary">A great venue for monthly gatherings!</h1>
   <div class="item">
	<div class="vcard" id="bricklayers-card">
  	<div class="fn org">The Bricklayers Arms</div>
 	<object class="include" data="#bricktel"></object>
  	</div>
   </div>
   <p class="description">Wonderful pub, cheap beer, open fire to warm mince pies at Christmas.</p>
</div>
</body>
</html>		
HTML;
		$xmfp = Xmf_Parser::create_by_HTML($this->mf_roots, $html, "");
		$arr = $xmfp->get_parsed_mfs();
		$test_arr = array(  "vcard" => array(  0 => array(  "fn" => "The Bricklayers Arms" ,  "org" => array(  "organization-name" => "The Bricklayers Arms") ,  "tel" => array(  0 => array(  "tel" => "897898923" ,  "type" => array(  0 => "work"))))) ,  "hreview" => array(  0 => array(  "summary" => "A great venue for monthly gatherings!" ,  "item" => array(  "vcard" => array(  "fn" => "The Bricklayers Arms" ,  "org" => array(  "organization-name" => "The Bricklayers Arms") ,  "tel" => array(  0 => array(  "tel" => "897898923" ,  "type" => array(  0 => "work"))))) ,  "description" => "Wonderful pub, cheap beer, open fire to warm mince pies at Christmas.")));
		$this->assertEqual($arr, $test_arr, "The Test for including of a subproperty of one mf into the subproperty of another subproperty (Multiple Ocurrences) failed");		
	}
 /**
  * Factory construction of the object by HTML
  * 
  * @param array $mF_roots The Array with all the MF_roots to be searched in the document
  * @param string $html the html to be parsed
  * @param uri $URI the uri to be used when deciding base
  * @param boolean $be_strict whether or not to be strict when dealing with errors in results.
  */
 static function create_by_HTML($mF_roots, $html, $URI = "", $be_strict = FALSE)
 {
     //Create instance of Xmf_Parser
     $xmfp = new Xmf_Parser();
     //Set $URI
     $xmfp->set_URI($URI);
     //Set $be_strict
     $xmfp->set_be_strict($be_strict);
     //Parse HTML
     $tidy = tidy_parse_string($html, $xmfp->tidy_conf);
     //Decide Base
     $xmfp->decide_base($tidy->head());
     //Parse Body
     $xmfp->parse_roots($mF_roots, $tidy->body());
     $xmfp->process_results();
     return $xmfp;
 }
<?php
/**
 * Simple example of How to Use the Class by specifying a URL
 * 
 * @package xmfp
 * @subpackage examples
 */

?><html>
<body>
<?php
define('XMFP_INCLUDE_PATH', '/home/www/test/xmf_parser-0.7/');
require_once(XMFP_INCLUDE_PATH . 'class.Xmf_Parser.php');

$xmfp = Xmf_Parser::create_by_URI($mF_roots, 'http://metonymie.com');

echo('<h1>Results</h1><pre>');
print_r( $xmfp->get_parsed_mfs() );
echo('</pre>');
echo('<h1>Errors</h1><pre>');
print_r( $xmfp->get_errors() );
echo('</pre>');
?>
</body>
</html>
<?php

/**
 * Simple example of How to Use the Class by specifying a URL. This one gives a lot of non real errors since it's and hresume
 * 
 * @package xmfp
 * @subpackage examples
 */
header('Content-Type: text/html; charset=UTF-8');
?>
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head>
<body><?php 
define('XMFP_INCLUDE_PATH', '/home/www/xmf_parser/');
require_once XMFP_INCLUDE_PATH . 'class.Xmf_Parser.php';
//$xmfp = Xmf_Parser::create_by_URI($mF_roots, 'http://valeurdusage.net/drupal62/cv');
$xmfp = Xmf_Parser::create_by_URI($mF_roots, 'http://www.linkedin.com/in/steveganz');
echo '<h1>Results</h1><pre>';
$results = $xmfp->get_parsed_mfs();
print_r($results);
echo '</pre>';
echo '<h1>Errors</h1><pre>';
print_r($xmfp->get_errors());
echo '</pre>';
?>
</body>
</html>