public function analyse(FileInterface $file, ParseOptions $options) { $this->analysis_last_path = ""; $this->analysis_path = ""; $this->analysis_depth = 0; $this->analysis_length = array(); $this->analysis_records = array(); $parser = @xml_parser_create(); if (!$parser) { throw new PHPXmlParserError(); } xml_set_element_handler($parser, array($this, 'analysisStartTag'), array($this, 'analysisEndTag')); xml_set_character_data_handler($parser, array($this, "analysisCDATA")); $first = true; while (!$file->feof()) { $xml = $file->fread(2048); if ($first) { $xml = ltrim($xml); $first = false; } xml_parse($parser, $xml, false); } if ($file->feof()) { xml_parse($parser, "", true); } $file->fclose($fp); $ignore[] = "ARG"; $ignore[] = "CATEGORIES"; $ignore[] = "CATEGORY"; $ignore[] = "CONTENT"; $ignore[] = "DC:SUBJECT"; $ignore[] = "FIELD"; $ignore[] = "FIELDS"; $ignore[] = "OPTIONVALUE"; $ignore[] = "PAYMETHOD"; $ignore[] = "PRODUCTITEMDETAIL"; $ignore[] = "PRODUCTREF"; $ignore[] = "SHIPMETHOD"; $ignore[] = "TDCATEGORIES"; $ignore[] = "TDCATEGORY"; $ignore[] = "MEDIA:THUMBNAIL"; $repeating_element_count = 0; foreach ($this->analysis_records as $xpath => $data) { if ($data["count"] > $repeating_element_count) { $ok_to_use = TRUE; foreach ($ignore as $v) { if (strpos($xpath, $v) !== FALSE) { $ok_to_use = FALSE; } } if ($ok_to_use) { //$repeating_element_xpath = $xpath; $repeating_element_count = $data["count"]; } } } return $repeating_element_xpath; }
public function read(FileInterface $file) { return $file->fread($file->filesize()); }
/** * Starts parsing a file * * @param FileInterface $file * @return array() the xml data * @access public */ public function parse(FileInterface $file, ParseOptions $options) { if ($this->parser === null) { throw new ParserException('Parser not been registered'); } $this->depth = 0; $this->stack = new Stack(); $this->tree = null; $this->stack->push(array()); // first index top of the tree $this->done = false; # start iterating over the file $first = true; while (!$file->feof() && !$this->done) { $xml = $file->fread(2048); if ($first) { $xml = ltrim($xml); $first = false; } if (xml_parse($this->parser, $xml, false) <= 0) { throw new PHPXmlParserError($this->getParserError()); } } # parsing line by line need to tell parsre the last pieice. if ($file->feof()) { xml_parse($this->parser, "", true); } # close the file $file->fclose(); return true; }