can't insert nil attribute in web based form... - InfoPath Dev
in

InfoPath Dev

can't insert nil attribute in web based form...

Last post 04-08-2013 08:54 AM by Poolio. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 09-15-2008 11:03 PM

    can't insert nil attribute in web based form...

    hello everybody, i try to clear double typed field, i've used next instructions,

                if (!node.MoveToAttribute("nil", ""))
                {    
                    node.CreateAttribute("xsi", "nil", node.NamespaceURI, "true");                
                }

                node.SetValue("");

    in the client infopath application it works fine, but when form is opened in a web browser it shows me error message:"Schema validation found non-datatype errors."

    Does anyone know why it happens? thanks.

    ps: InfoPath 2007 and c#

     

  • 03-02-2010 09:42 AM In reply to

    Re: can't insert nil attribute in web based form...

    Hi!

    This is an extremely late response to this, but I recently ran into this myself.

    After talking to some folks at Microsoft, here is the problem and the solution:

    Basically, there are differences in the way MSXML (InfoPath client XML library) and System.Xml (IPFS XML library) are validating the XML against the schema. After executing the SetValue() method, System.Xml recognizes the empty text node as a child of the “my:file” node. As such, a validation error occurs when you attempt to reapply the ‘nil’ attribute. The following code will succeed on the client and server:  
    XPathNavigator file = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:file", NamespaceManager);
     
    if (null != file && !file.Value.Equals(String.Empty))
    {
    //clear node
    file.MoveToFirstChild();
    file.DeleteSelf();
    //add nil attribute
    file.CreateAttribute("xsi", "nil", "http://www.w3.org/2001/XMLSchema-instance", "true");
     
    }
    Hilary Stoupa

  • 10-05-2010 10:35 AM In reply to

    Re: can't insert nil attribute in web based form...

    Thanks for posting the fix on here. I wonder if you wouldn't mind elaborating however on why this works. I've been trying the obvious: node.SetValue(string.Empty); node.CreateAttribute("xsi", "nil", "http://www.w3.org/2001/XMLSchema-instance", "true"); and getting the schema validation error when running in a browser. Following the example you posted I now try node.SetValue(string.Empty); node.MoveToFirstChild(); node.DeleteSelf(); node.CreateAttribute("xsi", "nil", "http://www.w3.org/2001/XMLSchema-instance", "true"); and this works! I'm trying to figure out why. The MoveToFirstChild selects whitespace as a node. Is this whitespace a side effect of when I originally delete the nil attribute? Is it this whitespace which System.Xml thinks is a node and different to the schema?
  • 04-08-2013 08:54 AM In reply to

    • Poolio
    • Not Ranked
    • Joined on 01-25-2013
    • Posts 2

    Re: can't insert nil attribute in web based form...

    Hi there,

    I've been battling with passing null values on boolean fields to a web service, and this exchange seemed so promising... but unfortunately I'm still stuck! This is what I'm doing:

    Node.SetValue(string.Empty);
    Node.MoveToFirstChild();
    Node.DeleteSelf();
    Node.CreateAttribute("xsi", "nil", System.Xml.Schema.XmlSchema.InstanceNamespace, "true");

    In some cases the node had more than one child, but made sure they were all deleted;
    For the namespace, I tried explicitly using "http://www.w3.org/2001/XMLSchema-instance", using InstanceNamespace as above, and also node.NamespaceName - none made a difference

    Does anybody have any other ideas about what could be stopping this working?

    As a different approach I've tried replacing the entire node, e.g.

    Node.ReplaceSelf(string.Format("<{0} xsi:nil='true'/>", Node.Name));

    But that results in the error "'xsi' is an undeclared prefix"

    Starting to lose the will to live, and much to the chagrin of my data and .Net-focused colleagues, considering setting all the web service fields to strings just so InfoPath can handle them... which is not a great story!

     Thanks,
    Poolio

Page 1 of 1 (4 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.