PHP XML simplexml_import_dom() Example

PHP XML simplexml_import_dom() Example

Posted in : PHP Posted on : January 21, 2011 at 6:39 PM Comments : [ 0 ]

This section contains the detail about the simplexml_import_dom() Example of xml in PHP.

PHP XML simplexml_import_dom() Example:

When you need to convert a Dom node in to a SimpleXMLElement object then use simplexml_import_dom() function. It return boolean value(true for success or false for failure). It takes two arguments "data" and "class", data is specify the DOM node to use and class is optional specify the class of the new object.  


simplexml_import_dom(data, class)


$dom_object = new DOMDocument;
if (!$dom_object) {
echo 'Error';
$simple_import_dom = simplexml_import_dom($dom_object);
echo $simple_import_dom->child1;

The root.xml file code is:

<?xml version="1.0"?>
<child1 child1_attribute="child1 attribute value">clid1 text</child1>
<child2 >clid2 text</child2>

After running this example the browser output is:


clid1 text

Download Example code

Go to Topic «PreviousHomeNext»

Your Comment:

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image

Tutorial Topics