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 @ 27370441

1 85ad3d82 Assos Assos
<?php
2
3
/**
4
 * @files
5 f066bdb5 Assos Assos
 * Contains FeedsXPathParserXML.
6
 */
7
8
/**
9
 * XPath parsing for XML.
10 85ad3d82 Assos Assos
 */
11
class FeedsXPathParserXML extends FeedsXPathParserBase {
12
13
  /**
14 0b4524f6 Assos Assos
   * {@inheritdoc}
15 85ad3d82 Assos Assos
   */
16
  protected function setup($source_config, FeedsFetcherResult $fetcher_result) {
17 f066bdb5 Assos Assos
    if (!empty($source_config['exp']['tidy']) && extension_loaded('tidy')) {
18 85ad3d82 Assos Assos
      $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 0b4524f6 Assos Assos
      $raw = tidy_repair_string($fetcher_result->getRaw(), $config, $encoding);
26 85ad3d82 Assos Assos
    }
27
    else {
28
      $raw = $fetcher_result->getRaw();
29
    }
30 0b4524f6 Assos Assos
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 85ad3d82 Assos Assos
    $use = $this->errorStart();
40 0b4524f6 Assos Assos
41
    $success = $document->loadXML($raw, $options);
42
43 85ad3d82 Assos Assos
    $this->errorStop($use, $source_config['exp']['errors']);
44 0b4524f6 Assos Assos
45 85ad3d82 Assos Assos
    if (!$success) {
46
      throw new Exception(t('There was an error parsing the XML document.'));
47
    }
48 0b4524f6 Assos Assos
49
    return $document;
50 85ad3d82 Assos Assos
  }
51
52 0b4524f6 Assos Assos
  /**
53
   * {@inheritdoc}
54
   */
55 85ad3d82 Assos Assos
  protected function getRaw(DOMNode $node) {
56
    return $this->doc->saveXML($node);
57
  }
58 0b4524f6 Assos Assos
59 85ad3d82 Assos Assos
}