Output keys and elements of a SimpleXMLElement object in PHP

Description

The following code shows how to output keys and elements of a SimpleXMLElement object.

Example


/*from w w w .  j a v a 2 s. c om*/
<?php
    $xml=simplexml_load_file("test.xml");
    print_r($xml);
?>

The following code is for test.xml.


//w  w w. j a v a  2 s.c  om
    <?xml version="1.0" encoding="UTF-8"?>
    <note>
    <to>Work</to>
    <from>Home</from>
    <heading>Reminder</heading>
    <body>This is a message.</body>
    </note>

The code above generates the following result.





















Home »
  PHP Tutorial »
    XML »




DOM
SimpleXML
SimpleXMLElement
XML Parser