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 |
|---|
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 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 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 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 commentedChanging category to feature request.
Comment #7
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 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 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 commentedHere is a patch that does this. It allows the following:
Comment #13
upchuk commentedAh, my markup from the third bullet was lost. It allows for use cases like:
Comment #14
upchuk commentedOops, forgot to set the new options in the defaults. Here we go.
Comment #15
upchuk 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 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 commentedThe patch applies to the latest DEV version of the module, not the release 1.0.0.
Comment #18
nikolay borisov 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 commented@Nikolay Borisov can you please provide an interdiff so I can see what was changed? Difficult to see otherwise.
Comment #21
nikolay borisov 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 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 commented@Upchuk I think it is a very good idea!
Here is a patch for that.
Comment #24
sakonn commentedHello,
the patch seems to work for me. Would like to have this functionality in this module.
Comment #25
matio89 commentedAttached a patch that works on 8.x-1.0 version.
Comment #26
matio89 commentedComment #27
guillaumeduveauSeems good to me, thanks. Tested on Drupal 9.2 + Views data export 8.x-1.0
Comment #28
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_nodeComment #29
sj.suraj commentedAdded updated patch to fix the test.
Comment #30
qusai taha commentedRe-roll the patch
Comment #31
qusai taha commentedComment #32
qusai taha commentedComment #33
smulvih2Comment #34
smulvih2Fixed formatting issue from patch #30. Also fixed #title attribute for
item_node_namewhich was placed underitems_wrapper_nodeas 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 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 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 commentedAdded XML prolog encoding="utf-8" to patch #35
Comment #43
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 commentedComment #45
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 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 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 commentedThank you very much the path #50 work well!
Comment #52
proweb.ua commented#50 works
how to add attributes to Item node name?
can this be done via the API?
Comment #53
jibus commented#50 works also.
I would suggest to move the "Item wrapper node name" before "Item node name" configuration field.
Comment #54
newme154 commentedHello,
I am not seeing the drop down info for the xml settings. however, I do see it for the CSV settings.
Comment #55
bassline commented#50 works
The XML configuration worked in my environment
Comment #56
andrew.wang commented#50 works +1. This patch is super handy for generating xml sitemap!
Comment #57
steven jones commentedThis looks great, and thanks for the hard work everyone, but this sort of change really should have some tests to make sure we're not breaking things for existing sites, and that the new settings work correctly etc. so setting back to needs work.
Comment #62
joelpittet@steven jones Thanks for the feedback. Reading between the lines, it sounds like the minimum needed here might be a test confirming that the XML response remains unchanged with the new feature settings unchanged. That would help ensure existing sites aren’t affected. Does that sound like the right approach? (Noting there are currently no XML output tests.)
Comment #63
joelpittet@steven jones I added a test as I suggested in #62 plus what it should look like with this change as well. It's super bare bones but maybe give you the confidence to commit?
Couple of notes:
issues from showing up after commit.
encoding="utf-8"so my test would likely fail in a test-only run. Though likely a good thing to have on XML so I didn't remove it from this MR.Comment #64
joelpittetHiding patches to avoid confusion.
Comment #65
franceslui commentedI reviewed the latest changes in the MR and tested them locally. Everything works as expected. The changes are minor, focused on code improvements, and include appropriate test coverage. I did not encounter any regressions or issues introduced by this patch.
Regarding the CSV and XML collapsible panes: when I expand these panes, collapse them, and then expand them again, they appear shortened as if they did not expand because only a portion of the content is immediately visible. The remaining content requires scrolling to view, which can be misleading. This seems to be a UX quirk, not caused by this MR, and likely a general issue in Drupal core.
Marking this MR RTBC. Thanks for the improvements and for adding test coverage.
Comment #66
steven jones commentedThanks @joelpittet for the work on this, and thanks everyone else for your continued patience with Views Data Export maintership!
Okay, so the code as it stands does have a few issues, specifically because of using string replacements to do some of the heavy lifting rather than an XML library. This reminds me of the famous stack overflow answer about parsing HTML with regex.
For example, at the moment I can set both the 'root node name' and 'item node name' to say 'response' and then use the new 'XML metadata field to add some more stuff in, and all that stuff actually gets repeated throughout the file, not only after the root node, as is the intention of the code.
I think there are a lot of sticky issues that we might need to sort out with this stuff, like the fact that it seems weird that you can inject arbirary non-valid XML into the middle of the XML document anyway. Seems like this is going to be super brittle going forward if this doesn't get done right.
I appreciate that the current batched export code also does string replacements, but I think that's another bug waiting to happen. Presumably you can't have a field called 'response' in a batch XML export, yes in fact, that breaks very badly at the moment!
I think what I'd like to do is:
<response>and<item>tags.simplebroken plain string swaps.Sorry if that sounds super annoying / convoluted, but I think rather than hold up some of these features because they aren't all ready, it makes sense to split them out.
I'll make the other tickets in moment, and we can refocus the work here to be back to the original issue.
Comment #67
steven jones commentedComment #69
steven jones commentedSort of tempted to remove the cheeky addition of the
encoding="utf-8"bit, and then the changes here really will be absolutely minimal and could get merged right in.Comment #70
joelpittetI recommend keeping encoding="UTF-8" in there — it ensures correct character decoding, avoids cross-platform inconsistencies, and even if XML parsers are required to assume UTF-8 by default, it’s still best practice to include it explicitly.
Comment #71
steven jones commented@joelpittet yeah, agreed, I think it should almost always be in there, but I don't want to break something random in someone's export, so I think I'll punt that change to #3522528: Allow specifying the XML encoding property and maybe we can make it the default for new installs or something like that.
You happy with the code otherwise?
Comment #72
steven jones commentedComment #73
steven jones commentedComment #75
steven jones commentedThanks everyone for your patience, I'll note that I'm committing a partial version of what was in MR!75, so if you're using all the features of this MR/patch then you might want to stick with that until all the sub issues of #3522419: [META]Make XML output more configurable are in, and then upgrade to the version of VDE that has those in.