2 namespace Utility\Import;
4 class Xml implements ImportInterface
7 private $_specialFields = array();
11 private $_currentItem;
13 public function __construct($file)
17 if(!file_exists($this->_file))
18 throw new \Exception('File ' . $this->_file . ' not found');
19 $this->_domdoc = new \DOMDocument();
20 $this->_domdoc->load($this->_file);
24 * @see Nirph_DataImport_Interface::getRecord()
26 public function getRecord ()
29 /* @var $this->_elements DOMNodeList */
30 if($this->_currentItem >= $this->_elements->length)
32 /* @var $node DOMNodeList */
33 $nodes = $this->_elements->item($this->_currentItem)->childNodes;
34 for($i = 1;$i < $nodes->length; $i+=2) { // The first item is a #text
35 if(is_string($nodes->item($i)->nodeValue)) // Only get nodes that has a text value
36 $record[$nodes->item($i)->nodeName] = $nodes->item($i)->nodeValue;
38 $this->_currentItem++;
43 * @see Nirph_DataImport_Interface::reset()
45 public function reset ()
47 $this->_currentItem = 0;
51 * @see Nirph_DataImport_Interface::setField()
53 public function setField ($fieldNr, FieldInterface $class)
55 // TODO Auto-generated method stub
58 public function setRowElementXPath($xPath)
61 $this->_rowXPath = $xPath;
62 $xpath = new \DOMXpath($this->_domdoc);
63 /* @var $this->_elements DOMNodeList */
64 $this->_elements = $xpath->query($this->_rowXPath);
65 if($this->_elements === false)
66 throw new \Exception("Invalid xpath");