I am trying to make a data export from D8 content to an XML file. Views_data_export module would be ideal for this but the XML I need to make has quite strict tag name restrictions (data import to a 3rd party system). Tag names can be changed for fields but how about the higher level <response>
and <item>
-tags?
I did not find any documentation about this, only instructions for D7 on how to change them. It would be interesting to know if this can be accomplished on D8 version at all at the moment? If not, this ticket could be a "Feature request" instead :)
Thanks for any help in advance!
Comment | File | Size | Author |
---|---|---|---|
#50 | 2886357-50.patch | 12.35 KB | Chizh273 |
#50 | Screenshot 2023-11-10 at 15.48.13.png | 659.23 KB | Chizh273 |
#47 | 2886357-47.patch | 12.35 KB | reszli |
|
Issue fork views_data_export-2886357
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
tmountjr CreditAttribution: tmountjr commentedI would like this functionality as well. I have a client taking webform submissions and translating them to an XML feed they can import into their CRM, but if I'm unable to change the "<response><item>...</item></response>" format it doesn't do them any good.
Comment #3
goldlilys CreditAttribution: goldlilys as a volunteer commentedI need a way to display XML format with the following structure:
As you can see, besides being able to change the field tags, I also want to change the
<item>
tags to<slide>
to group each item and<response>
to<channel>
In D7, the xml version had the headers tags:
available ... why isn't it included in D8?
Comment #4
heatherwoz CreditAttribution: heatherwoz commentedI was looking for how to set or change the encoding. That would be helpful too in addition to changing the default XML tags.
Comment #5
aiphesSuscribing too.
Comment #6
Sissonen CreditAttribution: Sissonen commentedChanging category to feature request.
Comment #7
abiyub CreditAttribution: abiyub commentedI am trying to do the same. -- I used Views Data Export module for Drupal 7. it looks like it is not available for D8 now.
Comment #8
drfuzetto CreditAttribution: drfuzetto as a volunteer commentedI am interested in this feature as well.
D7 you could define the root and item node. This feature doesn't not exist in D8.
Comment #9
aiphesIs it planned for future beta or RC release ?
Comment #10
drfuzetto CreditAttribution: drfuzetto as a volunteer commentedI ended up creating a custom serializer.
Mostly based off the code sample from here: https://www.drupal.org/forum/support/module-development-and-code-questio...
Here are some other helpful links:
https://www.drupal.org/forum/support/module-development-and-code-questio...
https://www.drupal.org/docs/8/api/serialization-api
Comment #11
MichelleI've been digging into this because I need it to be "nodes"/"node" not "response"/"item". Using the tips in #10, I made my own serializer but wasn't sure what to put in it. I was hoping to reuse as much of the core one as possible and found that you can change the rootnode (see https://www.drupal.org/project/drupal/issues/2824837#comment-12353490 ) but "item" is hardcoded deep in there.
I also found that the core XML serializer might be going away in Drupal 9: https://www.drupal.org/project/drupal/issues/2926034
I'm not sure how to write this properly so just am going to cobble something together. Would be nice to see better xml support in the module, though.
Comment #12
Upchuk CreditAttribution: Upchuk at WEBOMELETTE commentedHere is a patch that does this. It allows the following:
Comment #13
Upchuk CreditAttribution: Upchuk at WEBOMELETTE commentedAh, my markup from the third bullet was lost. It allows for use cases like:
Comment #14
Upchuk CreditAttribution: Upchuk at WEBOMELETTE commentedOops, forgot to set the new options in the defaults. Here we go.
Comment #15
Upchuk CreditAttribution: Upchuk at WEBOMELETTE commentedIt seems I forgot in batch exporting to remove the custom nodes added via configuration from the beginning and end of batch. Now it should be better.
Comment #16
mchamps CreditAttribution: mchamps commentedHi, I received the follow errors when I tried to patch with composer.
The issue came up with #12, #14 & #15.
- Installing drupal/views_data_export (1.0.0): Loading from cache
- Applying patches for drupal/views_data_export
https://www.drupal.org/files/issues/2021-01-16/2886357-14.patch (Changing default and tags in XML import)
Could not apply patch! Skipping. The error was: Cannot apply patch https://www.drupal.org/files/issues/2021-01-16/2886357-14.patch
[Exception]
Cannot apply patch Changing default and tags in XML import (https://www.drupal.org/files/issues/2021-01-16/2886357-14.patch)!
It's a great feature. Thanks !
Following !
Comment #17
Upchuk CreditAttribution: Upchuk at WEBOMELETTE commentedThe patch applies to the latest DEV version of the module, not the release 1.0.0.
Comment #18
Nikolay Borisov CreditAttribution: Nikolay Borisov as a volunteer and commentedthank you for the patch from #15, Upchuk
unforch it is not working for me ( Drupal 8.9.13, Views data export 8.x-1.x-dev)
I assume that you have checked a newer version of the XmlEncoder, where XmlEncoder::ROOT_NODE_NAME actually exists (in symfony/serializer 5 for example https://github.com/symfony/serializer/blob/5.x/Encoder/XmlEncoder.php), but in symfony/serializer 3.4 it does not exist https://github.com/symfony/serializer/blob/3.4/Encoder/XmlEncoder.php
Thats why I am using your patch with the slight change there and it works perfectly for me.
Cheers!
Comment #20
Upchuk CreditAttribution: Upchuk at WEBOMELETTE commented@Nikolay Borisov can you please provide an interdiff so I can see what was changed? Difficult to see otherwise.
Comment #21
Nikolay Borisov CreditAttribution: Nikolay Borisov as a volunteer and commentedsure @Upchuk.
Maybe you simply did it on Drupal 9. Apparently in the version 4.4 of the symfony/serializer compoenent the ROOT_NODE_NAME constant exists -> https://github.com/symfony/serializer/blob/4.4/Encoder/XmlEncoder.php (apparently introduced in version 4.2 of the component), where the version that is coming with Drupal 8 it is missing (simply check your version in the codebase where it is working with "composer show symfony/serializer" - in my case it was v3.4.47)
Cheers!
Comment #22
Upchuk CreditAttribution: Upchuk at WEBOMELETTE commentedI would check if the constant is defined and do a fallback if not. Also, not sure why the tests are failing now.
Comment #23
Nikolay Borisov CreditAttribution: Nikolay Borisov as a volunteer and commented@Upchuk I think it is a very good idea!
Here is a patch for that.
Comment #24
sakonn CreditAttribution: sakonn commentedHello,
the patch seems to work for me. Would like to have this functionality in this module.
Comment #25
matio89 CreditAttribution: matio89 at MAT-IT commentedAttached a patch that works on 8.x-1.0 version.
Comment #26
matio89 CreditAttribution: matio89 at MAT-IT commentedComment #27
GuillaumeDuveauSeems good to me, thanks. Tested on Drupal 9.2 + Views data export 8.x-1.0
Comment #28
sj.suraj CreditAttribution: sj.suraj commentedI am testing on Drupal 9.2 + Views data export 8.x-1.0
Only #25 is working for me but it's getting failed in test also it has missing schema for
xml_settings
,root_node_name
,item_node_name
,items_wrapper_node
Comment #29
sj.suraj CreditAttribution: sj.suraj as a volunteer commentedAdded updated patch to fix the test.
Comment #30
Qusai Taha CreditAttribution: Qusai Taha at Vardot commentedRe-roll the patch
Comment #31
Qusai Taha CreditAttribution: Qusai Taha at Vardot commentedComment #32
Qusai Taha CreditAttribution: Qusai Taha at Vardot commentedComment #33
smulvih2Comment #34
smulvih2Fixed formatting issue from patch #30. Also fixed #title attribute for
item_node_name
which was placed underitems_wrapper_node
as a duplicate #title.Comment #35
smulvih2The patch in #34 isn't enough to meet my requirements, I still need some more options. Please see desired XML output:
What is missing:
New patch implements the required changes above, while still supporting requirements from previous comments. I tested this with both standard and batch methods and works as expected with any combination of the options enabled.
New XML options:
Comment #36
GuillaumeDuveauPatch in #35 works for me, thanks!
Comment #37
tarasiadis CreditAttribution: tarasiadis commentedPatch in #35 works for me too, thanks!
But how can I set <?xml version="1.0" encoding="UTF-8" ?>
Maybe one more parameter as Root node attributes for xml element parameters?
Comment #38
nojj CreditAttribution: nojj commentedPatch #35 works for even for the 8.x-1.1 release.
but what about this
?
Comment #39
aiphes#35 add extra settings but xml output by default is like:
How can I add this infos ?:
Thanks
Comment #42
Xperd CreditAttribution: Xperd commentedAdded XML prolog encoding="utf-8" to patch #35
Comment #43
tarasiadis CreditAttribution: tarasiadis commentedI have problem to apply patch #42
Get below messages....
Could not apply patch! Skipping. The error was: Cannot apply patch https://www.drupal.org/files/issues/2022-09-25/2886357-42.patch
[Exception]
Cannot apply patch Ρυθμίσεις παραμέτρων της εξαγωγής xml για το root-item (https://www.drupal.org/files/issues/2022-09-25/2886357-42.patch)!
Comment #44
Xperd CreditAttribution: Xperd commentedComment #45
tarasiadis CreditAttribution: tarasiadis commentedThanks Xperd, #44 patch works.
One more issue. The produced file is not optimized in tree structure (beautifier style) like other xml files. How can we achieve this?
Comment #46
tarasiadis CreditAttribution: tarasiadis commentedSorry styling of tree I think is problem of my editor as on Chrome works ok.
Comment #47
reszlichanges to improve functionality and code:
still left to do:
Comment #48
reszliComment #49
jhedstromThe code in #47 and in the MR need to be reconciled. It would also be great to add a batch export test for these custom xml tags.
Comment #50
Chizh273 CreditAttribution: Chizh273 commentedThe #47 has one issue.
If you open the settings of the data export format with enabled warning logging (
$config['system.logging']['error_level'] = 'verbose';
) you will get a warning "Warning: Undefined array key "metadata" in /var/www/html/web/modules/contrib/views_data_export/src/Plugin/views/style/DataExport.php on line 241".I have updated the #47 patch to fix this warning.
Comment #51
sir_squall CreditAttribution: sir_squall commentedThank you very much the path #50 work well!
Comment #52
proweb.ua CreditAttribution: proweb.ua commented#50 works
how to add attributes to Item node name?
can this be done via the API?