1
XML writer seems not to support mapping an input to a element and it's corresponding nil attribut at the same time
Problem reported by Gunnar Quack - 2/4/2022 at 10:33 AM
Resolved
I need to transform a complex Json file to en XML file. The XML writer expose a pin for a element and a pin for the nil attribut. it is not possible to map an input to both pins.  I expect that when the JSON element is null, I can set the attribut nil=true on the XML attribut. it works fine only if I dont map the JSON element at the same time to the element. The transformation is not failing, but the result is that the XML element is empty. the problem is that not all XSD elements are optional. the expected behavior is when the nil attribut receive a true value and the element is null, that the XML writer writes en empty xml element with the attribut xsi:nil= true 

4 Replies

Reply to Thread
0
Liquid Support Replied
Employee Post
Hi,

Can you please provide an screen grab image of your data mapping example?

Of if it is very complex, please create a support ticket and send a zip of your .dm file and supporting data files:
0
Liquid Support Replied
Employee Post Marked As Resolution
Hi

I have not entirely understood your business logic, but I think this will give you what you need.
Which will turn 
"GBAreal": 3.01,

and

"GBAreal": null,
into 
<GBMark>
    <GBAreal>3.01</GBAreal>
</GBMark>
and
<GBMark>
    <GBAreal xsi:nil="true" />
</GBMark>
The key to this is duplicating the GBAreal element in the output
The first instance of GBAreal causes the element to be written out when the JSON value is 'null', we add the constant 'true' to force the nil attribute to be set to 'true'.

The second instance of GBAreal  causes an element to be written when the JSON value is a number.
If GBAreal is not present then nothing is output.

Note: It is not possible for them both to be written out (resulting in 2 GBAreal  elements) as the JSON source property can either contain a value (number) or be null (it can't be both) so only a max of one of them will ever be used.

0
Gunnar Quack Replied
yes, it works fine. to duplicate the node was the missing link.

but I wundred why the datatype of the null source is boolean. that cause a lot of double work. I had to cat the value to a string, when the target is a date.
0
Liquid Support Replied
Employee Post
You are correct, the Null node is of type bool, we will look at changing this to be of type string in a future release.

Reply to Thread