PHP simplexml_import_dom() Function

In this chapter you will learn:

  1. Description for PHP simplexml_import_dom() Function
  2. Syntax for PHP simplexml_import_dom() Function
  3. Parameter for PHP simplexml_import_dom() Function
  4. Return for PHP simplexml_import_dom() Function
  5. Example - Take a node of a DOM document and make it into a SimpleXML node

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//from   ja va2  s.c  om
$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   j  a  v  a2 s. c o  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;
?>

Next chapter...

What you will learn in the next chapter:

  1. Description for PHP simplexml_load_file() Function
  2. Syntax for PHP simplexml_load_file() Function
  3. Parameter for PHP simplexml_load_file() Function
  4. Return for PHP simplexml_load_file() Function
  5. Example - Convert an XML file into a SimpleXMLElement object, then output keys and elements of the object
  6. Example - Output the data from each element in the XML file
  7. Example - Output the element's name and data for each child node in the XML file
Home » PHP Tutorial » PHP SimpleXML Functions
PHP SimpleXMLElement Create
PHP addAttribute() Function
PHP addChild() Function
PHP asXML() Function
PHP attributes() Function
PHP children() Function
PHP SimpleXML count() Function
PHP getDocNamespaces() Function
PHP getName() Function
PHP getNamespaces() Function
PHP registerXPathNamespace() Function
PHP simplexml_import_dom() Function
PHP simplexml_load_file() Function
PHP simplexml_load_string() Function
PHP xpath() Function