Basic VB XpathNavigator/XpathNodeIterator stuff what am I doing wrong - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Basic VB XpathNavigator/XpathNodeIterator stuff what am I doing wrong

Last post 08-17-2007 02:10 PM by shaun.nieves. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 08-16-2007 09:02 AM

    Basic VB XpathNavigator/XpathNodeIterator stuff what am I doing wrong

    Hi This is a Newbie VB (Infopath 2007) question.

    I have a Data  with the following...
    <my:Group2>
    <my:Group2Field1>hello</my:Group2Field1>
    <my:Group2Field2>harry</my:Group2Field2>
    </my:Group2>
    <my:Group2>
    <my:Group2Field1>happy</my:Group2Field1>
    <my:Group2Field2>fred</my:Group2Field2>
    </my:Group2></my:myFields>

    I want to cycle through the Group2 items,  and within each Group2 item cycle through the elements. I have been playing with XpathNodeIterator and XpathNavigator.  Moving to the Child of Group2 does not seem to do what I want - ie I get lots of Child values with White Space only.  I could do it via the SelectSingleNode if I provide the xpath names of the 'fields' but I will not necessarly have that info...... the code is below.  What am I doing wrong ?

    Dim nav As XPathNavigator
    Dim groupnam As String = "/my:myFields/my:Group2"
    Dim Groupnode As XPathNodeIterator
    Dim field As String
    Dim curpos As Integer
    Dim mov As Boolean

    'Put the MainDataSource of the form into the DataSource variable
    Dim datsrc As DataSource = Me.MainDataSource

    'Put the xml of the main datasource into the navigator
    nav = datsrc.CreateNavigator()

    'Put the Group into the node iterator
    Groupnode = nav.Select(groupnam, NamespaceManager)

    'go to positon1
    Groupnode.MoveNext()
    curpos = Groupnode.CurrentPosition

    While curpos <= Groupnode.Count
    'Put the current node into the record navigator
    record = Groupnode.Current
    'go to position1
    mov = record.MoveToFirstChild()

    While mov = True
    field = record.Value
    MessageBox.Show(field)
    mov = record.MoveToNext()
    End While
    Groupnode.MoveNext()
    curpos = Groupnode.CurrentPosition()
    End While

  • 08-17-2007 02:10 PM In reply to

    Re: Basic VB XpathNavigator/XpathNodeIterator stuff what am I doing wrong

    It sounds like you're trying to loop through your data. If so, try this out. Hope this helps!

    Sub Main()
    Dim xmlDoc As New XmlDocument
    xmlDoc.Load("SampleData.xml")
    Dim ns As New XmlNamespaceManager(xmlDoc.NameTable)
    ns.AddNamespace("sp", "http://schemas.microsoft.com/sharepoint/soap/")
    ns.AddNamespace("rs", "urn:schemas-microsoft-com:rowset")
    ns.AddNamespace("z", "#RowsetSchema")
    Dim dataNodes As XmlNodeList = xmlDoc.SelectNodes("//sp:listitems/rs:data", ns) 'selects all data elements in the document
    'for each data node
    For Each dataNode As XmlNode In dataNodes
    Console.WriteLine(dataNode.Attributes("ItemCount").Value)
    'for each child row node of the data node
    For Each rowNode As XmlNode In dataNode.ChildNodes
    Console.WriteLine(rowNode.Attributes("ows_TrackingNumber").Value)
    Console.WriteLine(rowNode.Attributes("ows_Unit").Value)
    Next
    Next
    Console.ReadLine()
    End Sub

    Below is the XML the above uses

    <?xml version="1.0" encoding="utf-8" ?>
    <listitems xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema" xmlns="http://schemas.microsoft.com/sharepoint/soap/">
    <rs:data ItemCount="1">
    <z:row ows_TrackingNumber="ALLCHD_6_1_2007-04-07" ows_Unit="Unit 1" ows_ContainerType="CM" ows_Active="-1" ows_ID="825" ows_owshiddenversion="1" />
    <z:row ows_TrackingNumber="ALLCHD_6_2_2007-04-07" ows_Unit="Unit 1" ows_ContainerType="CM" ows_Active="-1" ows_ID="825" ows_owshiddenversion="1" />
    <z:row ows_TrackingNumber="ALLCHD_6_3_2007-04-07" ows_Unit="Unit 1" ows_ContainerType="CM" ows_Active="-1" ows_ID="825" ows_owshiddenversion="1" />
    <z:row ows_TrackingNumber="ALLCHD_6_4_2007-04-07" ows_Unit="Unit 1" ows_ContainerType="CM" ows_Active="-1" ows_ID="825" ows_owshiddenversion="1" />
    <z:row ows_TrackingNumber="ALLCHD_6_5_2007-04-07" ows_Unit="Unit 1" ows_ContainerType="CM" ows_Active="-1" ows_ID="825" ows_owshiddenversion="1" />
    </rs:data>
    <rs:data ItemCount="2">
    <z:row ows_TrackingNumber="ALLCHD_6_6_2007-04-07" ows_Unit="Unit 1" ows_ContainerType="CM" ows_Active="-1" ows_ID="825" ows_owshiddenversion="1" />
    <z:row ows_TrackingNumber="ALLCHD_6_7_2007-04-07" ows_Unit="Unit 1" ows_ContainerType="CM" ows_Active="-1" ows_ID="825" ows_owshiddenversion="1" />
    <z:row ows_TrackingNumber="ALLCHD_6_8_2007-04-07" ows_Unit="Unit 1" ows_ContainerType="CM" ows_Active="-1" ows_ID="825" ows_owshiddenversion="1" />
    <z:row ows_TrackingNumber="ALLCHD_6_9_2007-04-07" ows_Unit="Unit 1" ows_ContainerType="CM" ows_Active="-1" ows_ID="825" ows_owshiddenversion="1" />
    </rs:data>
    </listitems>

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