From every example I’ve seen, this works properly, but can’t figure out why I cannot get it work! Driving me nuts:
Sample XML
<?xml version="1.0"?>
<database>
<tables>
<table name="#_users">
<columns>
<column type="INT(8)" name="id">
<null>0</null>
<default></default>
<primary>1</primary>
<extra>AUTO_INCREMENT</extra>
</column>
<column type="VARCHAR(100)" name="username">
<null>0</null>
<index>1</index>
</column>
</columns>
<desc>The users table</desc>
</table>
</tables>
</database>
Sample code:
<?php
$xml = simplexml_load_file( $file );
if ( ! empty( $xml ) && $xml instanceof SimpleXMLElement ) {
foreach ( $xml->tables as $table ) {
print_r ( $table ); // Yep, XML is there!
echo $table['name']; // Outputs nothing! WHY?
}
}
?>
The xml loads as a SimpleXMLElement, I can see all the attributes in there, why the hell can’t I access them? What am I doing wrong?