how to add xsi:nil = "true" attribute - InfoPath Dev

InfoPath Dev

Use our Google Custom Search for best site search results.

how to add xsi:nil = "true" attribute

Last post 06-04-2013 04:00 AM by aurel33380. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 05-10-2010 08:51 AM

    how to add xsi:nil = "true" attribute

    Hello everyone,

     I have been trying for days now, to figure out but nothing id working :(

    i am writing some code on changed event  to check the content of one of my fields in infopath, if the field contains anything (int in this case), then I display a message that the field must be blank and then I want to delete that content. I gues I have to add the xsi:nil = "true" attribute?! which I do not know how....I tried SetValue("") but that is considered a string and since my field is an int, it does not like. Can anyone PLEASE help me on how to add this attribute or if there is anyother way to make this field blank. I will GREATLY appreciate it. Thanks.

    here is my attempted code:

    public void TOTAL_LENGTH_1MM_Changed(object sender, XmlEventArgs e)



    XPathNavigator TOTAL_LENGTH_1MM = MainDataSource.CreateNavigator();

    TOTAL_LENGTH_1MM = TOTAL_LENGTH_1MM.SelectSingleNode("/my:myFFIM_base_table/my:Species_Records/my:SpeciesGroup/my:GROUP_1MM/my:GROUP_1MM_sub/my:TOTAL_LENGTH_1MM", NamespaceManager);

    XPathNavigator SPECIES_ID = MainDataSource.CreateNavigator();SPECIES_ID = SPECIES_ID.SelectSingleNode("/my:myFFIM_base_table/my:Species_Records/my:SpeciesGroup/my:SPECIES_ID", NamespaceManager);


    if (SPECIES_ID.ToString() == "999990" && TOTAL_LENGTH_1MM.ToString() != "")


    MessageBox.Show("NOSP (No fish collected) was indicated. Length should be BLANK.");

    TOTAL_LENGTH_1MM.SetValue("");// this obviously did not work






  • 05-10-2010 09:26 AM In reply to

    Re: how to add xsi:nil = "true" attribute


    TOTAL_LENGTH_1MM.CreateAttribute("xsi", "nil", System.Xml.Schema.XmlSchema.InstanceNamespace, "true");


    Edit: Changed LookupNamespace() function to constant reference - same behavior but this is a better practice.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 05-10-2010 10:08 AM In reply to

    Re: how to add xsi:nil = "true" attribute


    Thank you for the quick response Jimmy. I added TOTAL_LENGTH_1MM.CreateAttribute("xsi", "nil", NamespaceManager.LookupNamespace("xsi"), "true"); to my code, but now I am getting this message

      System.InvalidOperationException was unhandled by user code
      Message="Schema validation found non-data type errors."

    any idea what this is about ?? (I tried 'googling' it, but I did not find anything useful). Thanks again!

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

    Re: how to add xsi:nil = "true" attribute

     Did you remove the line to make the node blank? It has to be blank before you add the nil attribute.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 05-10-2010 10:21 AM In reply to

    Re: how to add xsi:nil = "true" attribute

    that was it. THANK YOU very much!!! it WORKS!!!

  • 06-04-2013 04:00 AM In reply to

    Re: how to add xsi:nil = "true" attribute

     Please please i need help, this code doesn't work properly, i don't know how to write code for xsi:


    XPathNavigator nav = MainDataSource.CreateNavigator()




    nav.SelectSingleNode("//my:NewjoueurDatedenaissance", NamespaceManager).SetValue(string.Empty);

    nav.SelectSingleNode("//my:NewjoueurDatedenaissance", NamespaceManager).CreateAttribute("xsi", "nil", NamespaceManager.LookupNamespace("xsi"), "true");



    very thank's for helping. And sorry for my english




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