Cannot add attribute - InfoPath Dev
in

InfoPath Dev

Cannot add attribute

Last post 05-08-2012 06:55 AM by jsherman. 6 replies.
Page 1 of 1 (7 items)
Sort Posts: Previous Next
  • 05-04-2012 12:28 PM

    Cannot add attribute

    Hello

      I am trying to create "IsDirty" logic for each field in my form. I want to create a sub-routine that will create an attribute on a field if it doesn't already exist and set the value to true.. I plan to call the sub on field change.. I keep getting schema validation errors as thought it had the nil attribute.. Can an attribute have an attribute?? Why would it be nil if I am supplying a value upon creation?? How do I add an attribute to a field via VB code?

    The code for thesub is below:

    Public Sub Dirty_Changed(ByVal sender As Object, ByVal e As XmlEventArgs)
       If Not Me.SQLLoadActive Then
         Dim dom As XPathNavigator = MainDataSource.CreateNavigator()
         Select Case dom.SelectSingleNode("/my:myFields/my:RequestInfo/my:RequestType", NamespaceManager).Value
           Case "Add"
           Case "Change"
             If e.NewValue <> e.OldValue Then
               e.Site.CreateAttribute(e.Site.Prefix, "IsDirty", NamespaceManager.LookupNamespace("my"), System.String.Empty)
               MessageBox.Show(e.Site.Name & " - " & e.OldValue & " - " & e.NewValue)
             End If
           Case "Obsolete"
         End Select
       End If
    End Sub

  • 05-05-2012 08:40 AM In reply to

    What is the actual error that you are getting?  Does your data source define RequestType as having an attribute named IsDirty?

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 05-07-2012 07:24 AM In reply to

    The error is

     Schema validation found non-data type errors.

    No the IsDirty attribute is not defined. I am attempting to add it to the data source only if a user changes the value within the field.. Essentially I am trying to make a per field IsDirty functionality.. Really in general I just want to know how to add an attribute that doe snot exist in the data source at run time via VB.net code...

  • 05-07-2012 09:09 AM In reply to

    InfoPath will produce an error like that if you try to add an XML node to the main data source that is not defined in the schema.  This has nothing to do with xsi:nil.

    If you're looking to set and retrieve metadata properties to arbitrary fields, perhaps the SetNamedNodeProperty/GetNamedNodeProperty API is the way to go:

    http://msdn.microsoft.com/en-us/library/microsoft.office.infopath.datasource.setnamednodeproperty.aspx

    http://msdn.microsoft.com/en-us/library/microsoft.office.infopath.datasource.getnamednodeproperty.aspx

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 05-07-2012 11:19 AM In reply to

    I just checked those out and I am pretty sure it will work great.. Thank you very much...

    Now perhaps you can assist with 1 more problem during this adventure.. How can I build a loop that will iterate through each field in the form??

  • 05-07-2012 10:25 PM In reply to

    I believe that MainDataSource.CreateNavigator.Select("//*[not(*)]") should provide you with an XPathNodeIterator that lists all of the leaf elements in the main data source.  It won't include attributes, but according to the documentation I linked you to, Get/SetNamedNodeProperty doesn't work on attributes.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 05-08-2012 06:55 AM In reply to

    I will try what you posted above for iterating through the datsource.. Thanks..

    As for your above solution.. I see it doesn't work on attributes but I was orignally trying to create an attribute on a field to store the info i needed to.. So instead of storing it in the attribute i am storing it in the node proerty for that field.. Seems like it should work well..

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