public static XMLToArray ( SimpleXMLElement $sxml ) | ||
$sxml | SimpleXMLElement |
public function parseXML() { $sxml = new SimpleXMLElement($this->response_body); // For lack of a better way to find the elements returned (every time) // XML has an array 2 levels deep due to its non-unique key nature. /** @var SimpleXMLElement $root_child */ foreach ($sxml as $child_index => $root_child) { switch ($child_index) { case 'ErrorNumber': $this->root_error['code'] = (string) $root_child; break; case 'Type': $this->root_error['type'] = (string) $root_child; break; case 'Message': $this->root_error['message'] = (string) $root_child; break; case 'Payslip': case 'PayItems': // some xero endpoints are 1D so we can parse them straight away $this->elements[] = Helpers::XMLToArray($root_child); break; default: //Happy to make the assumption that there will only be one //root node with > than 2D children. foreach ($root_child->children() as $element_index => $element) { $this->elements[] = Helpers::XMLToArray($element); } } } }