first of all, I would like to thank @takbb for sharing his XML Generator Component with the community. In my opinion a great little tool especially for non-developers.
I am currently facing problems generating a certain xml structure with the component. Maybe someone who has more experience with the component can help me out. I put together an example workflow. The top part is where I am trying to create an xml with the XML generator. On the bottom you can find the desired XML structure as a reference.
XML Order Test.knwf (37.6 KB)
The input table looks like this. The first three rows represent one order with three items and the fourth row is another order with only one item.
The XML output I would like to create looks like this. Every order should contain one <ORDER_INFO> element and as many <LINE_INFO> elements as there are line items in the order.
After some trial and error the closest I could get to the desired result is this. For every line item a seperate <ORDER_INFO> and <LINE_INFO> element is created.
Can this be achieved with the XML generator component? Any help would be highly appreciated.
Hi @e2dboden , thank you for trying out my XML gen component. I don’t have access to my KNIME environment this week but I will endeavour to take a look at your workflow in the coming week and hopefully help answer you question.
@takbb Great, thank you.
My problem atm is, that I cannot really tell whether the component can be configured, to do what I want.
I like to keep my workflows simple. If possible, I would like to manage with only one XML generator.
If not, I will try out to generate the <ORDER_INFO> and <LINE_INFO> segments seperately and combine them with the XML column combiner. This will probably work, I still would like to explore my options with the XML generator first. The XML structure in my real use-case is a lot more complex with a lot more segments, leading me down a path of unwieldy workflows.
Hi @e2dboden, I think I may have some good news for you!
I can’t believe it is well over a year since I wrote that component and had to remind myself how it worked. It is still very much a prototype and I’m sure if there is interest in it I will find time to enhance it, but I believe it can be made to do what you have asked here without modification.
I think that adding the following lines to the “control” table does what you have requested:
I have uploaded this as an updated example.
XML Order Test - update 20220822.knwf (38.9 KB)
What this does is to define a further group element “LINE” which the LINE_INFO groups then have as their “parent”. The “breakonchange” entry tells it to repeat the LINE group children until there is a change in value of “Order”.
If LINE had been given a display value such as “LINE”, it would then have been output as
But (luckily! )… by specifying that the display value of LINE is blank, it doesn’t output the tag
Thanks again for your interest in this component. I am sure that there are plenty of refinements that may be needed, and it may well be that for some use cases, I will need to do some additional development work on it, so please let me know if you have any further queries. Also thank you for providing a working example of your problem. Having a semi-working example to play with along with the “required output” made this so much easier for me to assist.
Incidentally, in your “desired XML” the outer element was rather than but I haven’t “corrected” that and obviously it can be easily changed in the control table if is the required output.
thanks again. I will let you know if I come across any new obstacles with my use-case.
It looks like the last paragraph is missing some words. I wouldn´t mind correcting the control table, but I cannot make out what exactly the problem is.
Ah sorry @e2dboden, I had included the
> without escaping them which caused problems in rendering the paragraph.
This is what it should have said:
Incidentally, in your “desired XML” the outer element was
<ORDER> rather than
<ORDERS> but I haven’t “corrected” that and obviously it can be easily changed in the control table if it’s the required output.
with your Input I was able to generate a couple more demanding xml files (e.g. openTrans). Thank you again for the component and your support.
I got one tiny problem with the order of the elements. Is it possible to order the elements within a group differently?
The order of the rows in the control table seem to have an impact on the order of the elements. I wasn´t yet able to figure how it works exactly.
As an example:
If I would like to change the order of the elements within the <LINE_INFO> group. Which rows in the control table would I need to bring in order?
Hi @e2dboden , I’m glad to hear it’s helping. As I recall, the ordering of the elements within a group should be in the order that their “parent” tags appears in the control file.
So, the previous sample xml generated as this:
But if I change the order in which the parent tags appear for LineNum, ItemCode and Quantity (I have placed Quantity now before ItemCode) to this:
The xml is generated as follows:
I hope that helps, but do let me know if it isn’t working as expected.
Works as described. Thanks
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.