array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'pt_BR', ), 'this' => array ( 0 => 'function.dom-import-simplexml.php', 1 => 'dom_import_simplexml', ), 'up' => array ( 0 => 'ref.dom.php', 1 => 'DOM Funções', ), 'prev' => array ( 0 => 'ref.dom.php', 1 => 'DOM Funções', ), 'next' => array ( 0 => 'book.libxml.php', 1 => 'libxml', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'pt_BR', 'path' => 'reference/dom/functions/dom-import-simplexml.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 5, PHP 7, PHP 8)
dom_import_simplexml — Obtém um objeto DOMElement a partir de um objeto SimpleXMLElement
Esta função pega o nó node
da classe
SimpleXML e o transforma em um
nó DOMElement. Este novo objeto pode então ser usado
como um nó nativo DOMElement.
O nó DOMElement adicionado.
Versão | Descrição |
---|---|
8.0.0 |
Esta função não retorna mais null em caso de falha.
|
Exemplo #1 Importar SimpleXML para DOM com dom_import_simplexml()
<?php
$sxe = simplexml_load_string('<books><book><title>blah</title></book></books>');
if ($sxe === false) {
echo 'Error while parsing the document';
exit;
}
$dom_sxe = dom_import_simplexml($sxe);
if (!$dom_sxe) {
echo 'Error while converting XML';
exit;
}
$dom = new DOMDocument('1.0');
$dom_sxe = $dom->importNode($dom_sxe, true);
$dom_sxe = $dom->appendChild($dom_sxe);
echo $dom->saveXML();
?>