Infopath XPathNavigator


Infopath XPathNavigator

Working with XML Data Using the XPathNavigator Class http://msdn.microsoft.com/en-us/library/bb509311(v=office.12).aspx

Setting the Value of a Node That Has the xsi:nil Attribute

For certain data types, trying to set the value of a blank field programmatically raises the error “Schema validation found non-data type errors.” Typically the cause of this error is that the element has the xsi:nil attribute set to true. If you examine the underlying XML element for the blank field in the form, you can see this setting. For example, the XML fragment for the following blank Date field has the xsi:nil attribute set to true.

If the xsi:nil attribute is set to true, it indicates that the element is present but has no value, or in other words, is null. If you try to programmatically set the value of such a node, InfoPath displays the “Schema validation found non-data type errors” message because the element is currently flagged as being null. InfoPath sets the xsi:nil attribute to truefor null fields of the following data types:

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

To prevent this error, your code must test for the xsi:nil attribute, and if it is present, remove it before setting the value of the node. The following subroutine takes anXpathNavigator object positioned on the node you want to set, checks for the nilattribute, and then deletes it, if it exists.

public void DeleteNil(XPathNavigator node)
{
   if (node.MoveToAttribute(
      "nil", "http://www.w3.org/2001/XMLSchema-instance"))
      node.DeleteSelf();
}
Advertisements

About sharepointsriram

9+ Yrs of IT experience
This entry was posted in Sharepoint 2010 Infopath. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s