Projet

Général

Profil

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

root / drupal7 / sites / all / modules / feeds_xpathparser / FeedsXPathParserXML.inc @ f066bdb5

1
<?php
2

    
3
/**
4
 * @files
5
 * Contains FeedsXPathParserXML.
6
 */
7

    
8
/**
9
 * XPath parsing for XML.
10
 */
11
class FeedsXPathParserXML extends FeedsXPathParserBase {
12

    
13
  /**
14
   * Implements FeedsXPathParserBase::setup().
15
   */
16
  protected function setup($source_config, FeedsFetcherResult $fetcher_result) {
17

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

    
42
  protected function getRaw(DOMNode $node) {
43
    return $this->doc->saveXML($node);
44
  }
45
}