iterate over repeating table problem

K

kb at donovanhill

Trying to iterate over values within a repeating table, my vb.net code below
iterates over all node values within the form, not the selected group, would
anyone know where I am going wrong, any help would be greatly appreciated.

Dim navigator As XPathNavigator = CreateNavigator()

Dim nodes As XPathNodeIterator =
navigator.Select("/my:myFields/my:group2", NamespaceManager)
Dim nodesNavigator As XPathNavigator = nodes.Current

Dim nodestext As XPathNodeIterator =
nodesNavigator.SelectDescendants(XPathNodeType.Text, False)

While nodestext.MoveNext()

MessageBox.Show(nodestext.Current.Value)

End While
 
S

S.Y.M. Wong-A-Ton

You are the second person to use such a code structure. Can you please tell
me where you have found the code? Or did you write it yourself? In any case,
try using XPathNodeType.Element instead of XPathNodeType.Text.

BTW, since you are a regular question poster in this group and seem to write
code for your InfoPath form templates, you may want to take a few minutes to
help out a member of the InfoPath team and answer a few or all of his
questions. Check out his post here:
http://msdn.microsoft.com/newsgroup...-DC48AB0DA5C9&dglist=&ptlist=&exp=&sloc=en-us

Thanks!
 
S

S.Y.M. Wong-A-Ton

Thanks for telling me where you found the code, kb. And thanks also for
contributing to answering the questions from the InfoPath team.

A good resource for learning to work with the XPathNavigator and
XPathNodeNodeIterator classes in InfoPath 2007 is:
http://msdn2.microsoft.com/en-us/library/bb509311.aspx
It contains VB.NET code snippets, so it might help. Let us know how you get
along.
 
K

kb at donovanhill

Hi,

Changing .text to .element still iterates the entire form, it shows the
repeating table values at the end. Therefore the XpathNodeIterator ignores
the XPath address specified in the navigator.Select

Very frustrating, especially when this would be a very common task, anyway I
will try some other things.
Thanks
 
S

S.Y.M. Wong-A-Ton

Let's take a step backwards for a moment. Are you trying to retrieve the
values of one particular row in a repeating table? Or are you trying to loop
through all the rows and retrieve the values in each row?

This piece of code helped the last person who was experiencing difficulties
with SelectDescendants. I've tried to translate it to VB for you and
implement it in the code you already had (I did not test it!):

Dim navigator As XPathNavigator = CreateNavigator()
Dim nodes As XPathNodeIterator = navigator.Select("/my:myFields/my:group2",
NamespaceManager)

While nodes.MoveNext()
MessageBox.Show(nodes.Current.SelectSingleNode("my:firstfieldinrow",
NamespaceManager).Value)
MessageBox.Show(nodes.Current.SelectSingleNode("my:secondfieldinrow",
NamespaceManager).Value)
End While

I'm assuming that "/my:myFields/my:group2" is your repeating group.
my:firstfieldinrow is the name of a field in a row of the repeating table.
 
K

kb at donovanhill

Hi,

I am trying to loop through all the rows within a repeating table
and retrieve the values in each row. I will give your suggestion ago.

Thanks again for your help!
kb
 
S

S.Y.M. Wong-A-Ton

No worries.
---
S.Y.M. Wong-A-Ton


kb at donovanhill said:
Hi,

I am trying to loop through all the rows within a repeating table
and retrieve the values in each row. I will give your suggestion ago.

Thanks again for your help!
kb
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top