printing repeating table with vbscript

J

Justin

I'm trying to output the contents of a repeating field to a txt file. I
can get the first record of the table to appear, but i am unsure how to
get any other records. Below is a snippet of the code I have:



iItemCount =
XDocument.DOM.selectNodes("//dfs:dataFields/d:Table1/@TestField1").length

iRow=0

do while iRow < iItemCount
nodeValue =
XDocument.GetNamedNodeProperty(XDocument.DOM.selectSingleNode("dfs:dataFields/d:Table1/@TestField1"),
"TestField1", "wrong")

oTempFile.Write nodeValue
iRow = iRow + 1




This code is outputting 'wrong' (the value associated with a null field
or no return?)

Any idea on how I can output the contents of a repeating section or
table?

Thanks
 
S

S.Y.M. Wong-A-Ton

If you have something to identify the records (like an ID), you can add it as
a filter to the XPath expression to retrieve each node in the repeating group.
 
S

S.Y.M. Wong-A-Ton

Just realized that you don't need an ID after all. I think your original
selectNodes is returning the fields of a row and not the rows of a table. Try
something like this:

oRows = XDocument.DOM.selectNodes("//dfs:dataFields/d:Table1")

iRow = 1

For iRow = 1 To oRows.length
nodeValue = oRows(iRow).selectSingleNode("@TestField1").text
oTempFile.Write nodeValue
Next

I've written this from the top of my head and haven't tested it, so if it
does not work, please don't stone me. :)
 
J

Justin

I feel like I'm getting close here. I put the code in as follows:

Dim oRows
oRows = XDocument.DOM.selectNodes("//dfs:dataFields/d:Table1")
iRow = 1
For iRow = 1 To oRows.length
nodeValue = oRows(iRow).selectSingleNode("@TestField1").text
oTempFile.Write nodeValue
Next

When I run that, I get an error:

Wrong number of arguments or invalid property
assignment.

The error occurs on line 62, which is the row i assign oRows =
XDocument/..(..Table1)

Any ideas?

Sorry to be a pain in the @$$, in a year or so, i will have re-learned
java and coded this stupid form up in there, and sold it to people, ill
mail you a check.

Thanks....
 
S

S.Y.M. Wong-A-Ton

Try

Set oRows = XDocument.DOM.selectNodes("//dfs:dataFields/d:Table1")

If that doesn't work, post the tree structure for your data source, so that
I can see what it looks like.
 
J

Justin

getting closer I think. I have a run-time error now.

Object required: 'oRows(...)'
Line: 66

this is the line:

nodeValue = oRows(iRow).selectSingleNode("@TestField1").text

If you still need the tree structure, pretty simple as I made a test
form to get this code working right before I put it on my real form.

+myFields
+dataFields
+d:Table1
TestID
TestField1
TestField2

thank you so much again for the help
 
S

S.Y.M. Wong-A-Ton

How many rows do you have in the table? Try

For iRow = 0 To oRows.length - 1
....
Next

If that doesn't work, try debugging your code using XDocument.UI.Alert(...)
at each step to see what the code is doing, e.g.

XDocument.UI.Alert(oRows.length)
XDocument.UI.Alert(oRows(iRow).xml)
etc.
 
Top