I am receiving an XML response based on a request I place to a server and it does in fact return a valid set of results that I can dump on the screen using print_r()
Result set looks like this(edit: this is the exact structure of the file):
<root>
<main_node1>
<value1>one</value1>
<value2>two</value2>
</main_node1>
<main_node2>
<anothervalue>whatever</anothervalue>
</main_node2>
<recordset>
<record>
<value1>one</value1>
<value2>two</value2>
</reocrd>
<record>
<value1>one</value1>
<value2>two</value2>
</reocrd>
<record>
<value1>one</value1>
<value2>two</value2>
</reocrd>
</recordset>
</root>
when I use the line:
$xml = simplexml_load_string($xmlRequest);
$records = $xml->recordset->record;
I can walk through the $records array with a foreach loop without any problems however, when I try to access a specific record within the recordset using an index such as
$record = $xml->recordset->record[$index];
I am getting a NULL valeu back. I also tried to cast the result into an (array) with no success so far.
Every document I looked at regarding simpleXML says that it is possible to access the XML node by index, can someone please tell me what I might be doing wrong here?
Edit: so recordset is not the root of the document yet I am able to use the $xml->recordset->record notation to load a list of records in to my $records variable and print it out using the foreach loop.
I resolved my issue by using
notation and I am now able to access any record by their index.
Thank you for trying, I appreciate your efforts.