You are here

public function FeedsForenaXMLParser::parse in Forena Reports 7.5

Same name and namespace in other branches
  1. 7.3 feeds/FeedsForenaXMLParser.inc \FeedsForenaXMLParser::parse()
  2. 7.4 feeds/FeedsForenaXMLParser.inc \FeedsForenaXMLParser::parse()

Implements FeedsParser::parse().

File

feeds/FeedsForenaXMLParser.inc, line 7

Class

FeedsForenaXMLParser

Code

public function parse(FeedsSource $source, FeedsFetcherResult $fetcher_result) {
  $source_config = $source
    ->getConfigFor($this);
  $result = new FeedsParserResult();
  $parser = Frx::Fields($fields);

  // Load and configure parser.
  $xpath = @$this->config['xpath'];
  $options = @$this->config['options'];
  $options = @drupal_parse_info_format($source_config['options']);
  $fields = @$options['fields'];
  if (!$fields) {
    $fields = array();
  }
  $format = @(!$options['format']);
  $raw = $fetcher_result
    ->getRaw();
  $mappings = feeds_importer($this->id)->processor->config['mappings'];
  if ($raw) {
    $xml = new SimpleXMLElement($raw);

    // Treat * as normal iterator to improve performance.
    if ($xpath == '*') {
      $nodes = $xml;
    }
    else {
      $nodes = $xml
        ->xpath($xpath);
    }
    foreach ($nodes as $node) {
      Frx::Data()
        ->push($node, 'row');
      $item = array();
      foreach ($mappings as $field) {
        $text = $field['source'];
        $item[$text] = $parser
          ->render($text, !$format);
      }
      $result->items[] = $item;
      Frx::Data()
        ->pop();
    }
  }

  // Create a result object and return it.
  return $result;
}