cvs: php-src /ext/simplexml/examples interop.php xpath.php

From: Date: Sun, 26 Oct 2003 19:15:53 +0000
Subject: cvs: php-src /ext/simplexml/examples interop.php xpath.php
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-24288@lists.php.net to get a copy of this message
chregu Sun Oct 26 14:15:53 2003 EDT Added files: /php-src/ext/simplexml/examples interop.php xpath.php Log: - added interop between DOM and SimpleXML example - added xpath example Index: php-src/ext/simplexml/examples/interop.php +++ php-src/ext/simplexml/examples/interop.php <?php $dom = new domDocument; $dom->load("book.xml"); if(!$dom) { echo "Error while parsing the document\n"; exit; } print "As SimpleXML\n"; $s = simplexml_import_dom($dom); $books = $s->book; foreach ($books as $book) { echo "{$book->title} was written by {$book->author}\n"; } print "As DOM \n"; $dom = dom_import_simplexml($s); $books = $dom->getElementsByTagName("book"); foreach ($books as $book) { $title = $book->getElementsByTagName("title"); $author = $book->getElementsByTagName("author"); echo $title[0]->firstChild->data . " was written by ". $author[0]->firstChild->data . "\n"; } ?> Index: php-src/ext/simplexml/examples/xpath.php +++ php-src/ext/simplexml/examples/xpath.php <?php $books = simplexml_load_file('book.xml'); $xpath_result = $books->xsearch("/books/book/title"); foreach($xpath_result as $entry ) { print "$entry \n"; } ?>

« previous php.cvs (#24288) next »