SelectSingleNode - I need all nodes - InfoPath Dev
in

InfoPath Dev

SelectSingleNode - I need all nodes

Last post 01-13-2009 02:59 AM by BuildPro Guru. 11 replies.
Page 1 of 1 (12 items)
Sort Posts: Previous Next
  • 01-12-2009 08:00 AM

    SelectSingleNode - I need all nodes

    I have a repeating section insied of a repeating section.  I am creating appointments in Outlook based on information in the form via a button.  The button is located in the top level section.  If I have one section and one section-within-a-section, everything is great.  If I add a section anywhere, I only get the FIRST section.  How do I get ALL sections?  Currently I am using selectSinglNode to get the informatin that I need.  I have tried fooling around with selectNodes and selectDecendants and selectChildren and I keep getting similar errors:

    Error 1 'System.Xml.XPath.XPathNavigator' does not contain a definition for 'SelectNodes' C:\Documents and Settings\dfisher\My Documents\InfoPath Projects\Customer Care Cincinnati\FormCode.cs 134 74 Customer Care - no code

    Here is my code for selecting the single node:

    XPathNavigator BodyField1 = MainDataSource.CreateNavigator().SelectSingleNode("/dfs:myFields/dfs:dataFields/d:Buyers/d:WorkOrders/d:WorkOrderConcern/d:WorkOrderConcernInfo/@UpdatedInfo", NamespaceManager);

    string BodySeed1 = BodyField1.Value;

     Then I put the string in the spot in the appointment where I need it.  How do I do this for ALL iterations of that field?

    Fishman
  • 01-12-2009 08:35 AM In reply to

    Re: SelectSingleNode - I need all nodes

    I'm guessing you want something like

    foreach(XPathNavigator BodyField1 in MainDataSource.CreateNavigator().Select("/dfs:myFields/dfs:dataFields/d:Buyers/d:WorkOrders/d:WorkOrderConcern/d:WorkOrderConcernInfo/@UpdatedInfo", NamespaceManager))
    {
       
    string BodySeed1 = BodyField1.Value;
        // whatever code uses BodySeed1
    }

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 01-12-2009 10:24 AM In reply to

    Re: SelectSingleNode - I need all nodes

    Hello Jimmy and thanks for the response.  I commented out my original code and inserted yours like this:

    //Body

    //XPathNavigator BodyField1 = MainDataSource.CreateNavigator().SelectSingleNode("/dfs:myFields/dfs:dataFields/d:Buyers/d:WorkOrders/d:WorkOrderConcern/d:WorkOrderConcernInfo/@UpdatedInfo", NamespaceManager);

    foreach (XPathNavigator BodyField1 in MainDataSource.CreateNavigator().Select("/dfs:myFields/dfs:dataFields/d:Buyers/d:WorkOrders/d:WorkOrderConcern/d:WorkOrderConcernInfo/@UpdatedInfo", NamespaceManager));

    string BodySeed1 = BodyField1.Value;

    and this is the error that I get:

    The name 'BodyField1' does not exist in the current context.

    I have tired it several different ways to no avil.  I am not sure where to define BodyField1.

    Fishman
  • 01-12-2009 10:29 AM In reply to

    Re: SelectSingleNode - I need all nodes

    Note the syntax difference between your code and Jimmy's: you have a semi colon at the end of the foreach loop statement -- Jimmy has a curly brace, with a closing brace after the string BodySeed1 = BodyField1.Value;  line.

    Hilary Stoupa

  • 01-12-2009 10:38 AM In reply to

    Re: SelectSingleNode - I need all nodes

    Hello Hilary!  You reall are on top of this forum!

    Got it.  I have to pay closer attention to exact syntax - I am still getting the swing of it!  OK - I got it right and the form works, but now I only get the LAST one.

    Here is what I did:

    foreach (XPathNavigator BodyField1 in MainDataSource.CreateNavigator().Select("/dfs:myFields/dfs:dataFields/d:Buyers/d:WorkOrders/d:WorkOrderConcern/d:WorkOrderConcernInfo/@UpdatedInfo", NamespaceManager))

    {

    string BodySeed1 = BodyField1.Value;

    // whatever code uses BodySeed1

    myAppointment.Body = BodySeed1;

    }

    Fishman
  • 01-12-2009 10:50 AM In reply to

    Re: SelectSingleNode - I need all nodes

    You are only getting the last one because each time through the loop, you are reinitializing the variable BodySeed1 to be equal to the value, and you are setting the appointment body to that variable.

    So, let's say first value is 'Elephant', second is 'Giraffe' and third is 'Panda'. First trip through the loop, you see the string variable to 'Elephant' and the appointment body to 'Elephant'. Second trip, you set the variable to 'Giraffe' and the body to 'Giraffe'. Third trip through, you set it all to 'Panda'. You are overwriting everything, each trip through.

    If you want them all, you'll have to concatenate them -- perhaps something like this:

    myAppointment.Body = myAppointment.Body + BodySeed1;

    or:

    string BodySeed1; foreach (XPathNavigator BodyField1 in MainDataSource.CreateNavigator().Select("/dfs:myFields/dfs:dataFields/d:Buyers/d:WorkOrders/d:WorkOrderConcern/d:WorkOrderConcernInfo/@UpdatedInfo", NamespaceManager))

    {

    BodySeed1 = BodySeed1 + BodyField1.Value;

    // whatever code uses BodySeed1

    myAppointment.Body = BodySeed1;

    }

    Hilary Stoupa

  • 01-12-2009 11:20 AM In reply to

    Re: SelectSingleNode - I need all nodes

    Very nice Hilary!  Thanks for the instruction.  The first one works great - I will try the second one in a bit.

     

    Fishman
  • 01-12-2009 05:04 PM In reply to

    Re: SelectSingleNode - I need all nodes

    I think I am making a mess of this.  First, I tried to add another field (from the same repeating section) to the ForEach statement - and it is not as easy as I thought it would be. This is how I did that:

    //Body

    XPathNodeIterator BodyField2 = MainDataSource.CreateNavigator().Select("/dfs:myFields/dfs:dataFields/d:Buyers/d:WorkOrders/d:WorkOrderConcern/d:WorkOrderConcernInfo/@DateUpdated", NamespaceManager);

     

    //string BodySeed2 = BodyField2.Value;

    foreach (XPathNavigator BodyField1 in MainDataSource.CreateNavigator().Select("/dfs:myFields/dfs:dataFields/d:Buyers/d:WorkOrders/d:WorkOrderConcern/d:WorkOrderConcernInfo/@UpdatedInfo", NamespaceManager))

    {

    string BodySeed1 = BodyField1.Value;

    // whatever code uses BodySeed1

    myAppointment.Body = BodyField2.Current.Value + "-" + BodySeed1 + System.Environment.NewLine + System.Environment.NewLine + myAppointment.Body;

    BodyField2.MoveNext();

    This works well enough, but in some instances, I just need to get the information that is in the current repeating section and not all of them.  The code is assigned to a button that is in the repeating section that I want to retrieve the information from.  Is there any way to add a 'where' or 'if' or something to the ForEach selection?

    Fishman
  • 01-12-2009 05:44 PM In reply to

    Re: SelectSingleNode - I need all nodes

    It would be a lot easier to help you if we understood the structure of your data source and exactly what you're trying to do with each value.  Right now all we can do is guess.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 01-12-2009 06:23 PM In reply to

    Re: SelectSingleNode - I need all nodes

    Sorry, man.  This is what I have:

    Repeating section - WorkOrder

         Repeating section - WorkOrderConcern

               Repeating Section - WorkOrderConcernInfo

    I have a button that creates an appointment in my Outlook calendar.  The code in the button grabs the infromation from a couple of fields in the WorkOrder section - this information is not repeated, but it is needed every time that the button is clicked - I think I have this covered.

    The code also grabs information from a couple fields in WorkOrderConcern.  This is where the button resides.  I only need to grab this information from the repeating section where the button is.

    I also grab all the information from the WorkOrderConcernInfo section - just two fields.  This can repeat several times within WorkOrderConcern.  I need to get every instance of this information that is in a given WorkOrderConcern.

    I take all of this and use the various fields to make up the appointment elements.  Where I am struggling is the WorkOrderConcernInfo.  The code that I have is getting every instance of this rather than just what is in that instance of WorkOrderConcern. 

    Do you need to see any more of my code besides what I have already posted?

    Fishman
  • 01-12-2009 08:10 PM In reply to

    Re: SelectSingleNode - I need all nodes

    If that code is running in the event handler for a button, then e.Source is most likely directed at WorkOrderConcern.

    The following would probably work:

    XPathNodeIterator BodyField2 = e.Source.Select("d:WorkOrderConcernInfo/@DateUpdated", NamespaceManager);
    foreach (XPathNavigator BodyField1 in e.Source.Select("d:WorkOrderConcernInfo/@UpdatedInfo", NamespaceManager))
    {
       
    string BodySeed1 = BodyField1.Value; 
        myAppointment.Body = BodyField2.Current.Value + "-" + BodySeed1 + System.Environment.NewLine + System.Environment.NewLine + myAppointment.Body;
       
    BodyField2.MoveNext();
    }

    And if that does work, you can make the code a little tidier by doing something like this

    foreach (XPathNavigator ConcernInfo in e.Source.Select("d:WorkOrderConcernInfo", NamespaceManager))
    {
       
    string BodySeed1 = ConcernInfo.SelectSingleNode("@UpdatedInfo", NamespaceManager).Value; 
        string BodySeed2 = ConcernInfo.SelectSingleNode("@DateUpdated", NamespaceManager).Value; 
        myAppointment.Body = BodySeed2 +
    "-" + BodySeed1 + System.Environment.NewLine + System.Environment.NewLine + myAppointment.Body;
    }

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 01-13-2009 02:59 AM In reply to

    Re: SelectSingleNode - I need all nodes

    Thanks JImmy!  That works fantastic.  I have been trying like a madman to figure out how to select the entire node set and then just grab the nodes that I need rather than doing them one at a time.  Thanks again - this has been a tremendous help!

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