好网站建设公司,中国建设银行网站暑假工报名,hao123主页官网,阳江打卡网红店最近一直和infopath表单打交道#xff0c;碰到的问题也比较多#xff0c;刚刚就碰到一个在程序中修改infopath表单中域的内容时出错的问题#xff0c;写出来与大家共享一下#xff0c;我想这个问题#xff0c;可能玩infopath的话#xff0c;迟早会碰上的吧。具体表现就是…最近一直和infopath表单打交道碰到的问题也比较多刚刚就碰到一个在程序中修改infopath表单中域的内容时出错的问题写出来与大家共享一下我想这个问题可能玩infopath的话迟早会碰上的吧。 具体表现就是在代码中对一些值类型的域进行更改的时候代码报错出错信息Schema validation found non-data type errors. 小弟对xml schema真的不是很了解所以找了半天最后总算在infopath team blog上找到标准答案 文章地址http://blogs.msdn.com/infopath/archive/2006/11/28/the-xsi-nil-attribute.aspx xsi:nil属性你是否曾经在程序中设置域值时碰到schema valiadation错误很多时候这个错误的原因是节点定义了“nillable”属性. Nillable属性是一个特殊的属性,它能出现在一个XML schema的 xsd:elment中.如果一个元素定义了xsi:nil属性,意味着这个元素被定义了,但是没有值因此它是没有内容的。 然而如果你试图在程序中给一个定义了nillable属性的节点设置值你会得到一个错误信息“Schema validation found non-data type errors.”。你可能会发现nillable属性常被定义在下面几种数据类型上 Whole Number (integer) Decimal (double) Date (date) Time (time) Date and Time (dateTime) 要解决这个问题你的代码需要先检测nil属性是否被定义了。如果定义了那需要在给节点设置值之前移除这个属性。下面这段简单的程序使用一个XpathNavigator类检查节点的node是否有nil属性。如果存在则删除掉。 public void DeleteNil(XPathNavigator node){if (node.MoveToAttribute(nil, http://www.w3.org/2001/XMLSchema-instance)) node.DeleteSelf();} 上面这段代码是通用的你能很简单的调用这段代码在你需要编程改变一个域的值之前。下面是一个例子这段代码被一个按钮的click事件调用。 //Create a Navigator object for the main data source// 为主数据源创建一个Navigator对象XPathNavigator xn this.MainDataSource.CreateNavigator();//Create a navigator object for the field (node) //where we want to set the current date value// 为你要设置当前日期值的一个域节点创建一个navigator对象XPathNavigator xnfield1 xn.SelectSingleNode(/my:myFields/my:field1, this.NamespaceManager);//Check if the nil attribute exists on this node// 检查节点是否存在 “nil”属性DeleteNil(xnfield1);//Create a new dateTime object for the current date// 创建一个包含当前日期的新的dateTime对象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// 设置field1的值为使用”yyyy-mm-dd”格式的当前日期xnfield1.SetValue(curDate.GetDateTimeFormats().GetValue(5).ToString()); 转载于:https://www.cnblogs.com/pengyuan512/archive/2008/06/24/1228947.html