InfoPath Forms Code Error: Schema validation found non-data type errors

As per Microsoft InfoPath blog this error occurs when we are trying to set a nodes element value and the node has an xsi:null attribute. So, before setting any value check if the node has the xsi:nil attribute and if so delete that attribute. Belowcode snippe is from the same blog which can be used as a generic method before setting any value.

public void DeleteNil(XPathNavigator node)


if (node.MoveToAttribute(“nil”,”))



I had similar problem while appending rows to a repeating table using the XmlWriter in the code behind for an InfoPath Form. Unfortunately, the code snippet didn’t solved my problem. Examining the xml contained in the node using the innerxml property, I didn’t find any xsi:nil anywhere. However after struggling for 2 hours I was able to find the solution and this problem is specific to the repeating table.
The order in which we are appending the values in the code should be in the same order as is in the form design’s data source.

Below is a more detailed explanation. The repeating table in the InfoPath Form design was as follows:


commentTable being the root of the repeating table control. commentRow is the repeating table. The columns within a row are and its order is as show above: userID, commentText, occurrenceTime.

In the code behind of the form, I have my code as follows:

myRoot = MainDataSource.CreateNavigator();
node = myRoot.SelectSingleNode("/my:Main/my:commentTable", NamespaceManager);
using(XmlWriter writer = node.AppendChild())

writer.WriteStartElement("commentRow", myNamespace);
writer.WriteElementString("userID", myNamespace, "user id");
writer.WriteElementString("occurrenceTime", myNamespace, "12/20/08 10:00:00");
writer.WriteElementString("commentText", myNamespace, "test comment");


Everything looks perfect! Err… No!, the order in which I am writing the xml into the node is not in the correct sequence as it is in the InfoPath form design. In my code i am trying to write the ‘occurrenceTime’ before the ‘commentText’ which is not as per the design. So swapping it solved my problem. Though it is silly its important for the xml schema and that is the reason the schema validation fails.


20 thoughts on “InfoPath Forms Code Error: Schema validation found non-data type errors

  1. I kept having the validation error problem until I moved the applicable group under another dedicated group with nothing else in it.

    The group for the repeating table was at the same level as many other elements which would have been the problem.

    I therefore now have… /my:ReferralContact/my:grpContactTable/my:ContactHistory with only the relevant three fields within my:ContactHistory

  2. I am still getting the error! What am I doing wrong? I am copying data from a repeating table in the secondary data source to 3 repeating tables in the main data source. Right now I’m only working on the first.

    My repeating table (main ds) structure is
    /my:COBInquiry/my:group1/my:group2/my:field1 and


    public void DeleteNil(XPathNavigator node)
    if (node.MoveToAttribute(“nil”, “”))

    private void AddItem(string title, string displayname, XPathNodeIterator current)
    // Group1
    // Group2
    // Field1
    // Field2

    XPathNavigator main = MainDataSource.CreateNavigator();
    XPathNavigator nav = main.SelectSingleNode(“/my:COBInquiry/my:group1”, NamespaceManager);

    using (XmlWriter writer = nav.AppendChild())
    writer.WriteElementString(“field1”, title);
    writer.WriteElementString(“field2”, displayname);

    • You may try the following;

      string myNamespace = NamespaceManager.LookupNamespace(“my”); // “my” or whatever ns: you used in your form xml

      using (XmlWriter writer = nav.AppendChild())
      writer.WriteElementString(”field1″, myNamespace, title);
      writer.WriteElementString(”field2″, myNamespace ,displayname);

  3. hey, I am getting the same error but my scenario is different. I create the form with one template and then change the header of the actually xml to point to different template. This was working great till now, we had some major upgrade and added/removed few fields (we have done this in past and it worked) to the template. Is it the order of the field important inside the group (non-repeating)?

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s