Slideshow transcript
Slide 1: Drupal and SimpleXML
Slide 2: XML parsing • Very well defined, well known standards • Excellent support ... • ... in most other languages • Long-standing PHP weakness (up to version 4)
Slide 3: two main models
Slide 4: SAX
Slide 5: Simple API for XML • Stream - based xml parsing • Event - driven API • Uni-directional
Slide 6: DOM
Slide 7: Document Object Model • Full object representation of an XML document • Supports writing documents • Same system used by browsers, javascript, etc (i.e. “known quantity”)
Slide 8: Other key concepts • Namespaces: Allow extending existing XML documents • XPath: selector syntax for addressing parts of a document • XSLT: “template” language for transforming XML documents into other formats
Slide 9: DOM in PHP • http://php.net/domxml • Traditionally required external libraries and additional PHP compile flags • Has been removed from PHP core in PHP5 (available as a PECL module) • not really an option for Drupal core
Slide 10: SAX in PHP • Available in PHP 4 & PHP 5 ( --with-xml ) • Closest “built-in” support • (hence what we use in Drupal) • http://php.net/xml
Slide 11: SAX example
Slide 12: SAX example (cont.)
Slide 13: SAX example (cont)
Slide 14: SAX example (cont)
Slide 15: SAX drawbacks • Awkward maintain state across events • Requires prior knowledge of the document • Maybe not so simple (lots to code)
Slide 16: Enter SimpleXML
Slide 17: SimpleXML • DOM-based processing - including xpath • Included in PHP5 • And, um, it’s simple
Slide 18: SimpleXML example
Slide 19: Example file
Slide 20: SimpleXML example
Slide 21: XPath example
Slide 22: SimpleXML + drupal_http_request() ftw
Slide 23: simple webservices
Slide 24: When SimpleXML isn’t simple
Slide 25: namespaces
Slide 26: Example file
Slide 27: Namespaces example
Slide 28: maybe it’s not so bad
Slide 29: XML Writing
Slide 30: XML Writing example
Slide 31: Advantages for Drupal • Shorter, cleaner code (think cleaner aggregator.module, etc) • Manipulatable DOM structure (think hook_xml_alter) • XML Writing (think node_feed, etc)
Slide 32: Thanks, PHP5



Add a comment on Slide 1
If you have a SlideShare account, login to comment; else you can comment as a guest- Favorites & Groups
Showing 1-50 of 3 (more)