#phpbcat
FluentDOMThomas Weinert
About Me
● Application Developer● PHP● JavaScript● XSL
● Papaya Software GmbH● papaya CMS● Technical Director
About You?
About FluentDOM
● JQuery API● DOMNodeList replacement● Learning Project
● Test driven development● Continous Integration● Parser
● Tobias Schlitt● Bastian Feder, Thomas Weinert
Differences To jQuery
● „Only“ Traversing, Manipulation and some Core functions
● Xpath Expressions (not CSS Selectors)● No method html() but xml()● Callbacks have a $node parameter
Chaining
● Methods return objects
Chaining Sample
$fd = FluentDOM($html, 'html') ->find('/html/head/title') ->add('//h1') ->add('//h2');
Traversing
● find()● add()● not()● filter()● has()● end()● andSelf()
● children()● closest()● contents()● parent()● parents()● parentsUntil()● siblings()
● first()● last()● prev()● prevAll()● prevUntil()● next()● nextAll()● nextUntil()
Xpath
● XML Path Language● W3C Recommendation 16 November 1999● Used by
● XSLT 1● Xpointer
● More specific then CSS● More powerful then CSS
Namespaces
● Xpath depends on namespaces● Register your own namespaces prefixes● Method: namespaces()
$title = FluentDOM($xml) ->namespaces( array('project-atom' => 'http://www.w3.org/2005/Atom') ) ->evaluate( 'string(/project-atom:feed/project-atom:title)' );
Interfaces
● IteratorAggregate● Iterator● RecursiveIterator● Seekable
● Countable● ArrayAccess (read only)
Functions
● Create FluentDOM object and load data● FluentDOM● FluentDOMStyle
Manipulation
● append()● prepend()● before()● after()● remove()● replaceAll()● replaceWith()
● appendTo()● prependTo()● insertAfter()● insertBefore()● wrap()● wrapAll()● wrapInner()
● xml()● text()● attr()● addClass()● removeClass()● toggleClass()
Loaders
● Default Loaders● DOMDocument, DOMNode● XML (file and string)● HTML (file and string)
● Additional Loaders● SimpleXMLElement● PDO● JSON
Own Loaders
● Interface FluentDOMLoader● load() returns DOMDocument or DOMNode
Extending FluentDOM
● FluentDOMCore● spawn()● push()● unique()● _applyContentsToNodes()
Future
● CSS Selectors● ?
Get It
● http://fluentdom.org● http://nightly.fluentdom.org● svn://svn.fluentdom.org