Infopath 2007 Set xsi:nil on FormServices

In InfoPath 2007 the fields wich type is one of the following:

  • Whole Number (integer)
  • Decimal (double)
  • Date (date)
  • Time (time)
  • Date and Time (dateTime)

If you try to set that field value programaticaly without clearing the xsi:nil attribute you will get an “Schema validation found non-data type errors.”

For more information: http://blogs.msdn.com/infopath/archive/2006/11/28/the-xsi-nil-attribute.aspx

But if you want to later clear that field value you will need to set the xsi:nil attribute back to true.

If you try to create the attribute using the CreateAttribute, it works on the full client but it wont work on the Sharepoint Forms Server.

The only way that I found to make this work in a “clean” way was like this:

XPathNavigator nodeToClear = xDoc.SelectSingleNode(“xpathtonode”, this.NamespaceManager);

nodeToClear.ReplaceSelf(string.Format("<{0} xsi:nil=’true’/>", nodeToClear.Name));

Hope it helps…