2009-07-14

FluentDOM Loaders

We are still improving and experimenting with FluentDOM. We removed the constructor and added a load() method. The reason was to allow the creation of new documents with FluentDOM.


Now this is possible:

$fd = new FluentDOM();
$fd->append($fd->document->createElement('html'))
   ->append($fd->document->createElement('body'))
   ->append('<h1>Hell World</h1>');
echo $fd;

FluentDOM uses loader objects (Thanks for the idea Toby) and supports different types of sources. You can load HTML or XML , files or strings or define your own custom loaders. To load a HTML file you can just use the FluentDOM function or the load() method:

$fd = FluentDOM($fileName, 'text/html');

$fd = new FluentDOM();
$fd->load($fileName, 'text/html');

Or you define your own loader object:

$fd = new FluentDOM();
$fd->setLoaders(array(new MyFluentDOMLoader()));
$fd->load($source, $contentType);

You can find an example for inifiles in ~/examples/iniloader/.