Projet

Général

Profil

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

root / drupal7 / sites / all / modules / feeds_xpathparser / FeedsXPathParserXML.inc @ 0b4524f6

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
   * {@inheritdoc}
15
   */
16
  protected function setup($source_config, FeedsFetcherResult $fetcher_result) {
17
    if (!empty($source_config['exp']['tidy']) && extension_loaded('tidy')) {
18
      $config = array(
19
        'input-xml' => TRUE,
20
        'wrap'      => 0,
21
        'tidy-mark' => FALSE,
22
      );
23
      // Default tidy encoding is UTF8.
24
      $encoding = $source_config['exp']['tidy_encoding'];
25
      $raw = tidy_repair_string($fetcher_result->getRaw(), $config, $encoding);
26
    }
27
    else {
28
      $raw = $fetcher_result->getRaw();
29
    }
30

    
31
    $options = LIBXML_NONET;
32
    $options |= defined('LIBXML_COMPACT') ? LIBXML_COMPACT : 0;
33
    $options |= defined('LIBXML_PARSEHUGE') ? LIBXML_PARSEHUGE : 0;
34

    
35
    $document = new DOMDocument();
36
    $document->strictErrorChecking = FALSE;
37
    $document->recover = TRUE;
38

    
39
    $use = $this->errorStart();
40

    
41
    $success = $document->loadXML($raw, $options);
42

    
43
    $this->errorStop($use, $source_config['exp']['errors']);
44

    
45
    if (!$success) {
46
      throw new Exception(t('There was an error parsing the XML document.'));
47
    }
48

    
49
    return $document;
50
  }
51

    
52
  /**
53
   * {@inheritdoc}
54
   */
55
  protected function getRaw(DOMNode $node) {
56
    return $this->doc->saveXML($node);
57
  }
58

    
59
}