Problem getting data with Iterator and Navigator - InfoPath Dev
in

InfoPath Dev

Problem getting data with Iterator and Navigator

Last post 07-24-2012 11:28 AM by PaulRAnderson. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 07-24-2012 08:37 AM

    Problem getting data with Iterator and Navigator

    I am trying to get the values of two elements in an XML file and am almost there but it's not quite working.

    A simplistic view of the XML is:

    --------------------------------------------------------------------------------
        <root>
           <device> (repeating)
               <name>
               <summary>
                   <issue> (repeating)
    --------------------------------------------------------------------------------

    I want to get all names and all issues for each name.  The string deviceName correctly contains name but I can't get issue because device contains the children, not the children of the children.

    --------------------------------------------------------------------------------

        XPathNodeIterator devices = MainDataSource.CreateNavigator().Select("/root/device", NamespaceManager);
        while (devices.MoveNext())
        {
            XPathNavigator device = devices.Current.CreateNavigator().SelectSingleNode("name", NamespaceManager);
            if (device != null)
            {
                String deviceName = device.Value;
                XPathNodeIterator issues = device.CreateNavigator().Select("summary/issue", NamespaceManager);
                while (issues.MoveNext())
                {
                    XPathNavigator issue = issues.Current.CreateNavigator().SelectSingleNode(issuePath, NamespaceManager);
                    if (issue != null)
                    {
                        String issueValue = issue.Value;
                    }
                }
            }
        }

    --------------------------------------------------------------------------------

    The code in the "while(issues.MoveNext())" section never executes because there are no issues.

    What can I do to either grab all data underneath <device> or should I step through manually somehow and grab issues?

    Paul

  • 07-24-2012 09:32 AM In reply to

    Re: Problem getting data with Iterator and Navigator

    In this line:

        XPathNodeIterator issues = device.CreateNavigator().Select("summary/issue", NamespaceManager);

    how about using devices.Current instead of device?  I think that's the problem.

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

    Re: Problem getting data with Iterator and Navigator

    Thank you!  Your answer set me on the right path.

     I changed device to devices.Current as you suggested and also removed the definition of the innermost XPathNavigator, as the value of issue is the InnerXml.  The code that works is:

        XPathNodeIterator devices = MainDataSource.CreateNavigator().Select("/root/device", NamespaceManager);
         while (devices.MoveNext())
         {
             XPathNavigator device = devices.Current.CreateNavigator().SelectSingleNode("name", NamespaceManager);
             if (device != null)
             {
                 String deviceName = device.Value;
                 XPathNodeIterator issues = devices.Current.CreateNavigator().Select("/summary/issue", NamespaceManager);
                 while (issues.MoveNext())
                 {
                    String issue = issues.Current.InnerXml;
                }
             }
         }

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