2007 barcelona drupalcon: drupal and simplexml
DESCRIPTION
TRANSCRIPT
![Page 1: 2007 Barcelona Drupalcon: Drupal and SimpleXML](https://reader033.vdocument.in/reader033/viewer/2022051312/5463a5e2b4af9f493f8b45f6/html5/thumbnails/1.jpg)
Drupal and SimpleXML
![Page 2: 2007 Barcelona Drupalcon: Drupal and SimpleXML](https://reader033.vdocument.in/reader033/viewer/2022051312/5463a5e2b4af9f493f8b45f6/html5/thumbnails/2.jpg)
XML parsing
• Very well defined, well known standards
• Excellent support ...
• ... in most other languages
• Long-standing PHP weakness (up to version 4)
![Page 3: 2007 Barcelona Drupalcon: Drupal and SimpleXML](https://reader033.vdocument.in/reader033/viewer/2022051312/5463a5e2b4af9f493f8b45f6/html5/thumbnails/3.jpg)
two main models
![Page 4: 2007 Barcelona Drupalcon: Drupal and SimpleXML](https://reader033.vdocument.in/reader033/viewer/2022051312/5463a5e2b4af9f493f8b45f6/html5/thumbnails/4.jpg)
SAX
![Page 5: 2007 Barcelona Drupalcon: Drupal and SimpleXML](https://reader033.vdocument.in/reader033/viewer/2022051312/5463a5e2b4af9f493f8b45f6/html5/thumbnails/5.jpg)
Simple API for XML
• Stream - based xml parsing
• Event - driven API
• Uni-directional
![Page 6: 2007 Barcelona Drupalcon: Drupal and SimpleXML](https://reader033.vdocument.in/reader033/viewer/2022051312/5463a5e2b4af9f493f8b45f6/html5/thumbnails/6.jpg)
DOM
![Page 7: 2007 Barcelona Drupalcon: Drupal and SimpleXML](https://reader033.vdocument.in/reader033/viewer/2022051312/5463a5e2b4af9f493f8b45f6/html5/thumbnails/7.jpg)
Document Object Model
• Full object representation of an XML document
• Supports writing documents
• Same system used by browsers, javascript, etc (i.e. “known quantity”)
![Page 8: 2007 Barcelona Drupalcon: Drupal and SimpleXML](https://reader033.vdocument.in/reader033/viewer/2022051312/5463a5e2b4af9f493f8b45f6/html5/thumbnails/8.jpg)
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
![Page 9: 2007 Barcelona Drupalcon: Drupal and SimpleXML](https://reader033.vdocument.in/reader033/viewer/2022051312/5463a5e2b4af9f493f8b45f6/html5/thumbnails/9.jpg)
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
![Page 10: 2007 Barcelona Drupalcon: Drupal and SimpleXML](https://reader033.vdocument.in/reader033/viewer/2022051312/5463a5e2b4af9f493f8b45f6/html5/thumbnails/10.jpg)
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
![Page 11: 2007 Barcelona Drupalcon: Drupal and SimpleXML](https://reader033.vdocument.in/reader033/viewer/2022051312/5463a5e2b4af9f493f8b45f6/html5/thumbnails/11.jpg)
SAX example
![Page 12: 2007 Barcelona Drupalcon: Drupal and SimpleXML](https://reader033.vdocument.in/reader033/viewer/2022051312/5463a5e2b4af9f493f8b45f6/html5/thumbnails/12.jpg)
SAX example (cont.)
![Page 13: 2007 Barcelona Drupalcon: Drupal and SimpleXML](https://reader033.vdocument.in/reader033/viewer/2022051312/5463a5e2b4af9f493f8b45f6/html5/thumbnails/13.jpg)
SAX example (cont)
![Page 14: 2007 Barcelona Drupalcon: Drupal and SimpleXML](https://reader033.vdocument.in/reader033/viewer/2022051312/5463a5e2b4af9f493f8b45f6/html5/thumbnails/14.jpg)
SAX example (cont)
![Page 15: 2007 Barcelona Drupalcon: Drupal and SimpleXML](https://reader033.vdocument.in/reader033/viewer/2022051312/5463a5e2b4af9f493f8b45f6/html5/thumbnails/15.jpg)
SAX drawbacks
• Awkward maintain state across events
• Requires prior knowledge of the document
• Maybe not so simple (lots to code)
![Page 16: 2007 Barcelona Drupalcon: Drupal and SimpleXML](https://reader033.vdocument.in/reader033/viewer/2022051312/5463a5e2b4af9f493f8b45f6/html5/thumbnails/16.jpg)
Enter SimpleXML
![Page 17: 2007 Barcelona Drupalcon: Drupal and SimpleXML](https://reader033.vdocument.in/reader033/viewer/2022051312/5463a5e2b4af9f493f8b45f6/html5/thumbnails/17.jpg)
SimpleXML
• DOM-based processing - including xpath
• Included in PHP5
• And, um, it’s simple
![Page 18: 2007 Barcelona Drupalcon: Drupal and SimpleXML](https://reader033.vdocument.in/reader033/viewer/2022051312/5463a5e2b4af9f493f8b45f6/html5/thumbnails/18.jpg)
SimpleXML example
![Page 19: 2007 Barcelona Drupalcon: Drupal and SimpleXML](https://reader033.vdocument.in/reader033/viewer/2022051312/5463a5e2b4af9f493f8b45f6/html5/thumbnails/19.jpg)
Example file
![Page 20: 2007 Barcelona Drupalcon: Drupal and SimpleXML](https://reader033.vdocument.in/reader033/viewer/2022051312/5463a5e2b4af9f493f8b45f6/html5/thumbnails/20.jpg)
SimpleXML example
![Page 21: 2007 Barcelona Drupalcon: Drupal and SimpleXML](https://reader033.vdocument.in/reader033/viewer/2022051312/5463a5e2b4af9f493f8b45f6/html5/thumbnails/21.jpg)
XPath example
![Page 22: 2007 Barcelona Drupalcon: Drupal and SimpleXML](https://reader033.vdocument.in/reader033/viewer/2022051312/5463a5e2b4af9f493f8b45f6/html5/thumbnails/22.jpg)
SimpleXML+
drupal_http_request() ftw
![Page 23: 2007 Barcelona Drupalcon: Drupal and SimpleXML](https://reader033.vdocument.in/reader033/viewer/2022051312/5463a5e2b4af9f493f8b45f6/html5/thumbnails/23.jpg)
simple webservices
![Page 24: 2007 Barcelona Drupalcon: Drupal and SimpleXML](https://reader033.vdocument.in/reader033/viewer/2022051312/5463a5e2b4af9f493f8b45f6/html5/thumbnails/24.jpg)
When SimpleXML isn’t simple
![Page 25: 2007 Barcelona Drupalcon: Drupal and SimpleXML](https://reader033.vdocument.in/reader033/viewer/2022051312/5463a5e2b4af9f493f8b45f6/html5/thumbnails/25.jpg)
namespaces
![Page 26: 2007 Barcelona Drupalcon: Drupal and SimpleXML](https://reader033.vdocument.in/reader033/viewer/2022051312/5463a5e2b4af9f493f8b45f6/html5/thumbnails/26.jpg)
Example file
![Page 27: 2007 Barcelona Drupalcon: Drupal and SimpleXML](https://reader033.vdocument.in/reader033/viewer/2022051312/5463a5e2b4af9f493f8b45f6/html5/thumbnails/27.jpg)
Namespaces example
![Page 28: 2007 Barcelona Drupalcon: Drupal and SimpleXML](https://reader033.vdocument.in/reader033/viewer/2022051312/5463a5e2b4af9f493f8b45f6/html5/thumbnails/28.jpg)
maybe it’s not so bad
![Page 29: 2007 Barcelona Drupalcon: Drupal and SimpleXML](https://reader033.vdocument.in/reader033/viewer/2022051312/5463a5e2b4af9f493f8b45f6/html5/thumbnails/29.jpg)
XML Writing
![Page 30: 2007 Barcelona Drupalcon: Drupal and SimpleXML](https://reader033.vdocument.in/reader033/viewer/2022051312/5463a5e2b4af9f493f8b45f6/html5/thumbnails/30.jpg)
XML Writing example
![Page 31: 2007 Barcelona Drupalcon: Drupal and SimpleXML](https://reader033.vdocument.in/reader033/viewer/2022051312/5463a5e2b4af9f493f8b45f6/html5/thumbnails/31.jpg)
Advantages for Drupal
• Shorter, cleaner code (think cleaner aggregator.module, etc)
• Manipulatable DOM structure (think hook_xml_alter)
• XML Writing (think node_feed, etc)
![Page 32: 2007 Barcelona Drupalcon: Drupal and SimpleXML](https://reader033.vdocument.in/reader033/viewer/2022051312/5463a5e2b4af9f493f8b45f6/html5/thumbnails/32.jpg)
Thanks, PHP5