Author |
Message
|
protocol7 |
Posted: Sat Dec 27, 2003 6:01 am Post subject: TDS: keeping null fields in the logical tree |
|
|
Novice
Joined: 27 Nov 2003 Posts: 13 Location: Göteborg, Sweden
|
I'm using TDS to parse a semi-colon delimited format, e.g:
field1;field2;field3
My problem is that fields can be empty, e.g:
field1;;field3
and the sequence and numbering of the fields is crucial for me. The parser will (correctly) threat the empty field as a null field and not create a node in the logical tree. But, in my ESQL I need to check the values of field based on their position (e.g. the second field) in the original file. This is currently impossible since there won't be any node created for the second field and the second node in the logical tree will actually contain the value of the third field.
Is there any way to configure the parser to create a node in the logical tree for an empty field? The node could for example contain an empty string.
Many thanks!
Niklas |
|
Back to top |
|
 |
jefflowrey |
Posted: Sat Dec 27, 2003 7:50 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
Have you looked at default value constraints? Have you looked at the Null handling properties of elements?
Have you looked in the Working With Messages manual for information on working with null fields? _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
protocol7 |
Posted: Sat Dec 27, 2003 8:06 am Post subject: |
|
|
Novice
Joined: 27 Nov 2003 Posts: 13 Location: Göteborg, Sweden
|
I have looked at default values, but for elements this is only used if the node exists but is empty. However, I just read that for attributes the node should be created. I will go ahead and see if that might solve the problem.
I also read the manual on null handling options and tried to configure the null handling to both NULLLogicalValue and NULLLiteralValue but with no luck. I didn't find anything else in the manual that helped me. I'm sure I'm missing something obvious so if I'm happy for any help!
Niklas |
|
Back to top |
|
 |
protocol7 |
Posted: Sat Dec 27, 2003 8:16 am Post subject: |
|
|
Novice
Joined: 27 Nov 2003 Posts: 13 Location: Göteborg, Sweden
|
I just tried using attributes but they are not allowed in All fields delimited TDS definitions.
Niklas |
|
Back to top |
|
 |
jefflowrey |
Posted: Sun Dec 28, 2003 6:48 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
Sorry. I forgot that the Null handling stuff is for defining what characteristics of the physical message result in a Logical Null.
You should be able to use the FIELDNAME function to figure out if you're accessing the right field or otherwise preserve the right field when you're accessing the children by position.
Or, of course, you could just not access them by position, instead access them by name. Then you could directly check if Field2 is NULL, or whatever, without worrying if FIELDNAME(ParentField.*[2]) = 'Field2'. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
protocol7 |
Posted: Sun Dec 28, 2003 7:02 am Post subject: |
|
|
Novice
Joined: 27 Nov 2003 Posts: 13 Location: Göteborg, Sweden
|
Yeap, the reason why I'm accessing the nodes by position is that I also get a list of what fields have changed, as a list of positions. I'm only interested in the values that has changed. So I start of with reading the positions that have changed and then try to get the values for those fields by position. This fails now since the list of nodes is shifted as soon as there is a null field. I could keep a table that maps field names to positions in my ESQL but I would not like to since I want someone to makes changes to the message set only when the format is changed. The ESQL should not have to updated.
The fix I can think of now is to pre-process the incoming data and insert a space in the empty field. This way the parser will keep the node. But I can't belive that there isn't a more clever way of configuring the parser to keep empty nodes. |
|
Back to top |
|
 |
kimbert |
Posted: Tue Dec 30, 2003 12:34 pm Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Are you sure that the Null Handling facilities cannot be used here?
You should be able to get a syntax element in the tree, with the value 'null'. (which is not the same as a null syntax element!). To do this, go to the TDS properties of the element, and set the property 'Encodng Null' to 'NullLiteralValue' and the property 'Encoding Null Value' to the empty string.
If this works, you should be able to access all the nodes by position with no problems. |
|
Back to top |
|
 |
protocol7 |
Posted: Tue Dec 30, 2003 3:38 pm Post subject: |
|
|
Novice
Joined: 27 Nov 2003 Posts: 13 Location: Göteborg, Sweden
|
I've tried using that option but I simply fail to get it working :-/
I've uploaded a minimal implementation for WBIMB 5.0.2 that fails at http://www.protocol7.com/lab/nulltest.zip (Flow and MessageSet projects).
If anyone got some time to take a look at my example and see if you can find any problem I would be ever thankful!
Niklas |
|
Back to top |
|
 |
kimbert |
Posted: Mon Jan 05, 2004 3:10 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
I took a look at your message set. You need to set the 'Nillable' flag on the logical properties as well. Let me know if that works. |
|
Back to top |
|
 |
protocol7 |
Posted: Mon Jan 05, 2004 5:58 am Post subject: |
|
|
Novice
Joined: 27 Nov 2003 Posts: 13 Location: Göteborg, Sweden
|
Perfect! Thanks, that works like a charm.
/niklas |
|
Back to top |
|
 |
|