From 8a4d57e7a1c51349a44daa718f5e4b2cf909f1ad Mon Sep 17 00:00:00 2001 From: Ken Date: Thu, 29 Jan 2004 01:23:00 +0000 Subject: [PATCH] Added DOM examples. git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@150076 c90b9560-bf6c-de11-be94-00142212c4b1 --- .../functions/simplexml-load-dom.xml | 28 ++++++++++++--- reference/simplexml/reference.xml | 34 ++++++++++++++++++- 2 files changed, 57 insertions(+), 5 deletions(-) diff --git a/reference/simplexml/functions/simplexml-load-dom.xml b/reference/simplexml/functions/simplexml-load-dom.xml index 6bf0a878c3..329f64d8ee 100644 --- a/reference/simplexml/functions/simplexml-load-dom.xml +++ b/reference/simplexml/functions/simplexml-load-dom.xml @@ -1,11 +1,9 @@ - + simplexml_load_dom - Get a simplexml_element object from a DOM node. @@ -24,7 +22,29 @@ it returns &false;. - &warn.undocumented.func; + + Import DOM + +loadXML('blah'); +if(!$dom) { + echo 'Error while parsing the document'; + exit; +} + +$s = simplexml_import_dom($dom); + +echo $s->book[0]->title; +?> +]]> + + + This code should output: + + blah + diff --git a/reference/simplexml/reference.xml b/reference/simplexml/reference.xml index 8bf70aafd4..6a25150497 100644 --- a/reference/simplexml/reference.xml +++ b/reference/simplexml/reference.xml @@ -1,5 +1,5 @@ - + SimpleXML functions SimpleXML @@ -192,6 +192,38 @@ echo $xml->asXML(); + + + DOM Interoperability + + PHP has a mechanism to convert XML nodes between SimpleXML + and DOM formats. This example shows how one might change + a DOM element to SimpleXML. + + + + This will only work with DOM in PHP 5, but SimpleXML wasn't + available before that version, so you should be fine. + + + +loadXML('blah'); +if(!$dom) { + echo 'Error while parsing the document'; + exit; +} + +$s = simplexml_import_dom($dom); + +echo $s->book[0]->title; +?> +]]> + + +