/** * @param SimpleXMLElement $xml * @return TrackSegment * @throws InvalidGPXException */ public static function fromXML(SimpleXMLElement $xml) { $trackSegment = new TrackSegment(); if (!empty($xml->trkpt)) { $trackPoints = []; foreach ($xml->trkpt as $trackPoint) { array_push($trackPoints, Waypoint::fromXML($trackPoint)); } $trackSegment->setTrackPoints($trackPoints); } if (!empty($xml->extensions)) { $trackSegment->setExtensions(Extensions::fromXML($xml->extensions[0])); } return $trackSegment; }
/** * @param SimpleXMLElement $xml * @return Track */ public static function fromXML(SimpleXMLElement $xml) { $track = new Track(); if (!empty($xml->name)) { $track->setName((string) $xml->name[0]); } if (!empty($xml->cmt)) { $track->setComment((string) $xml->cmt[0]); } if (!empty($xml->desc)) { $track->setDescription((string) $xml->desc[0]); } if (!empty($xml->src)) { $track->setSource((string) $xml->src[0]); } if (!empty($xml->link)) { $links = []; foreach ($xml->link as $link) { array_push($links, Link::fromXML($link)); } $track->setLinks($links); } if (!empty($xml->number)) { $track->setNumber((int) $xml->number[0]); } if (!empty($xml->type)) { $track->setType((string) $xml->type[0]); } if (!empty($xml->extensions)) { $track->setExtensions(Extensions::fromXML($xml->extensions[0])); } if (!empty($xml->trkseg)) { $trackSegments = []; foreach ($xml->trkseg as $trackSegment) { array_push($trackSegments, TrackSegment::fromXML($trackSegment)); } $track->setTrackSegments($trackSegments); } return $track; }