You are here

protected function Xml::getSimpleXml in Migrate Plus 8.4

Same name and namespace in other branches
  1. 8.5 src/Plugin/migrate_plus/data_parser/Xml.php \Drupal\migrate_plus\Plugin\migrate_plus\data_parser\Xml::getSimpleXml()
  2. 8.2 src/Plugin/migrate_plus/data_parser/Xml.php \Drupal\migrate_plus\Plugin\migrate_plus\data_parser\Xml::getSimpleXml()
  3. 8.3 src/Plugin/migrate_plus/data_parser/Xml.php \Drupal\migrate_plus\Plugin\migrate_plus\data_parser\Xml::getSimpleXml()

Builds a \SimpleXmlElement rooted at the iterator's current location.

The resulting SimpleXmlElement also contains any child nodes of the current element.

Return value

\SimpleXmlElement|false A \SimpleXmlElement when the document is parseable, or false if a parsing error occurred.

Throws

\Drupal\migrate\MigrateException

1 call to Xml::getSimpleXml()
Xml::fetchNextRow in src/Plugin/migrate_plus/data_parser/Xml.php
Retrieves the next row of data. populating currentItem.

File

src/Plugin/migrate_plus/data_parser/Xml.php, line 140

Class

Xml
Obtain XML data for migration using the XMLReader pull parser.

Namespace

Drupal\migrate_plus\Plugin\migrate_plus\data_parser

Code

protected function getSimpleXml() {
  $node = $this->reader
    ->expand();
  if ($node) {

    // We must associate the DOMNode with a DOMDocument to be able to import
    // it into SimpleXML. Despite appearances, this is almost twice as fast as
    // simplexml_load_string($this->readOuterXML());
    $dom = new \DOMDocument();
    $node = $dom
      ->importNode($node, TRUE);
    $dom
      ->appendChild($node);
    $sxml_elem = simplexml_import_dom($node);
    $this
      ->registerNamespaces($sxml_elem);
    return $sxml_elem;
  }
  else {
    foreach (libxml_get_errors() as $error) {
      $error_string = self::parseLibXmlError($error);
      throw new MigrateException($error_string);
    }
    return FALSE;
  }
}