Latest web development tutorials

PHP simplexml_import_dom () function

PHP SimpleXML Reference Manual PHP SimpleXML Reference Manual

Examples

Get DOM document node and converted into a SimpleXML node:

<?php
$dom=new domDocument;
$dom->loadXML("<note><to>Tove</to><from>Jani</from></note>");
$x=simplexml_import_dom($dom);
echo $x->from;
?>

Running instance »

Definition and Usage

simplexml_import_dom () function returns SimpleXMLElement object from a DOM node.


grammar

simplexml_import_dom( node,classname );

参数 描述
node 必需。规定 DOM 元素节点。
classname 可选。规定新对象的 class。

technical details

return value: If successful SimpleXMLElement object, if fails returns FALSE.
PHP version: 5+


More examples

Example 1

Output DOM document titled second book node:

<?php
$dom=new domDocument;
$dom->loadXML("<books><book><title>Title1</title></book><book><title>Title2</title></book></books>");
$x=simplexml_import_dom($dom);
echo $x->book[1]->title;
?>

Running instance »


PHP SimpleXML Reference Manual PHP SimpleXML Reference Manual