Пример #1
0
 /**
  * Create objects and fill objects tables from a OSM xml document (string).
  *
  * @param string $xmlStr
  */
 public function createObjectsfromXml($xmlStr)
 {
     OSM_ZLog::debug(__METHOD__, $xmlStr);
     if (empty($xmlStr)) {
         throw new OSM_Exception('Xml string could not be empty');
     }
     $xmlObj = simplexml_load_string($xmlStr);
     if ($xmlObj == null) {
         _err('Failed to parse xml: [' . print_r($xmlStr, true) . ']');
         throw new OSM_Exception('Failed to parse xml');
     }
     $this->_loadedXml[] = $xmlStr;
     // Take all others object
     $objects = $xmlObj->xpath('/osm/*');
     foreach ($objects as $obj) {
         OSM_ZLog::debug(__METHOD__, 'subobjects type=', $obj->getName());
         switch ($obj->getName()) {
             case self::OBJTYPE_RELATION:
                 $r = OSM_Objects_Relation::fromXmlObj($obj);
                 $this->_relations[$r->getId()] = $r;
                 break;
             case self::OBJTYPE_WAY:
                 $w = OSM_Objects_Way::fromXmlObj($obj);
                 $this->_ways[$w->getId()] = $w;
                 break;
             case self::OBJTYPE_NODE:
                 $n = OSM_Objects_Node::fromXmlObj($obj);
                 $this->_nodes[$n->getId()] = $n;
                 break;
             case 'note':
             case 'meta':
             case 'remark':
                 break;
             default:
                 throw new OSM_Exception('Object "' . $obj->getName() . '" is not supported');
         }
     }
 }