Loading src/Plugin/migrate_plus/data_parser/SimpleXml.php +1 −1 Original line number Diff line number Diff line Loading @@ -73,7 +73,7 @@ class SimpleXml extends DataParserPluginBase { foreach ($this->fieldSelectors() as $field_name => $xpath) { foreach ($target_element->xpath($xpath) as $value) { if ($value->children() && !trim((string) $value)) { $this->currentItem[$field_name] = $value; $this->currentItem[$field_name][] = $value; } else { $this->currentItem[$field_name][] = (string) $value; Loading src/Plugin/migrate_plus/data_parser/Xml.php +1 −1 Original line number Diff line number Diff line Loading @@ -255,7 +255,7 @@ class Xml extends DataParserPluginBase { // and has children then return the whole object for the process // plugin or other row manipulation. if ($value->children() && !trim((string) $value)) { $this->currentItem[$field_name] = $value; $this->currentItem[$field_name][] = $value; } else { $this->currentItem[$field_name][] = (string) $value; Loading tests/data/xml_multiple_items.xml 0 → 100644 +21 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <items> <item> <Id>item_1</Id> <Name>Item 1</Name> <Values1> <SubItem> <Id>1</Id> <Name>Name 1</Name> </SubItem> <SubItem> <Id>2</Id> <Name>Name 2</Name> </SubItem> </Values1> <Values2> <SubItem>3</SubItem> <SubItem>4</SubItem> </Values2> </item> </items> tests/data/xml_persons.xml 0 → 100644 +32 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <persons> <person> <id>1</id> <name>Elizabeth</name> <children> <child age="8"> <name>Elizabeth Junior</name> <name>Jane</name> </child> </children> </person> <person> <id>2</id> <name>George</name> <children> <child> <name>George Junior</name> <age>10</age> </child> </children> </person> <person> <id>3</id> <name>Peter</name> <children> <child> <name age="6">Lucy</name> </child> </children> </person> </persons> tests/src/Kernel/Plugin/migrate_plus/data_parser/BaseXmlTest.php +36 −1 Original line number Diff line number Diff line Loading @@ -124,7 +124,7 @@ abstract class BaseXmlTest extends KernelTestBase { */ public function testSingleValueWithAttributes() { $urls = [ $this->path . '/tests/data/xml_data_parser.xml', $this->path . '/tests/data/xml_persons.xml', ]; $this->configuration['urls'] = $urls; $this->configuration['item_selector'] = '/persons/person'; Loading @@ -150,6 +150,41 @@ abstract class BaseXmlTest extends KernelTestBase { $this->assertEquals($expected_names, $names); } /** * Tests retrieval a value with multiple items. */ public function testMultipleItems(): void { $this->configuration['urls'] = [ $this->path . '/tests/data/xml_multiple_items.xml', ]; $this->configuration['fields'] = [ [ 'name' => 'id', 'label' => 'Id', 'selector' => 'Id', ], [ 'name' => 'sub_items1', 'label' => 'Sub items 1', 'selector' => 'Values1/SubItem', ], [ 'name' => 'sub_items2', 'label' => 'Sub items 2', 'selector' => 'Values2/SubItem', ], ]; $parser = $this->getParser(); $parser->next(); // Transform SimpleXMLELements to arrays. $item = json_decode(json_encode($parser->current()), TRUE); $sub_items1 = array_column($item['sub_items1'], 'Id'); $this->assertEquals(['1', '2'], $sub_items1); $this->assertEquals(['3', '4'], $item['sub_items2']); } /** * Parses and asserts the results match expectations. * Loading Loading
src/Plugin/migrate_plus/data_parser/SimpleXml.php +1 −1 Original line number Diff line number Diff line Loading @@ -73,7 +73,7 @@ class SimpleXml extends DataParserPluginBase { foreach ($this->fieldSelectors() as $field_name => $xpath) { foreach ($target_element->xpath($xpath) as $value) { if ($value->children() && !trim((string) $value)) { $this->currentItem[$field_name] = $value; $this->currentItem[$field_name][] = $value; } else { $this->currentItem[$field_name][] = (string) $value; Loading
src/Plugin/migrate_plus/data_parser/Xml.php +1 −1 Original line number Diff line number Diff line Loading @@ -255,7 +255,7 @@ class Xml extends DataParserPluginBase { // and has children then return the whole object for the process // plugin or other row manipulation. if ($value->children() && !trim((string) $value)) { $this->currentItem[$field_name] = $value; $this->currentItem[$field_name][] = $value; } else { $this->currentItem[$field_name][] = (string) $value; Loading
tests/data/xml_multiple_items.xml 0 → 100644 +21 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <items> <item> <Id>item_1</Id> <Name>Item 1</Name> <Values1> <SubItem> <Id>1</Id> <Name>Name 1</Name> </SubItem> <SubItem> <Id>2</Id> <Name>Name 2</Name> </SubItem> </Values1> <Values2> <SubItem>3</SubItem> <SubItem>4</SubItem> </Values2> </item> </items>
tests/data/xml_persons.xml 0 → 100644 +32 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <persons> <person> <id>1</id> <name>Elizabeth</name> <children> <child age="8"> <name>Elizabeth Junior</name> <name>Jane</name> </child> </children> </person> <person> <id>2</id> <name>George</name> <children> <child> <name>George Junior</name> <age>10</age> </child> </children> </person> <person> <id>3</id> <name>Peter</name> <children> <child> <name age="6">Lucy</name> </child> </children> </person> </persons>
tests/src/Kernel/Plugin/migrate_plus/data_parser/BaseXmlTest.php +36 −1 Original line number Diff line number Diff line Loading @@ -124,7 +124,7 @@ abstract class BaseXmlTest extends KernelTestBase { */ public function testSingleValueWithAttributes() { $urls = [ $this->path . '/tests/data/xml_data_parser.xml', $this->path . '/tests/data/xml_persons.xml', ]; $this->configuration['urls'] = $urls; $this->configuration['item_selector'] = '/persons/person'; Loading @@ -150,6 +150,41 @@ abstract class BaseXmlTest extends KernelTestBase { $this->assertEquals($expected_names, $names); } /** * Tests retrieval a value with multiple items. */ public function testMultipleItems(): void { $this->configuration['urls'] = [ $this->path . '/tests/data/xml_multiple_items.xml', ]; $this->configuration['fields'] = [ [ 'name' => 'id', 'label' => 'Id', 'selector' => 'Id', ], [ 'name' => 'sub_items1', 'label' => 'Sub items 1', 'selector' => 'Values1/SubItem', ], [ 'name' => 'sub_items2', 'label' => 'Sub items 2', 'selector' => 'Values2/SubItem', ], ]; $parser = $this->getParser(); $parser->next(); // Transform SimpleXMLELements to arrays. $item = json_decode(json_encode($parser->current()), TRUE); $sub_items1 = array_column($item['sub_items1'], 'Id'); $this->assertEquals(['1', '2'], $sub_items1); $this->assertEquals(['3', '4'], $item['sub_items2']); } /** * Parses and asserts the results match expectations. * Loading