/** * @param SimpleXMLElement $xml * @return Metadata * @throws InvalidGPXException */ public static function fromXML(SimpleXMLElement $xml) { $metadata = new Metadata(); if (!empty($xml->name)) { $metadata->setName((string) $xml->name[0]); } if (!empty($xml->desc)) { $metadata->setDescription((string) $xml->desc[0]); } if (!empty($xml->author)) { $metadata->setAuthor(Person::fromXML($xml->author[0])); } if (!empty($xml->copyright)) { $metadata->setCopyright(Copyright::fromXML($xml->copyright[0])); } if (!empty($xml->link)) { $links = []; foreach ($xml->link as $link) { array_push($links, Link::fromXML($link)); } $metadata->setLinks($links); } if (!empty($xml->time)) { $metadata->setTime(strtotime((string) $xml->time[0])); } if (!empty($xml->keywords)) { $metadata->setKeywords((string) $xml->keywords[0]); } if (!empty($xml->bounds)) { $metadata->setBounds(Bounds::fromXML($xml->bounds0[0])); } if (!empty($xml->extensions)) { $metadata->setExtensions(Extensions::fromXML($xml->extensions[0])); } return $metadata; }