/** * Map the child elements of the current element, to the properties of the GpxElement object * * @param \SimpleXMLElement $element The element that we want to reformat as an object * @return \GpxReader\GpxElement $gpxElement The object that we want to set the properties for **/ protected function mapChildElements($element, GpxElement $gpxElement) { switch ($element->getName()) { case 'ele': $gpxElement->elevation = (double) $element->__toString(); break; case 'time': $gpxElement->timestamp = new \DateTime($element->__toString()); break; } }
/** * Recusive function for parseProducts * * @param SimpleXMLElement $c The SimpleXMLElement object to parse * @param int $depth Not used * @param array $prod Custom associative array to store the parsed children */ public function childProdParse($c, $depth, $prod) { $name = $c->getName(); $value = $c->__toString(); if ($name == "Custom") { $prod['cust_' . $c['id']->__toString()] = $value; } elseif (isset($prod[$name])) { if ($c->children()->count() || $c->attributes()) { $value = ['v' => $value]; } if ($c->attributes()) { $value['_attr'] = []; foreach ($c->attributes() as $a => $b) { $value['_attr'][$a] = $b->__toString(); } } if ($c->children()->count()) { $value['_children'] = []; foreach ($c->children() as $cc) { $value['_children'] = $this->childProdParse($cc, $depth + 1, $value['_children']); } } if (is_array($prod[$name]) && !isset($prod[$name]['v'])) { $prod[$name][] = $value; } else { $prod[$name] = [$prod[$name], $value]; } } else { if ($c->children()->count() || $c->attributes()) { $prod[$name] = ['v' => $value]; } else { // if($name == "Image"){ // $prod[$name] = [[$value]]; // }else $prod[$name] = $value; } if ($c->attributes()) { $prod[$name]['_attr'] = []; foreach ($c->attributes() as $a => $b) { $prod[$name]['_attr'][$a] = $b->__toString(); } } if ($c->children()->count()) { $prod[$name]['_children'] = []; foreach ($c->children() as $cc) { $prod[$name]['_children'] = $this->childProdParse($cc, $depth + 1, $prod[$name]['_children']); } } if ($name == "Image") { $prod[$name] = [$prod[$name]]; } } return $prod; }
public function handle(ResponseCore $response) { $xml = new SimpleXMLElement($response->body); $location = $xml->__toString(); return $location; }