PHP simplexml_import_dom() Function

Description

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

Syntax

PHP simplexml_import_dom() Function has the following syntax.

simplexml_import_dom(node,classname);

Parameter

ParameterIs RequiredDescription
nodeRequired.A DOM element node
classnameOptional.Class of the new object

Return

Returns a SimpleXMLElement object on success. FALSE on failure.

Example

Take a node of a DOM document and make it into a SimpleXML node:


<?php/*  w w  w.  j  a  v a 2  s.  com*/
$dom=new domDocument;
$dom->loadXML("<book><name>PHP</name><name>Java</name></book>");
$x=simplexml_import_dom($dom);
echo $x->from;
?>

Output the title of the second book node in the DOM document:


<?php//from  ww  w  .j a v  a 2 s  . co  m
$dom=new domDocument;
$dom->loadXML("<books><book><title>Java</title></book><book><title>PHP</title></book></books>");
$x=simplexml_import_dom($dom);
echo $x->book[1]->title;
?>




















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions