/**
  * @param string $string
  * @return FluentDOM
  */
 protected function getFixtureFromString($string)
 {
     $dom = new DOMDocument();
     $dom->loadXML($string);
     $loader = $this->getMock('FluentDOMLoader');
     $loader->expects($this->once())->method('load')->with($this->equalTo(''))->will($this->returnValue($dom));
     $fd = new FluentDOM();
     $fd->setLoaders(array($loader));
     return $fd->load('');
 }
Example #2
0
<?php

/**
* Sample how to use the JSON loader
*
* It loads the FluentDOM twitter timeline. This is only an example, Twitter provides XML, too.
*
* @version $Id: jsonToXml.php 414 2010-03-26 17:27:03Z subjective $
* @package FluentDOM
* @subpackage examples
*/
require_once dirname(__FILE__) . '/../../FluentDOM.php';
require_once dirname(__FILE__) . '/../../FluentDOM/Loader/StringJSON.php';
// get the loader object
$jsonLoader = new FluentDOMLoaderStringJSON();
// activate type attributes
$jsonLoader->typeAttributes = TRUE;
// get a FluentDOM
$fd = new FluentDOM();
// inject the loader object
$fd->setLoaders(array($jsonLoader));
$url = 'http://twitter.com/status/user_timeline/FluentDOM.json?count=10';
$json = file_get_contents($url);
header('Content-type: text/xml');
echo $fd->load($json)->formatOutput();
<?php

require '../../FluentDOM.php';
$xmlFile = 'hello.xml';
class ExampleLoader implements FluentDOMLoader
{
    // this could implement checks, error handling, ...
    public function load($source, $type)
    {
        $dom = new DOMDocument();
        $dom->load($source);
        return $dom;
    }
}
$fd = new FluentDOM();
// set loader(s)
$fd->setLoaders(array(new ExampleLoader()));
// load data  using custom loader
$fd->load($xmlFile);
echo $fd->find('/message')->text('Hello World!');
Example #4
0
<?php

/**
* Sample how to use a custom FluentDOMLoader
*
* @version $Id: iniToXml.php 429 2010-03-29 08:05:32Z subjective $
* @package FluentDOM
* @subpackage examples
*/
require_once dirname(__FILE__) . '/../../FluentDOM.php';
require_once dirname(__FILE__) . '/FluentDOMIniLoader.php';
$iniFile = dirname(__FILE__) . '/sample.ini';
$fd = new FluentDOM();
$fd->setLoaders(array(new FluentDOMIniLoader()));
header('Content-type: text/plain');
echo $fd->load($iniFile, 'text/ini')->formatOutput();
echo "\n\n";
echo 'URL: ', $fd->find('//URL')->text();