When the parent has attributes, the xml data_parser migrate_plus plugin reduces single-value results to scalars wrongly: it takes the attributes instead of the value.
The count() function only counts the children of the SimpleXMLElement. The attributes which the element might have are not counted, but returned when the reset function is used. An alternative could be to return the first child of the element, but the attributes may be relevant to the processor, hence leaving control to the processor. Therefor only reducing single-value arrays to scalar seems to be the viable option for this problem.
The inline code documentation also states transforming the result to scalar which would negate the possibility of a child node of a SimpleXmlElement for backwards compatibility.
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | 2986883-10.patch | 3.65 KB | heddn |
| #10 | interdiff_6-10.txt | 2.14 KB | heddn |
Comments
Comment #2
rojan raj commentedPatch attached for fix.
Comment #3
rojan raj commentedComment #4
StefanPr commentedAdded/adjusted some code comments for clarification.
Added tests.
Comment #6
StefanPr commentedCode style fix for succeeding tests
Comment #7
StefanPr commentedComment #8
heddnCould we have a scenario with multiple children too to confirm those are imported as arrays still?
Comment #9
StefanPr commentedI'll try and add some more tests since there aren't any for this data_parser, but these wouldn't be needed for this issue since it selects a single child. If we wanted to select multiple children the selector would be /children. The scenario might not be the best example since it implies working for multiple children, but it tests the current issue retrieving a single value from the last child retrieved from xpath when it has attributes.
Comment #10
heddnHere's a couple more scenarios.
Comment #11
gnugetI found this issue today and #10 looks GREAT!
Thanks @heddn, @StefanPr and @rojan raj
Comment #12
gnugetI just noted that the
SimpleXMLplugin already do this check so even the comment explaining the change might be unnecessary.https://git.drupalcode.org/project/migrate_plus/-/blob/8.x-5.x/src/Plugi...
Comment #14
heddnThanks everyone for your contributions.