/** * @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; }