- ๐ท๐ดRomania reszli Tรขrgu Mureศ
changes to improve functionality and code:
- I needed some more elements inside the root node, so I introduced an additional config field called "metadata" as a textarea
- also, I replaced the custom replacement of {{ lang }} by allowing the use of token in the attributes and metadata fields
- additionally I switched to dep. inj. where possible
still left to do:
- instead of strpos and str_replace, switch to a better way of manipulating the XML (i.e. using DOMDocument)
- Status changed to Needs work
over 2 years ago 8:38pm 22 February 2023 - ๐บ๐ฆUkraine chizh273
The #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.
- ๐จ๐ญSwitzerland sir_squall
Thank you very much the path #50 work well!
- ๐บ๐ฆUkraine proweb.ua
how to add attributes to Item node name?
can this be done via the API? - Status changed to Needs review
10 months ago 3:26pm 24 July 2024 - ๐ซ๐ทFrance jibus
#50 works also.
I would suggest to move the "Item wrapper node name" before "Item node name" configuration field.
- ๐บ๐ธUnited States newme154
Hello,
I am not seeing the drop down info for the xml settings. however, I do see it for the CSV settings.
- ๐ฏ๐ตJapan bassline
#50 works
The XML configuration worked in my environment
- Status changed to RTBC
5 months ago 7:28am 16 January 2025 - ๐ฌ๐งUnited Kingdom steven jones
This 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.
- ๐จ๐ฆCanada joelpittet Vancouver
joelpittet โ changed the visibility of the branch 2886357-changing-default-response to hidden.
- Status changed to Needs work
about 1 month ago 8:47pm 30 April 2025 - ๐จ๐ฆCanada joelpittet Vancouver
joelpittet โ changed the visibility of the branch 2886357-changing-default-response to active.
- ๐จ๐ฆCanada joelpittet Vancouver
joelpittet โ changed the visibility of the branch 8.x-1.x to hidden.
- ๐จ๐ฆCanada joelpittet Vancouver
@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.)
- ๐จ๐ฆCanada joelpittet Vancouver
@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:
- the new options weren't defaulted so I added some defaults unioned on to prevent
Exception: Warning: Undefined array key "metadata"
issues from showing up after commit.
- The previous version of this didn't have
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.
- the new options weren't defaulted so I added some defaults unioned on to prevent
- ๐จ๐ฆCanada franceslui
I 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.
- ๐ฌ๐งUnited Kingdom steven jones
Thanks @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:
- Restrict the scope of this issue to the original report only, i.e. allowing someone to change the
<response>
and<item>
tags. - Work on getting a test in for that functionality, which should be pretty easy tbh.
- Get just those points committed and mark this ticket as done. This will give us a proper place to put options, the beginnings of the code that's currently in the MR anyway and add in custom handling for XML where we'll need it in the future anyway.
- Replace out the current string manipulation of XML in the batched export with proper XML manipulations. This can be a new ticket that could be worked on separately.
- Raise separate tickets for the other features introduced in this ticket, which is:
- Removing the root node entirely (presumably only valid to do if there's only a single child node anyway.)
- Adding attributes to the root node - This doesn't need to be done as a single text field, as the Symfony serializer actually has built-in support for doing these already, so we could provide nice escaping etc. and not do broken plain string swaps.
- XML Header (the metadata) This seems like a bit of a weird one to me, but I understand that there might be some use-cases out there that would want to add some arbitrary XML to the root node of the file. Again this should get added via the XML encoder if possible, but maybe having big warning messages all over this entry field that you're likely to break things unless you know exactly what you're doing, then maybe it's okay.
- Removing empty values from the output.
- Adding an extra wrapper with an arbitrary name.
- Encourage others to work on those tickets/get them committed in a timely way.
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.
- Restrict the scope of this issue to the original report only, i.e. allowing someone to change the
- Merge request !76Resolve #2886357 "Allow changing the XML root and item node names. โ (Merged) created by steven jones
- ๐ฌ๐งUnited Kingdom steven jones
Sort 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. - ๐จ๐ฆCanada joelpittet Vancouver
I 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.
- ๐ฌ๐งUnited Kingdom steven jones
@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 โจ Allow specifying the XML encoding property Active and maybe we can make it the default for new installs or something like that.
You happy with the code otherwise?
-
steven jones โ
committed dabf0613 on 8.x-1.x
Issue #2886357 by xperd, steven jones, joelpittet, upchuk, nikolay...
-
steven jones โ
committed dabf0613 on 8.x-1.x
- ๐ฌ๐งUnited Kingdom steven jones
Thanks 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 โจ [meta]Make XML output more configurable Active are in, and then upgrade to the version of VDE that has those in.
Automatically closed - issue fixed for 2 weeks with no activity.