Overview
KB
Technical FAQ
PHP Manual
CSS2 Manual
HTML Manual
JS Guide
JS Reference
PhpDock Manual
Nu-Coder Manual
PhpExpress Manual
PHP Joomla
Development
Learn PHP
 
<dom_import_simplexmllibxml>
^DOM FunctionsLast updated: Mon, 26 Oct 2026

Dom\import_simplexml

(PHP 8 >= 8.4.0)

Dom\import_simplexml — Gets a Dom\Attr or Dom\Element object from a SimpleXMLElement object

Description

function Dom\import_simplexml(object $node): Dom\Attr|Dom\Element

This function takes the given attribute or element node (a SimpleXMLElement instance) and creates a Dom\Attr or Dom\Element node, respectively. The new Dom\Node refers to the same underlying XML node as the SimpleXMLElement.

Parameters

node

The attribute or element node to import (a SimpleXMLElement instance).

Return Values

The Dom\Attr or Dom\Element.

Examples

Example #1 Import SimpleXML into DOM and modify SimpleXML through DOM

Error handling omitted for brevity.

<?php

$sxe = simplexml_load_string('<books><book><title>blah</title></book></books>');
$elt = Dom\import_simplexml($sxe);
$elt->setAttribute("foo", "bar");
echo $sxe->asXML();

?>

The above example will output:

<?xml version="1.0"?>
<books foo="bar"><book><title>blah</title></book></books>

See Also


<dom_import_simplexmllibxml>
^DOM FunctionsLast updated: Mon, 26 Oct 2026