reset(); $this->_file = $file; if(!file_exists($this->_file)) throw new \Exception('File ' . $this->_file . ' not found'); $this->_domdoc = new \DOMDocument(); $this->_domdoc->load($this->_file); } /* (non-PHPdoc) * @see Nirph_DataImport_Interface::getRecord() */ public function getRecord () { $record = array(); /* @var $this->_elements DOMNodeList */ if($this->_currentItem >= $this->_elements->length) return false; /* @var $node DOMNodeList */ $nodes = $this->_elements->item($this->_currentItem)->childNodes; for($i = 1;$i < $nodes->length; $i+=2) { // The first item is a #text if(is_string($nodes->item($i)->nodeValue)) // Only get nodes that has a text value $record[$nodes->item($i)->nodeName] = $nodes->item($i)->nodeValue; } $this->_currentItem++; return $record; } /* (non-PHPdoc) * @see Nirph_DataImport_Interface::reset() */ public function reset () { $this->_currentItem = 0; } /* (non-PHPdoc) * @see Nirph_DataImport_Interface::setField() */ public function setField ($fieldNr, FieldInterface $class) { // TODO Auto-generated method stub } public function setRowElementXPath($xPath) { // TODO: Validation $this->_rowXPath = $xPath; $xpath = new \DOMXpath($this->_domdoc); /* @var $this->_elements DOMNodeList */ $this->_elements = $xpath->query($this->_rowXPath); if($this->_elements === false) throw new \Exception("Invalid xpath"); } }