/** * @param SimpleXMLElement $xml * @return Route * @throws InvalidGPXException */ public static function fromXML(SimpleXMLElement $xml) { $route = new Route(); if (!empty($xml->name)) { $route->setName((string) $xml->name[0]); } if (!empty($xml->cmt)) { $route->setComment((string) $xml->cmt[0]); } if (!empty($xml->desc)) { $route->setDescription((string) $xml->desc[0]); } if (!empty($xml->src)) { $route->setSource((string) $xml->src[0]); } if (!empty($xml->link)) { $links = []; foreach ($xml->link as $link) { array_push($links, Link::fromXML($link)); } $route->setLinks($links); } if (!empty($xml->number)) { $route->setNumber((int) $xml->number[0]); } if (!empty($xml->type)) { $route->setType((string) $xml->type[0]); } if (!empty($xml->extensions)) { $route->setExtensions(Extensions::fromXML($xml->extensions[0])); } if (!empty($xml->rtept)) { $routePoints = []; foreach ($xml->rtept as $routePoint) { array_push($routePoints, Waypoint::fromXML($routePoint)); } $route->setRoutePoints($routePoints); } return $route; }