XML to JSON to XML

Hi @robvp ah yes, I see I made a small error in the namespace declaration, but also hadn’t allowed for additional namespaces, so I’ve looked at what you were doing and I can see what you were aiming at, but I’ve gone back and adjusted the workflow so that the “etd” namespace columns get identified up-front. This would be better for future proofing if there ended up being multiple columns with the same name but different namespaces (which of course is the primary reason for namespaces in the first place :wink: )

So a metanode at the beginning splits the columns and sets some to “tns..” and others to “etd..”

This could be adjusted further as necessary if there are other namespaces.
I then updated downstream nodes that were affected by these column name changes.

I also noticed my error in the nodes highlighted here. These have to be set to “unnamed root element” since otherwise the grouping element name gets nested inside itself!

And finally, the part that was causing trouble with namespaces. I thought about how to simplify this process and make it flexible for future use and created a component to handle the namespace “corrections”

The Variable Creator contains a var called “NAMESPACES-REPLACEMENT” and is set to an arbitrary value that you won’t find elsewhere in your XML, e.g “[#REPLACENAMESPACES#]”

This is then used to populate the Namespace entry in the JSON to XML node

and this causes the declaration line to be generated as this:

There is then a component that I created to keep things clean “Replace Namespace declaration”.

This component performs two jobs. Firstly it handles the replacement of “tns..” with “tns:” and “etd..” with “etd:” (using a Table Creator to supply the internal String Replacer (Dictionary)

and secondly it replaces the entire line containing the above “[#REPLACENAMESPACES#]” marker/ It is configurable so if I have the namespace line declaration wrong, you can change it:

I don’t know if you still need the String Replace to replace " with , I assume you do so I’ve left it in anyway. This now generates well-formed XML again.

The included component is shared in my “experimental” space on the hub.

Feel free to pull it down, disconnect, modify/adapt and share on your own hub space as you see fit.

Here is the updated workflow

XML to JSON to XML JPK FA SIMPLIFIED-3-takbb.knwf (436.2 KB)

edit: btw in the namespace info you gave in your last post, the namespaces seemed to be doubled-up.
I removed the duplication but just realised on re-reading what I pasted above that a ref to KNIME.ORG was also in there. I imagine that shouldn’t really be there, but that can be manually adjusted now in the above component as needed.

3 Likes