Author |
Message
|
6FA |
Posted: Mon Jan 25, 2016 4:11 am Post subject: How to assign empty value using mapping node? |
|
|
Novice
Joined: 08 Jan 2016 Posts: 21
|
Hi Folks,
I'm converting msg from xml to csv using mapping node.
Ex XML msg:
<ID>1</ID>
<name></name>
<age>16</age>
Here I have a requirement that, if the value in xml is empty(Like <name></name>) I need to pass empty value to csv file.
Expected output: 1,,16
I'm using If, else condition. If fn:exists(name), then moving the value. In else statement I'm assigning hard value as ''. But in output I'm getting 1,'',16
Can anyone suggest how can I get the expected output.
Thanx  |
|
Back to top |
|
 |
maurito |
Posted: Mon Jan 25, 2016 4:53 am Post subject: |
|
|
Partisan
Joined: 17 Apr 2014 Posts: 358
|
Have you tried anything else , or just give up at the first hurdle ? If that didn't work, try something different. It probably will be quicker, you will learn something and once you get the solution, it will be more rewarding. |
|
Back to top |
|
 |
6FA |
Posted: Mon Jan 25, 2016 5:15 am Post subject: |
|
|
Novice
Joined: 08 Jan 2016 Posts: 21
|
Hi Maurito,
I'm planning to do it in Custom esql. But I'm thinking it is long process to do for all fields.
Can you suggest me what are the other possible ways to do this.
Thanks  |
|
Back to top |
|
 |
maurito |
Posted: Mon Jan 25, 2016 5:17 am Post subject: |
|
|
Partisan
Joined: 17 Apr 2014 Posts: 358
|
6FA wrote: |
Hi Maurito,
I'm planning to do it in Custom esql. But I'm thinking it is long process to do for all fields.
Can you suggest me what are the other possible ways to do this.
Thanks  |
Have you tried anything else ? |
|
Back to top |
|
 |
6FA |
Posted: Mon Jan 25, 2016 5:36 am Post subject: |
|
|
Novice
Joined: 08 Jan 2016 Posts: 21
|
No.
I tried looking into the possible functions in mapping node. But I didn't get anything.
Thanks  |
|
Back to top |
|
 |
mqjeff |
Posted: Mon Jan 25, 2016 6:13 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
So, if you put the value - '' - in the field in the mapping function, then you get the value - '' - out in the message.
Are you sure that you want to put '' in the field in the mapping node?
Have you looked at the options available with the DFDL model to deal with missing or empty fields? _________________ chmod -R ugo-wx / |
|
Back to top |
|
 |
timber |
Posted: Mon Jan 25, 2016 6:14 am Post subject: |
|
|
 Grand Master
Joined: 25 Aug 2015 Posts: 1292
|
Quote: |
Here I have a requirement that, if the value in xml is empty(Like <name></name>) I need to pass empty value to csv file. |
So you want the XML value to be copied to the output. Have you tried the simple solution - just wiring the input element to the output element? If so, what happened?
Quote: |
In else statement I'm assigning hard value as '' |
Is that an empty string, or two quote characters? How would the XPath language interpret it? |
|
Back to top |
|
 |
6FA |
Posted: Mon Jan 25, 2016 7:16 am Post subject: |
|
|
Novice
Joined: 08 Jan 2016 Posts: 21
|
Quote: |
So you want the XML value to be copied to the output. Have you tried the simple solution - just wiring the input element to the output element? If so, what happened? |
If I did like this Nothing coming out. output is like 1,16
But expected is 1,,16
Quote: |
Is that an empty string, or two quote characters? How would the XPath language interpret it? |
It is empty string(not '').[/quote] |
|
Back to top |
|
 |
fjb_saper |
Posted: Mon Jan 25, 2016 7:55 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
is the field mandatory?, Is it nillable?  _________________ MQ & Broker admin |
|
Back to top |
|
 |
timber |
Posted: Mon Jan 25, 2016 8:41 am Post subject: |
|
|
 Grand Master
Joined: 25 Aug 2015 Posts: 1292
|
Quote: |
If I did like this Nothing coming out. output is like 1,16 |
Aha!! In that case, I know what the problem is. Your DFDL model is instructing the parser to suppress delimiters for empty elements. For some users, that's what they want. For your data format it is incorrect.
Here's what you need to do:
- Open the DFDL editor
- Find the element that represents the 'name' in the output CSV.
- Click on the sequence group that it lives in
- Look at the DFDL properties on the right-hand side of the DFDL editor. One of them will be called ''Delimiter Suppression Policy'. You need to set this to 'Trailing Empty Lax'. Or maybe to 'Never' if you do not want trailing empty elements to be suppressed.
The only remaining puzzle is...how did you end up with this property set to the wrong value. The CSV wizard should set it correctly. |
|
Back to top |
|
 |
6FA |
Posted: Wed Jan 27, 2016 1:19 am Post subject: |
|
|
Novice
Joined: 08 Jan 2016 Posts: 21
|
Hi Timber,
Thank you very much. Its working.
Quote: |
Here's what you need to do:
- Open the DFDL editor
- Find the element that represents the 'name' in the output CSV.
- Click on the sequence group that it lives in
- Look at the DFDL properties on the right-hand side of the DFDL editor. One of them will be called ''Delimiter Suppression Policy'. You need to set this to 'Trailing Empty Lax'. Or maybe to 'Never' if you do not want trailing empty elements to be suppressed.
|
Thanks  |
|
Back to top |
|
 |
timber |
Posted: Wed Jan 27, 2016 5:23 am Post subject: |
|
|
 Grand Master
Joined: 25 Aug 2015 Posts: 1292
|
btw, your first question is quite interesting:
Quote: |
I'm converting msg from xml to csv using mapping node |
...because you are not really doing that at all.
You are mapping your input XML message tree to an output DFDL message tree using a Mapping node. The DFDL parser is converting OutputRoot.DFDL to a stream of bytes that represents a CSV document.
When using IIB, never forget that the parser is an integral part of the message flow. Input and output nodes read and create bitstreams. They use parsers to convert between bitstreams and trees. Other message flow nodes work only with message trees. |
|
Back to top |
|
 |
|