note 113423 deleted from simplexml.examples-basic by cmb
| From: | cmb@php.net | Date: | Wed, 08 Jun 2022 16:28:52 +0000 |
| Subject: | note 113423 deleted from simplexml.examples-basic by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-218567@lists.php.net to get a copy of this message | ||
Note Submitter: eng dot emad_2010 at yahoo dot com
----
Example # 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 .
The simplexml_import_dom() function returns a SimpleXMLElement object from a DOM node.
DOM object
<?php
//create DOM document $dom that contain XML
$dom = new DOMDocument;
$dom->loadXML('<books><book><title>blah</title></book></books>');
if (!$dom) {
echo 'Error while parsing the document';
exit;
}
//convert DOM document $dom to object $books
$books = simplexml_import_dom($dom);
//access object $books
echo $books->book[0]->title;
?>