PDA

View Full Version : creating a recordset


kentyler
05-02-2003, 05:17 PM
for my own reasons, i'm trying to convert a dataset into something like a recordset object in javascript

I'm using xml that you can see at
http://www.seedwiki.com/test/xmlquery.cfm?querystring=select%20*%20from%20terri tories

I can loop over the rows all right, but inside each row element there are 2 column elements, and for the life of me I can figure out how to loop over them inside the row loop.


<canvas debug = "true">

<script>
//COLUMN
function column()
{
this.name = "";
this.value = "";}

//ROW
function row()
{
this.columns = new array();
}


//RECORDSET
function recordset()
{
this.pointer = 0;
this.rows = new array();
}
</script>

<dataset autorequest="true" type="http" name="queryinfo"
src="http://www.seedwiki.com/test/xmlquery.cfm?querystring=select%20*%20from%20terri tories" />

<view>

<datapointer xpath="queryinfo:/queryinfo/data" ondata="processData()">
<method name="processData">
<![CDATA[
var myrecordset = new recordset();
counter = 0;
this.selectChild( 1 );
var numberOfFields = this.getNodeCount();
do {
for ( i = 1; i <= numberOfFields; i++ )
{
debug.write("node is " + i + " name is " + this.getXpath("column[i]/@name") );
}
} while ( this.selectNext() );
debug.write( "there are " + myrecordset.rows.length + " rows");
]]>
</method>
</datapointer>
</view>


I want to pick up the two attriubutes of each column element, its name and value.

antun
05-02-2003, 06:24 PM
Hey kentyler

Two issues:

1) I was getting script running slowly errors constantly. The reason for this is that the counter variable i was not protected in this line of code:


for ( i = 1; i <= numberOfFields; i++ )


... should really be:


for ( var i = 1; i <= numberOfFields; i++ )


This was actually a problem with our source code for datapointer. There was an unprotected variable i in our code, so your counter conflicted with it and sent it into an infinite loop.

2) To get to the right column in your row, you're refering to the i variable in a string, so this line:


debug.write("node is " + i + " name is " + this.getXpath("column[i]/@name") );


... should be


debug.write("node is " + i + " name is " + this.getXpath("column[" + i + "]/@name") );


That will evaluate to:


column[1]/@name
column[2]/@name
column[3]/@name
column[4]/@name
... and so forth.


-Antun