FeedsXPathParserXML.inc 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. /**
  3. * @files
  4. * Provides the FeedsXPathParserXML class.
  5. */
  6. class FeedsXPathParserXML extends FeedsXPathParserBase {
  7. /**
  8. * Implements FeedsXPathParserBase::setup().
  9. */
  10. protected function setup($source_config, FeedsFetcherResult $fetcher_result) {
  11. if (!empty($source_config['exp']['tidy'])) {
  12. $config = array(
  13. 'input-xml' => TRUE,
  14. 'wrap' => 0,
  15. 'tidy-mark' => FALSE,
  16. );
  17. // Default tidy encoding is UTF8.
  18. $encoding = $source_config['exp']['tidy_encoding'];
  19. $raw = tidy_repair_string(trim($fetcher_result->getRaw()), $config, $encoding);
  20. }
  21. else {
  22. $raw = $fetcher_result->getRaw();
  23. }
  24. $doc = new DOMDocument();
  25. $use = $this->errorStart();
  26. $success = $doc->loadXML($raw);
  27. unset($raw);
  28. $this->errorStop($use, $source_config['exp']['errors']);
  29. if (!$success) {
  30. throw new Exception(t('There was an error parsing the XML document.'));
  31. }
  32. return $doc;
  33. }
  34. protected function getRaw(DOMNode $node) {
  35. return $this->doc->saveXML($node);
  36. }
  37. }