XPath Issue - MoveToChild() Doesn't Seem To Work - InfoPath Dev
in

InfoPath Dev

XPath Issue - MoveToChild() Doesn't Seem To Work

Last post 04-11-2013 07:10 AM by RobSil1976. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 04-10-2013 09:35 PM

    XPath Issue - MoveToChild() Doesn't Seem To Work

    Hi there,

     I have a XPathNavigator object that is set at 1 node of a repeating group in my main data source.  In actuality it is in an OnChanged event in the code behind for that note.  I type text in 1 field, when OnChanged fires, it adjusts the text, queries DB then sets another 2 fields.

     I use the following code to set the two fields, but it keeps failing on the 2nd SetValue() call with the exception: "'xnTypedAccount.SetValue()' threw an exception of type 'System.InvalidOperationException'".  Stack trace message is: Schema validation found non-data type errors.

    Code:

              string namespaceURI = xnTypedAccount.NamespaceURI; //xnTypedAccount is the XpathNavigator object passed as an arg to my Changed event.             
                    xnTypedAccount.MoveToParent(); //go up to parent node.
                    xnTypedAccount.MoveToChild("ActAccountToCharge", namespaceURI); //come back down to 1st sibling we are setting.
                    xnTypedAccount.SetValue(accountNum); //set value to be queried value.
                    xnTypedAccount.MoveToParent(); //back up
                    xnTypedAccount.MoveToChild("ActJobNum", namespaceURI); //back down to 2nd sibling (this is where the exception happens).
    

    Can someone tell me how to set this field? I do notice that if the datatype of that field is "Integer" it fails... if I change it to be text it works... suspect it is the xsi:nill attribute but not sure why.  It is an integer field so I want to keep it as integer for shredding etc.

     

    My parent nodes "outerxml" is:

    <my:OrderItemCoding xmlns:my=\"http://schemas.microsoft.com/office/infopath/2003/myXSD/2013-02-22T21:06:27\">
     <my:CodingItemIdx>1</my:CodingItemIdx>
     <my:QtyOrdered></my:QtyOrdered>
            <my:ActAccountToCharge></my:ActAccountToCharge>
            <my:ReqAcctToCharge>104609</my:ReqAcctToCharge>

             <my:ActJobNum xmlns:my=\"http://schemas.microsoft.com/office/infopath/2003/myXSD/2013-02-22T21:06:27\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:nil=\"true\"></my:ActJobNum>
    </my:OrderItemCoding>

    (with \r\n\t\t\t\t\t\t text removed for cleanliness).

    EDIT: Also... if I edit the field first and put in some misc. data... it seems to be able to be updated properly after that.  Why is it that the field must be typed in before it can be set programatically?

    Thanks,

    Rob

  • 04-11-2013 07:10 AM In reply to

    Re: XPath Issue - MoveToChild() Doesn't Seem To Work

    Update:  I solved the issue this AM.  Did more googling once I had a chance to wrap my head around what was failing (nil=true was the cause).  I found this link that explains the issue:

    http://msdn.microsoft.com/en-us/library/office/bb509311(v=office.12).aspx

    Essentially you have to delete the nil attribute before you set the value.  I used the method listed in the article:

            public void DeleteNil(XPathNavigator node)
            {
                if (node.MoveToAttribute(
                   "nil", "http://www.w3.org/2001/XMLSchema-instance"))
                    node.DeleteSelf();
            }
    
     
    And now it works! :)

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