1

I have nillable decimal element defined in xsd schema like this:

<xs:element name="myDecimalValue" nillable="true" type="xs:decimal" /> 

This is distinguished field and I want to check if it is nill in expression shape. I could use xpath() function like this:

xpath("string(//*[local-name()='myDecimalValue']/@*[local-name()='nil'])") == "true"

But it looks a little bit complicated for simple null-checking. So I'm wondering if I'm missing something and there is better way to do it?

oderibas
  • 1,575
  • 12
  • 20

2 Answers2

0

you can try to use a decide shape instead of the xpath

your decide shape will lok like this just ask if myDecimalValue is null

 msgName.myDecimalValue != null here

than you can continue your logic

if you using a distinguished field use it its more readable for other dev

EDIT:

can you try
varString = System.Convert.ToString(msgName.myDecimalValue);

and then ask if varString is null or not

i tried it and it compile well

hopes it help :)

MIkCode
  • 2,655
  • 5
  • 28
  • 46
  • You can't compare decimal and null. You'll get this error: `operator '!=' cannot be applied to operands of type 'System.Decimal' and 'null'` – oderibas Apr 23 '12 at 11:03
  • 1
    This won't work either. Because msgName.myDecimalValue is of type System.Decimal and not System.Nullable - there is no way System.Convert.ToString() would return null. – oderibas Apr 25 '12 at 15:02
0

I have a suspicion that this can't be achieved.

Specifically, from http://support.microsoft.com/kb/942250

Properties that have a null value are not permitted in the message context. Therefore, if a null value is written into the message context, this value will be deleted.

(this is in the document section relating to Promoted and Distinguished properties, so I am assuming it is applicable to both).

So it looks like your xpath solution might be the required solution, as the distinguished property won't be in the message context anyway.

StuartLC
  • 104,537
  • 17
  • 209
  • 285
  • I think this is applicable only to promoted properties. Distinguished properties are not written into message context, so null values are permitted. But anyway, looks like xpath is the only way to go here. – oderibas Jan 16 '13 at 09:09
  • Related to this, recently had a case where a Distinguished field was omitted *entirely* on an incoming multipart message. An expression shape which attempted to evaluate it (msg.Part.DistinguishedField) gave a Null Reference Exception. So yes, xpath is indeed safest, unless it is also validated or pre-parsed through a map/xslt to ensure the field is correct as expected. – StuartLC Jan 16 '13 at 09:17