Using a third party API, I am attempting to parse the output that I get. I'm being returned a StdClass object that contains some XML but not properly formatted XML as follows:
stdClass Object
(
[any] => <data xmlns="" count="2" count_available="3366"><row id="1"><description1>testing 1</description1></row><row id="2"><description1>testing 2</description1></row></data>
)
What is the best and easiest way to parse this so i can retrieve fields such as 'description1' ?
You need to extract the content from the object and then you can use SimpleXML to access the values. SimpleXML uses object notation to access the XML elements, so this loops over the <row>
elements in the document and for each one outputs the <description1>
element (casting to a string otherwise you end up with a SimpleXMLElement object)...
$xml = simplexml_load_string($object->any);
foreach ($xml->row as $row){
echo (string)$row->description1.PHP_EOL;
}