Projet

Général

Profil

Paste
Télécharger (1,05 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / feeds_xpathparser / FeedsXPathParserXML.inc @ 135bbeb9

1
<?php
2

    
3
/**
4
 * @files
5
 * Provides the FeedsXPathParserXML class.
6
 */
7
class FeedsXPathParserXML extends FeedsXPathParserBase {
8

    
9
  /**
10
   * Implements FeedsXPathParserBase::setup().
11
   */
12
  protected function setup($source_config, FeedsFetcherResult $fetcher_result) {
13

    
14
    if (!empty($source_config['exp']['tidy'])) {
15
      $config = array(
16
        'input-xml' => TRUE,
17
        'wrap'      => 0,
18
        'tidy-mark' => FALSE,
19
      );
20
      // Default tidy encoding is UTF8.
21
      $encoding = $source_config['exp']['tidy_encoding'];
22
      $raw = tidy_repair_string(trim($fetcher_result->getRaw()), $config, $encoding);
23
    }
24
    else {
25
      $raw = $fetcher_result->getRaw();
26
    }
27
    $doc = new DOMDocument();
28
    $use = $this->errorStart();
29
    $success = $doc->loadXML($raw);
30
    unset($raw);
31
    $this->errorStop($use, $source_config['exp']['errors']);
32
    if (!$success) {
33
      throw new Exception(t('There was an error parsing the XML document.'));
34
    }
35
    return $doc;
36
  }
37

    
38
  protected function getRaw(DOMNode $node) {
39
    return $this->doc->saveXML($node);
40
  }
41
}