Writing a spyke for a simple program, I came out with this odd behavior when I try to compile my BizTalk project.
I have created a simple schema, and in one of the fields I have field of type xs:dateTime. Well, when I have tried to use this field on an expression shape, I get this build compiler error:
'System.Xml.XmlDocument' does not contain a definition for 'XXXX'
where XXXX is the field name of the element that I have declared as a xs:dateTime type. I then went and set it up as a distinguished field. Here is a sample generated xml from my test schema:
<ns0:Customer xmlns:ns0="http://DistingProperty.Test.Customer.v1">
<FName>FName_0</FName>
<DOB_datetime>1999-05-31T13:20:00.000-05:00</DOB_datetime>
<DOB_date>1999-05-31</DOB_date>
</ns0:Customer>
and this is the schema that I have used
When I am trying to use the distinguished field inside an expression shape, noticed that I get the Visual Studio IntelliSense:
When you try to read this value, it will always complain about the XmlDocument not being able to find the definition for the field that is defined as DateTime.
To get around this, you should use the System.Convert.ToString() instead of the .ToString() function;
1 Trace.WriteLine(" bad:[" + msgIN.DOB_datetime.ToString() + "]");
2 Trace.WriteLine("good:[" + System.Convert.ToString(msgIN.DOB_datetime) + "]");
Another lengthy way to get around this issue is to assign the distinguish field to an xmlNode and then use the xml Namespace Manager to get to the node value instead.
The code on my expression shape looks like this:
1 System.Diagnostics.Trace.WriteLine("bts- In here");
23 //assign values to person
4 xDoc = msgIN;5
6 xmlnsMgr = new System.Xml.XmlNamespaceManager(xDoc.NameTable);7 xmlnsMgr.AddNamespace("ns0", "http://DistingProperty.Test.Customer.v1");
89 xNode = xDoc.SelectSingleNode("/ns0:Customer/DOB_datetime", xmlnsMgr);
10 System.Diagnostics.Trace.WriteLine("bts-[" + xNode.OuterXml + "]");11
12 xNode = xDoc.SelectSingleNode("/ns0:Customer/DOB_date", xmlnsMgr);13 System.Diagnostics.Trace.WriteLine("bts-[" + xNode.OuterXml + "]");
1415 //this works as expected
16 System.Diagnostics.Trace.WriteLine("bts- " + msgIN.FName);17
Which ever way you choose, this looks like a limitation on the way the XLANG/s in the Expression shape interprets the command code.