Author |
Message
|
Thomas2ab |
Posted: Wed Sep 03, 2014 6:20 am Post subject: DFDL - Datetime to String format |
|
|
Acolyte
Joined: 07 Mar 2014 Posts: 51
|
Hi everyone,
I would like to know if it exists in the DFDL transformation, a property that would allow me to transform an income dateTime (the xsd format like YYYY-MM-DD'T'HH:MM:SS) to a String with the following format:YYYMMDD
Is there a property that might do that easily?
Thanks!!
Regards, |
|
Back to top |
|
 |
Vitor |
Posted: Wed Sep 03, 2014 6:24 am Post subject: Re: DFDL - Datetime to String format |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
Thomas2ab wrote: |
I would like to know if it exists in the DFDL transformation, a property that would allow me to transform an income dateTime (the xsd format like YYYY-MM-DD'T'HH:MM:SS) to a String with the following format:YYYMMDD |
DFDL is a descritption language not a transformation language.
If the input is YYYY-MM-DD'T'HH:MM:SS then you want DFDL to parse it as such.
Once parsed and held in the message tree as a dateTime you can then manipulate it any way you want, and such manipulation is probably easiest if it's a dateTime not a string.
If you want to (for example) manipulate it into a YYYYMMDD string for output both the ESQL and Graphical tools within WMB/IIB offer simple methods of doing this. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
Thomas2ab |
Posted: Wed Sep 03, 2014 7:28 am Post subject: |
|
|
Acolyte
Joined: 07 Mar 2014 Posts: 51
|
Thaks Vitor I understood.
Via graphica mapping node, do you know if there isa way to cast and set a format?
Thanks!
Regards, |
|
Back to top |
|
 |
fjb_saper |
Posted: Wed Sep 03, 2014 7:31 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
you should not need to. Parse it via the xsd as the corresponding format (date, time, timestamp) and map it as the same type. In DFDL just set up the corresponding output format.
Then map from input to output using the graphical mapper...
Have fun  _________________ MQ & Broker admin |
|
Back to top |
|
 |
Vitor |
Posted: Wed Sep 03, 2014 7:35 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
Thomas2ab wrote: |
Via graphica mapping node, do you know if there isa way to cast and set a format? |
Yes there is. There's actually 2 I can think of and may be more. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
Thomas2ab |
Posted: Wed Sep 03, 2014 9:23 am Post subject: |
|
|
Acolyte
Joined: 07 Mar 2014 Posts: 51
|
That is great then thank you.
Just to precise I am using WMB 8.0.0.4
Thanks,
Regards, |
|
Back to top |
|
 |
kimbert |
Posted: Wed Sep 03, 2014 11:53 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Is the incoming dateTime value in an XML document? If so, just set the 'Build tree using XML Schema' property ( on the input node, assuming that you are using XMLNSC) so that it gets added to the message tree as an ESQL TIMESTAMP. Then just set the 'textCalendarPattern' property on the appropriate field in DFDL xsd to ensure that it gets written in the required format. _________________ Before you criticize someone, walk a mile in their shoes. That way you're a mile away, and you have their shoes too. |
|
Back to top |
|
 |
Thomas2ab |
Posted: Thu Sep 04, 2014 5:04 am Post subject: |
|
|
Acolyte
Joined: 07 Mar 2014 Posts: 51
|
Thanks Kimbert!
Yes it is a datetime coming from an XML Docuemnt, and yes we are using XMLNSC.
I could not find a lot of example on that textCalendarPattern property on the internet.
Could you give me an example on how to use it?
Furthermore, in my dfdl schema definition, should I define that field as String or dateTime in the end?
Thanks again!
Regards |
|
Back to top |
|
 |
kimbert |
Posted: Thu Sep 04, 2014 6:06 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
First, add a Trace node to your flow and check that the the value in the message tree is a TIMESTAMP and not a CHARACTER.
In your DFDL schema this field should be a dateTime ( otherwise the DFDL editor will not allow you so set any calendar-related properties ).
re: how to set the pattern, see
http://www.ogf.org/dfdl/DFDL_1.0_Web/dfdl_13_11.html _________________ Before you criticize someone, walk a mile in their shoes. That way you're a mile away, and you have their shoes too. |
|
Back to top |
|
 |
Thomas2ab |
Posted: Mon Sep 08, 2014 2:33 pm Post subject: |
|
|
Acolyte
Joined: 07 Mar 2014 Posts: 51
|
Hello Kimber and thanks again.
The thing is that the rule is the following:
I am getting the xsd dateTime as input and the output should be a string with the following format YYYYDDMM.
[u]However[/u], when this value is not present in the input message, the output should be 8 spaces (' ').
So I used the following definition:
[code]<xsd:element minOccurs="1" maxOccurs="1" dfdl:length="8" dfdl:calendarPattern="YYYYMMDD" dfdl:lengthKind="explicit" dfdl:representation="text" dfdl:textPadKind="padChar" dfdl:textStringJustification="left" dfdl:textStringPadCharacter="%SP;" name="Date" type="xsd:dateTime"/>[/code]
However I got the errors that the textStringJustification is not a valid value for a dateTime field, which makes totally sense.
So my question is how could I 'mix' those rules? The date Pattern and the empty spaces in case it does not come in the input message.
Thanks again,
Regards, |
|
Back to top |
|
 |
fjb_saper |
Posted: Tue Sep 09, 2014 11:56 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Ass null value, null kind etc ... to your DFDL setup  _________________ MQ & Broker admin |
|
Back to top |
|
 |
Thomas2ab |
Posted: Tue Sep 09, 2014 3:52 pm Post subject: |
|
|
Acolyte
Joined: 07 Mar 2014 Posts: 51
|
Thanks fjb_saper, however I did not understand your answer...
Should I remove those properties? If so, how could I have the space and justification in case the input is not present?
Should I put null like this:
dfdl:textStringJustification=""
I am not sure it will work.
could you please explain me a bit more what you were meaning?
Thanks,
Regards |
|
Back to top |
|
 |
fjb_saper |
Posted: Wed Sep 10, 2014 3:12 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
If the element is not present but is mandatory you have to create it with a null value. DFDL will then serialize according to the null properties you set.
Have fun  _________________ MQ & Broker admin |
|
Back to top |
|
 |
kimbert |
Posted: Wed Sep 10, 2014 5:45 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Quote: |
However, when this value is not present in the input message, the output should be 8 spaces (' '). |
The answer depends on what you mean by 'not present'.
Do you mean
a) the field is present with an empty value or
b) the field is completely missing
Or, to put the question another way, what do you see in OutputRoot.DFDL. Is it
a) a CHARACTER element whose value is sometimes a date value and sometimes the empty string or
b) a TIMESTAMP element that is sometimes present and sometimes missing from the output tree
I think it is probably b). In which case, you should assign a default value of eight spaces to the element ( look in the 'Content' section in the DFDL properties ) and DFDL will write the default value when the field is missing. _________________ Before you criticize someone, walk a mile in their shoes. That way you're a mile away, and you have their shoes too. |
|
Back to top |
|
 |
Thomas2ab |
Posted: Wed Sep 10, 2014 3:28 pm Post subject: |
|
|
Acolyte
Joined: 07 Mar 2014 Posts: 51
|
Hello and thanks everyone.
@Kimbert:
What I mean by not present is that the xnl input field will be completely missing as in the xsd definition, this element is optional.
However, this means that in the output txt file I need to have 8 spaces (' ').
So, what I was wondering initially, is how can I define that field in the dfdl format?
Because I defined it like this:
Code: |
<xsd:element minOccurs="1" maxOccurs="1" dfdl:length="8" dfdl:calendarPattern="YYYYMMDD" dfdl:lengthKind="explicit" dfdl:representation="text" dfdl:textPadKind="padChar" dfdl:textStringJustification="left" dfdl:textStringPadCharacter="%SP;" name="Date" type="xsd:dateTime"/> |
But this doesn't work. It will work if I set the type as string but in this case the calendarPattern is useless and I don't know how I would transform the format in order to get either a YYYYMMDD value or 8 spaces value.
Thanks again,
Regards, |
|
Back to top |
|
 |
|