diff options
| author | Christian Stocker <chregu@php.net> | 2003-10-26 19:15:52 +0000 |
|---|---|---|
| committer | Christian Stocker <chregu@php.net> | 2003-10-26 19:15:52 +0000 |
| commit | 4e5d4006fdf1998afc010df10459101960b3d15e (patch) | |
| tree | 99a93b040e62b96055753847956e6e1adbaa2892 /ext/simplexml/examples | |
| parent | 1e46a26f0fb8a636b27b2e8b31db92f621e0cde0 (diff) | |
| download | php-git-4e5d4006fdf1998afc010df10459101960b3d15e.tar.gz | |
- added interop between DOM and SimpleXML example
- added xpath example
Diffstat (limited to 'ext/simplexml/examples')
| -rw-r--r-- | ext/simplexml/examples/interop.php | 27 | ||||
| -rw-r--r-- | ext/simplexml/examples/xpath.php | 9 |
2 files changed, 36 insertions, 0 deletions
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 @@ +<?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"; +} + + +?> 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 @@ +<?php +$books = simplexml_load_file('book.xml'); + +$xpath_result = $books->xsearch("/books/book/title"); +foreach($xpath_result as $entry ) { + print "$entry \n"; +} + +?> |
