NYCPHP Meetup

NYPHP.org

[nycphp-talk] libxml in PHP 5

Sterling Hughes sterling at bumblebury.com
Wed Aug 13 06:32:41 EDT 2003


Am Die, 2003-08-12 um 14.46 schrieb Adam Maccabee Trachtenberg:
> On Mon, 11 Aug 2003, Analysis & Solutions wrote:
> 
> > I was thinking that the new XML parser would necessitate scripts use
> > different function calls.  Or will the main functions and behavior remain
> > the same, but only the library be changed?
> 
> The plan is to make the libxml switch seamless and not require any
> changes in your XML code. 

Yes, and kinda.  The SAX extension (ext/xml) will remain the same.

Code that uses the DOM extension will need to be rewritten.  The DOM
extension has always been experimental, and never really worked.  Now it
will, and it will be 100% DOM 2 (and mostly DOM 3) compliant.  The API
for the XSLT extension is also completely changed.

> 
> > If the functions will indeed be different, is there some place to find
> > docs about these new procedures?  They don't have to be great, just give
> > me an idea of how to start hacking something simple.
> 
> PHP 5 will also have the SimpleXML extension. I believe the C code in
> the CVS is also the documentation. (Source code: The ultimate documentation.)

book.xml
<books>
 <book asin="84343483538">
  <title>Winnie the Pooh</title>
  <author>Arthur Milne</author>
  <description>A true classic</description>
 </book>
 <book asin="838488287773">
  <title>The Grapes of Wrath</title>
  <author>John Steinbeck</author>
  <description>Not bad...</description>
  <note>Its wierd, but not many europeans know john steinbeck, they all 
  know arthur milne.</note>
 </book>
</books>

book.php
<?php
$books = simplexml_load_file('book.xml');
foreach ($books->book as $book) {
?>
  <a href="http://www.amazon.com/<?=$book->asin?>"><?=$book->title?></a>
  <br/>
  <?=$book->author?>
  <br/><br/>
  <?=$book->description?>
  <br/>
  <? if (!empty($book->note)) { ?>
    <b>Note:</b> <?=$book->note?>
  <? } ?>
<?php
}
?>

Yep, that's it.  SimpleXML is actually quite powerful.  For example, I
wrote a full WSDL parser using simplexml.  It supports Xpath, Schema and
the full XML infoset.

-Sterling


-- 
"Backups are for wimps. Real men upload their data to an FTP site and
have everyone else mirror it." 
    - Linus Torvalds



More information about the talk mailing list