namibia
df0489e1eeeeab5a9bd44e1d84fce49924fe1bac
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
<?php namespace Utility\Import; class Xml implements ImportInterface { private $_file; private $_specialFields = array(); private $_domdoc; private $_rowXPath; private $_elements; private $_currentItem; public function __construct($file) { $this->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"); } } |
Commits for namibiamodule/Utility/src/Utility/Import/Xml.php
Revision | Author | Commited | Message |
---|---|---|---|
df0489 ... | Mark | Fri 14 Oct, 2016 10:01:00 +0000 | initial commit |