function testFromXml() { $xml = "<place><point>38.2638886 -106.126131</point><elev>5.343</elev><floor>4</floor><featuretypetag>blah</featuretypetag><featurename>Chloride Mine</featurename><relationshiptag>nearby</relationshiptag></place>"; $place = Services_Gnip_Place::fromXML($xml); $this->assertEquals("38.2638886 -106.126131", $place->point); $this->assertEquals(5.343, $place->elev); $this->assertEquals(4, $place->floor); $this->assertEquals("blah", $place->featuretypetag); $this->assertEquals("Chloride Mine", $place->featurename); $this->assertEquals("nearby", $place->relationshiptag); }
/** * Converts XML formatted activity to Services_Gnip_Activity object. * * @param string $xml XML data * @return object Services_Gnip_Activity */ public static function fromXML($xml) { $xml_element = new SimpleXMLElement($xml); $found_at = strval($xml_element->at); $found_action = strval($xml_element->action); $found_activityID = strval($xml_element->activityID); $found_URL = strval($xml_element->URL); $found_source = Services_Gnip_Activity::getUnboundXML($xml_element->xpath('source'), 'source'); $found_keyword = Services_Gnip_Activity::getUnboundXML($xml_element->xpath('keyword'), 'keyword'); $place_result = $xml_element->xpath('place'); if (array_key_exists(0, $place_result)) { foreach ($place_result as $k => $v) { $found_place[] = Services_Gnip_Place::fromXML($v->asXML()); } } else { $found_place = null; } $found_actor = Services_Gnip_Activity::getUnboundXML($xml_element->xpath('actor'), 'actor', array('metaURL', 'uid')); $found_destinationURL = Services_Gnip_Activity::getUnboundXML($xml_element->xpath('destinationURL'), 'destinationURL', array('metaURL')); $found_tag = Services_Gnip_Activity::getUnboundXML($xml_element->xpath('tag'), 'tag', array('metaURL')); $found_to = Services_Gnip_Activity::getUnboundXML($xml_element->xpath('to'), 'to', array('metaURL')); $found_regardingURL = Services_Gnip_Activity::getUnboundXML($xml_element->xpath('regardingURL'), 'regardingURL', array('metaURL')); $payload_result = $xml_element->xpath('payload'); if (array_key_exists(0, $payload_result)) { foreach ($payload_result as $k => $v) { $found_payload = Services_Gnip_Payload::fromXML($v->asXML()); } } else { $found_payload = null; } return new Services_Gnip_Activity(new DateTime($found_at), $found_action, $found_activityID, $found_URL, $found_source, $found_keyword, $found_place, $found_actor, $found_destinationURL, $found_tag, $found_to, $found_regardingURL, $found_payload); }