Author |
Message
|
Cubersome |
Posted: Tue Nov 11, 2014 12:07 pm Post subject: DFDL Parsing - \r Issue |
|
|
Apprentice
Joined: 02 Mar 2012 Posts: 37
|
Hi,
I am using DFDL parser to parse the below format.
A
B
C
D
E
The terminator for each line is <CR><LF>.
The above record is getting parsed correctly but in the debugger "\r" is coming at the end of each field value like
A\r
B\r
C\r etc and when I am putting the entire record in XMLNSC format it is creating like
<Record>
<Tag1>A.</Tag1>
<Tag2>B.</Tag2>
etc.
Please advice why carriage return is including the field value and how to eliminate that.
I am using Broker 8.0.02 on windows. |
|
Back to top |
|
 |
kimbert |
Posted: Tue Nov 11, 2014 12:13 pm Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
I can guess this one, I think.
Each line in your data ends with a carriage return (0x0D) and a line feed (0x0A). I bet you have set the terminator ( or separator ) to either %LF; or %#x0A. In other words, a linefeed. So the value of each delimited field includes the carriage return ( represented as '\r' to make it visible ). _________________ 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 |
|
 |
Cubersome |
Posted: Tue Nov 11, 2014 12:23 pm Post subject: |
|
|
Apprentice
Joined: 02 Mar 2012 Posts: 37
|
I put the Terminator as {$dfdl:outputNewLine}.
Do we have anyway to make it invisible and not to output in XML data.? |
|
Back to top |
|
 |
kimbert |
Posted: Tue Nov 11, 2014 12:31 pm Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Quote: |
I put the Terminator as {$dfdl:outputNewLine} |
Two questions:
1. Why did you do this?
2. What is the actual value of $dfdl:outputNewLine?
Quote: |
Do we have anyway to make it invisible and not to output in XML data.? |
I think you have missed the point.
Your XML is wrong because your message flow gave an incorrect message tree to the XMLNSC parser.
This happened because your input data was parsed incorrectly.
That happened because your DFDL model is wrong.
So you need to fix your DFDL model. Set the terminator correctly, and then the carriage returns will not be in the message tree, and the XML will not contain funny-looking characters. _________________ 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 |
|
 |
Cubersome |
Posted: Fri Jan 30, 2015 7:24 am Post subject: |
|
|
Apprentice
Joined: 02 Mar 2012 Posts: 37
|
Hi Kimbert,
Thanks a lot for your help. Terminator issue was resolved.
I am facing a new issue with the validation.
My Input file will have many records and 5 records will make one logical record.
A
B
C
D
E
I created a DFDL parser to parse 5 records to create a message.I want to validate the 5th record which always starts with "email". Now I want to put a validation if the 5th record does not start with "email"- DFDL should give a parse error. How can we achive this??
I created a pattern for the word "email"..but it is not working..
Can you please throw some light on this??? |
|
Back to top |
|
 |
kimbert |
Posted: Sun Feb 01, 2015 2:20 pm Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Please post an example of your input message.
You should also read the DFDL specification. Guessing is not a good strategy when it comes to programming . _________________ 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 |
|
 |
fjb_saper |
Posted: Sun Feb 01, 2015 4:04 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Did you try any assertions?  _________________ MQ & Broker admin |
|
Back to top |
|
 |
Cubersome |
Posted: Mon Feb 02, 2015 8:55 am Post subject: |
|
|
Apprentice
Joined: 02 Mar 2012 Posts: 37
|
Hi Kimbert,
Below is the correct input message
12345678
2
XXXX
2014-05-06
email:abc@xyz.com
456789
56
YYYYYYYY
2014-10-10
email:xyz@abc.com
89042532ABC
34566
ZZZZZZZZZZ
2014-01-01
email:aertwt@abc.com
I created a DFDL for parsing the above file. Suppose if one of the records is missing, it is creating 5 records as message which is correct according to the definition. But instead of creating a message it should throw an error when the 5th record does not start with word "email". |
|
Back to top |
|
 |
kimbert |
Posted: Tue Feb 03, 2015 6:19 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Set minOccurs to 1 on the 5th element, and set its initiator to 'email:'
Ideally, you should also tighten up the model when parsing the other 4 fields. It's hard to advise on how to do that without seeing a specification for the input file. If you leave them modeled as xs:string you will find that the parser will not invalid values, and it will report an error on a later field instead. That can be confusing for whoever maintains the application. _________________ 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 |
|
 |
Cubersome |
Posted: Tue Feb 03, 2015 6:30 am Post subject: |
|
|
Apprentice
Joined: 02 Mar 2012 Posts: 37
|
Hi Kimbert,
If I am setting the initiator to "email:" it is taking the rest of the value into that field leaving the word "email:".
I want the full text into the 5th element including the word "email:". |
|
Back to top |
|
 |
Vitor |
Posted: Tue Feb 03, 2015 6:40 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
Cubersome wrote: |
I want the full text into the 5th element including the word "email:". |
Which you're unable to concatenate to the front of the resulting text value because......? _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
kimbert |
Posted: Tue Feb 03, 2015 6:41 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Quote: |
I want the full text into the 5th element including the word "email:".
|
In that case you need to add a DFDL discriminator to the 5th element. The discriminator expression is an XPath that returns a Boolean result. Set the expression to {fn:starts-with(., 'email:')}
btw, why do you need the 'email:' in the message tree? Are you writing the value to an XML file? _________________ 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 |
|
 |
Cubersome |
Posted: Tue Feb 03, 2015 6:57 am Post subject: |
|
|
Apprentice
Joined: 02 Mar 2012 Posts: 37
|
Hi Vitor,
We are building a framework and we dont want to code explicitly for that input file. We want everything in configurable parameters.
Hi Kimbert,
I already tried putting a assertion on 5th element with fn:starts-with(5thelement path,'email:')..but the issue with that - it is always taking the first occurrence and I want to do it for all elements. I am not able to set the dynamic array index for that element occurrence.
Yes we are writing the entire message tree as an XML file. |
|
Back to top |
|
 |
kimbert |
Posted: Tue Feb 03, 2015 7:55 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Quote: |
We are building a framework and we dont want to code explicitly for that input file. |
You cannot have both flexibility and error detection. You will need to choose one or the other. This is not a DFDL problem - you would end up making the same decisions regardless of your parsing/transformation technology. _________________ 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 |
|
 |
maurito |
Posted: Tue Feb 03, 2015 8:28 pm Post subject: |
|
|
Partisan
Joined: 17 Apr 2014 Posts: 358
|
Define a DFDL unbounded array containing 5 fields, with the 5th element having the assert/discriminator. That way the assert/discriminator will apply to every 5th element. |
|
Back to top |
|
 |
|