How to solve an error when setting integer or other domain values in infopath in a program

Source: Internet
Author: User
I have been dealing with infopath forms recently and have encountered many problems. Program An error occurred when modifying the field content in the infopath form. Write it out and share it with you. I think this problem may happen sooner or later if you play infopath.
Specifically Code When changing some value-type fields, the Code reports an error. error message :" Schema validation found non-data type errors. "
I really don't know much about XML schema, so after searching for half a day, I finally found the standard answer on the infopath team blog.
Article Address: http://blogs.msdn.com/infopath/archive/2006/11/28/the-xsi-nil-attribute.aspx

Xsi: NilAttribute

Have you ever encounteredSchema valiadationError? This error is often caused by the node definition."Nillable"Attribute. NillableA property is a special property.,It can appear inXML SchemaOfXSD: elmentMedium.If an element definesXsi: NilAttribute,This element is defined.,But there is no value, so it has no content.

However, if you try to set a value for a node that defines the nillable attribute in the program, you will get an error message: "schema validation found non-data type errors .". You may find that the nillable attribute is often defined on the following data types:

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

To solve this problem, your code needs to be checked firstNilWhether the attribute is defined. If this attribute is defined, you need to remove this attribute before setting a value for the node. The following simple program usesXpathnavigatorClass, check the node'sNodeYesNilAttribute. If yes, delete it.

Public   Void Deletenil (xpathnavigator node)
{
If(Node. movetoattribute ("Nil","Http://www.w3.org/2001/XMLSchema-instance"))
Node. deleteself ();
}

The above code is generic, and you can easily call this code before you need to program to change the value of a domain. The following is an example. This code is called by the Click Event of a button.

// Create a navigator object for the main data source
// Create a navigator object for the primary data source
Xpathnavigator XN =   This . Maindatasource. createnavigator ();

// Create a navigator object for the field (node)
// Where we want to set the current date value
// Create a navigator object for a domain (node) that you 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
// Check whether the node has the "nil" attribute
Deletenil (xnfield1 );

// Create a new datetime object for the current date
// Create a new datetime object containing 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
// Correct format: yyyy-mm-dd
// Set the value of field1 to the current date in "yyyy-mm-dd" format.
Xnfield1.setvalue (curdate. getdatetimeformats (). getvalue ( 5 ). Tostring ());

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.