Your SlideShare is downloading. ×
XML and PHP 5
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

XML and PHP 5

1,548

Published on

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,548
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
28
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. A Sneak Preview of XML in PHP 5 Adam Trachtenberg Co-Author PHP Cookbook [email_address] January 21, 2004
  • 2. XML Extensions in PHP 5
    • Work together as a unified whole.
    • Are standardized on a single XML library: libxml2 .
    • Fully comply with W3 specifications.
    • Efficiently process data.
    • Provide you with the right XML tool for your job.
  • 3. Five Major Extensions
    • DOM
    • SAX
    • SimpleXML
    • XPath
    • XSLT
  • 4. Music Catalogue XML
    • <music>
    • <artist id=&quot;1&quot;>
    • <name> The Rolling Stones </name>
    • <albums>
    • <title> Exile On Main Street </title>
    • </albums>
    • </artist>
    • <artist id=&quot;2&quot;>
    • <name> Aimee Mann </name>
    • <albums>
    • <title> I'm With Stupid </title>
    • <title> Bachelor No. 2 </title>
    • </albums>
    • </artist>
    • </music>
  • 5. DOM
    • The 800 pound gorilla of XML.
    • You can do everything and the <kitchen:sink> with DOM, but navigating through your documents can be cumbersome.
    • Tree-based API
    • Undergone a complete rewrite to correspond with DOM specifications.
  • 6. DOM Example Code $music = new domDocument ; $music -> preserveWhiteSpace = false ; $music -> load ( 'music.xml' ); $names = $music ->      getElementsByTagName ( 'name' ); foreach ( $names as $name ) {    print $name -> firstChild -> nodeValue ; } The Rolling Stones Aimee Mann
  • 7. SAX
    • PHP's original XML extension.
    • Streaming (or event-based) parser
    • Uses less memory than DOM, but frequently at the expense of more complex PHP code.
    • Used to use expat. Now uses libxml2
  • 8. SimpleXML
    • A new PHP 5 only extension.
    • Excels at parsing RSS files, REST results, and configuration data.
    • If you know the document's format ahead of time, SimpleXML is the way to go.
    • Only supports elements, text nodes, and attributes.
    • Tree-based API
  • 9. SimpleXML Example Code $x = simplexml_load_string ( $xml ); $artists = $x -> artist ; foreach( $artists as $artist ) {      print &quot;$artist->name &quot; ; } The Rolling Stones Aimee Mann
  • 10. XPath
    • Query XML documents like you're using regular expressions to find the subset of information that you need and eliminate the unnecessary portions.
    • Highly useful and undervalued piece of XML.
    • Usable with DOM and SimpleXML
  • 11. XPath Example Code
    • $xpath = new domXPath ( $music );
    • $albums = $xpath -> query (
    • &quot;/music/artist[name =
    • 'Rolling Stones']/albums/name&quot; );
    • foreach ( $albums as $a )
    • print $a -> firstChild -> nodeValue ;
    • }
    • Exile On Main Street
  • 12. XSLT
    • A way to take XML documents and transform them into HTML or another output format.
    • Defines templates using XML-based stylesheets.
    • Easily shared among different applications, but has a quirky syntax.
    • Uses libxslt library instead of Sablotron.
  • 13. XSLT Example Code
    • $xslt = new xsltProcessor ;
    • $xsl = domDocument :: load ( 'music.xsl' );
    • $xslt -> importStylesheet ( $xsl );
    • $xml = domDocument :: load ( 'music.xml' );
    • print $xslt -> transformToXML ( $xml );
  • 14. Web Services
    • SOAP
      • PEAR::SOAP
      • soap Extension (Written in C)
    • REST
      • SimpleXML
    • XML-RPC
      • Still there…
  • 15. Resources
    • DOM, XSLT, XPath
      • PHP 5 Meets XML and the DOM PHP Magazine: www.php-mag.net
    • SimpleXML
      • Using PHP 5's SimpleXML O’Reilly Network: www.onlamp.com/php
  • 16. Did I mention I wrote a book?

×