I can find quite a bit about this topic but have not been able to get anything to work to get my XML into an array. I have the following:

$string = <<<XML
<?xml version="1.0" encoding="ISO-8859-1"?>
<rows>
<row id="9"> <cell></cell><cell>1</cell><cell>239.9470</cell><cell>0.8378 </cell></row>
<row id="10"> <cell></cell><cell>2</cell><cell>248.4749</cell><cell>0.8756 </cell></row>
<row id="11"> <cell></cell><cell>3</cell><cell>297.9717</cell><cell>0.9034 </cell></row>
<row id="12"> <cell></cell><cell>4</cell><cell>232.9227</cell><cell>0.9160 </cell></row>
<row id="13"> <cell></cell><cell>5</cell><cell>267.5802</cell><cell>0.8995 </cell></row>
</rows>
XML;

$xml = simplexml_load_string($string);

How do I get the simpleXML object into an array?

    Perhaps the first way to answer your question would be to ask, "If you already have the XML in a SimpleXML object, why do you also want to have it in an array?" Depending on the answer to this, you may find that there is no reason, as you should be able to do pretty much anything with that object that you could do with an array.

      That is a very good question, one which I did not consider. I have an XML string which I am going to load into an Oracle database.

        Here's a simplistic example (no error-checking, sql-injection prevention, etc.):

        <pre><?php
        // define $string, then...
        $xml = simplexml_load_string($string);
        foreach($xml->row as $row)
        {
           $query = "INSERT INTO tablename VALUES('" . $row['id'] . "',";
           foreach($row->cell as $value)
           {
              $query .= "'".$value."',";
           }
           $query = rtrim($query, ',');
           echo $query . "\n";
        }
        ?></pre>
        
          Write a Reply...