Table to XML

Dear all,
I’m trying to create an xml out of a table.
The solution provided in Create XML document from a table , which is to go over “Table to JSON” and then “JSON to XML” doesn’t work well in this case, because JSON rearranges the tags alphabetically. Loading the resulting XML files on the target platform results into errors.
The order of the tags is relevant and should stay the way we sort them using, e.g. “Column Resorter” node.
Is there a way to load a table directly to XML, preserving the needed tag order? Such a node would be a great thing!

hi @alexkrah

Take a look at a post I did a few weeks ago, too. It might be useful, but let me know if you have any questions about it

Hi @alexkrah , any data and workflow you can share?

Also, what is the issue with JSON rearranging the tags? JSON and XML are not dependent on position, hence why they have tag names. You access the elements by name, not by position.

@brunoa29a I think that’s true in many cases, but sometimes ordering of elements is enforced in an xml schema using the sequence tag, or is simply enforced by some badly written (or old) software that we have no control over. I’ve worked on projects where XML is used for interfacing but the recipient application’s xml parsing is perhaps not as well written as it should be and is fussy about order of elements.

So whilst I agree that in general order shouldn’t matter, I’ve seen places where it does, and sometimes there is no way round (nobody is going to pay for a some legacy destination application to be changed :wink: ) and it’s left to us get it output in the “correct” order, painful though it is.


Hi @takbb , yes I am aware of what you are saying, I have encountered these situations. Just trying to see if that is the case for @alexkrah and trying to raise awareness that the elements will be accessed by name in the end.

1 Like

@bruno29a, sure thing. It’s funny though how for me, once I got bitten a couple of times by a situation where I had to produce xml in a specific element order, it became the first thing I looked for in a generic xml generator, even though it ought to be just an edge case. I spent quite a while writing a bespoke generic java xml generator on one project about 10 years ago simply because I couldn’t find an open database-neutral tool to easily generate what I needed.

It was actually the driver behind me doing the above xml workflows, when I was looking at what Knime had to offer in this regard.

Yes, this is the case.
In the meanwhile I did find a way of sorting the XML elements by twicking with the tag-names, but this is no nice solution. I was just hoping, somebody has a better idea, or that KNIME takes this as an improvement opportunity.

Hi @alexkrah , if you have Python 3 installed within your KNIME environment, you may be interested in a couple of components I’ve been working on the past few days. I’ve taken ideas from a java xml generator I wrote a few years back and thrown together a python script. My aim is to have the ability to perform simple (and not so simple) xml generation without having to jump through hoops.

As an initial demo, see the workflow I have uploaded to the hub. If interested, I will also put up a further demo or maybe a small tutorial on how to go about configuring it to change things like element order, naming, grouping. It’s a work in progress, but happy to receive feedback on possible “features” that could be added. One day maybe I’ll try to develop something like this as a Java Node rather than a python script component. Ironic considering my original was done in Java!