From: Christian Stocker Date: Sun, 26 Oct 2003 19:15:52 +0000 (+0000) Subject: - added interop between DOM and SimpleXML example X-Git-Tag: RELEASE_2_0_0RC1~69 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4e5d4006fdf1998afc010df10459101960b3d15e;p=php - added interop between DOM and SimpleXML example - added xpath example --- diff --git a/ext/simplexml/examples/interop.php b/ext/simplexml/examples/interop.php new file mode 100644 index 0000000000..9e38ec1110 --- /dev/null +++ b/ext/simplexml/examples/interop.php @@ -0,0 +1,27 @@ +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"; +} + + +?> diff --git a/ext/simplexml/examples/xpath.php b/ext/simplexml/examples/xpath.php new file mode 100644 index 0000000000..23253d7b74 --- /dev/null +++ b/ext/simplexml/examples/xpath.php @@ -0,0 +1,9 @@ +xsearch("/books/book/title"); +foreach($xpath_result as $entry ) { + print "$entry \n"; +} + +?>