2009-06-11

FluentDOM

Today I like to present a new projekt: FluentDOM

It provides an easy to use, jQuery like, fluent interface for DOMDocument.

The idea was born in a workshop of Tobias Schlitt about the PHP XML extensions at the IPC Spring in Berlin.

The last few days Bastian Feder and I implemented it. That's how it looks in action:

require_once('../FluentDOM.php');
echo FluentDOM($xml)
 ->node(
   FluentDOM($samples)
   ->find('//b[@id = "first"]')
   ->removeAttr('id')
   ->addClass('imported')
 )
 ->replaceAll('//p');

We are aware that here are some other projects with similiar concepts. But none of them matched our requirements (XML targeted, XPath selectors, namespace support, ...).

You can take a look at the current version in Bastian's public SVN.

svn://fluentdom.org/trunk/FluentDOM

5 comments:

  1. Hey Thomas,
    it was fun trying out how test driven development works.

    Btw. For those who do not like to use svn may download the current version of FluentDOM from
    http://download.bastian-feder.de/FluentDOM.tar.gz

    hf
    Lapis

    ReplyDelete
  2. What`s the difference to phpQuery[1]?

    [1] http://code.google.com/p/phpquery/

    ReplyDelete
  3. Basics and details :-)

    FluentDOM has a different target (reading and manipulating XML documents) and uses xpath selectors.

    For the details - check the source.

    ReplyDelete
  4. Sounds promising :) Will look at the sources and play around with it.

    ReplyDelete
  5. I have more and more fun using this. Great work! I even get more and more used started to xpath queries. Thanks for sharing this.

    ReplyDelete

x