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";
}

?>

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to