The xsi:nil attribute

Have you ever tried to programmatically set a value on a field only to get a “schema validation” error? Many times, this error is caused by the “nillable” attribute being present on the node. The nillable attribute is a special attribute that can appear on an xsd:element within an XML schema. If an element has the xsi:nil attribute specified, it indicates that the element is present but has no value, and therefore no content is associated with it.

However, if you attempt to programmatically set a value on this node and the nillable attribute is present, you will get an error similar to: “Schema validation found non-data type errors.” You will find the nillable attribute is typically present on the following data types:

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

To resolve this error, your code will simply need to test if the nil attribute is present and if so, remove that attribute before setting the value on the node. The following sample procedure takes an XpathNavigator object, checks that node for the nil attribute and if it exists deletes the attribute:

public void DeleteNil(XPathNavigator node)


if (node.MoveToAttribute("nil", ""))



The above procedure is generic - you can easily call this procedure as needed before programmatically trying to set the value of a field. As an example, this code is called from the click event of a button:

//Create a Navigator object for the main data source

XPathNavigator xn = this.MainDataSource.CreateNavigator();


//Create a navigator object for the field (node)

//where we want to set the current date value

XPathNavigator xnfield1 = xn.SelectSingleNode("/my:myFields/my:field1", this.NamespaceManager);


//Check if the "nil" attribute exists on this node



//Create a new dateTime object for the current date

DateTime curDate = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day);


//Set the value of field1 to the current date in the

//correct format: yyyy-mm-dd


Scott Heim
Support Engineer

Comments (12)
  1. I have been facing this error everytime I start an InfoPath project, and I keep forgetting the reason

  2. I have been facing this error everytime I start an InfoPath project, and I keep forgetting the reason

  3. BobC says:

    Why would you get this error during an AppendChild?  Is there any way to debug the problem?  If I take the same xml and manually append it to an existing form, then open the form, Infopath doesn’t complain.  Only in code.

    Please help MSFT!

  4. infopath says:

    Hi BobC,

    What is the error you are getting with the xsi:nil attribute as in this sample?


  5. Bob_Chauvin says:

    I was trying to append a row to a repeating section, and got the error on the Append action.  Found that If I restructured the schema to have the repeating group within a group, and used the AddRow code from


  6. 最近一直和infopath表单打交道,碰到的问题也比较多,刚刚就碰到一个在程序中修改infopath表单中域的内容时出错的问题,写出来与大家共享一下,我想这个问题,可能玩infopath的话,迟早会碰…

  7. Boyan's blog says:

    If you try to programaticaly set/remove values of fields in InfoPath, you might have come across the

  8. samhuang says:

    I tried to add a new row at the end of a repeating table programmatically, and received the error after all.

    The elements of the row are not of any of the data types mentioned in this post, and none of them resulted with attribute of xsl:nil after modified by my program, so I don’t even know where I can apply the DeleteNil method to…How to fix this issue?

    Any idea is appreciated, thank you!

  9. infopath says:

    Hi samhuang,

    This error may be cause by the way in which you are appending the child via code. Can you provide me with an overview of your data structure and what code you are using to append the child row? (I know you are using the AppendChild method but what exactly are you passing to this method?)


  10. says:

    Wow … thanks much .. I thought I was going nutz!!!

    Much appreciated.

  11. Thank you for sharing.

    Great Post.

Comments are closed.

Skip to main content