How do I iterate through nodes in Javascript?

Here is the doc:


January 15th, 2002
January 15th, 2002

Application Recieved
This is permit is for new plumbing work in an addition
New Work
1
1
1
1
1
1
1
1

This is the code I am trying to get to work, but alas it does not:

<%@ language=“javascript” %>
<%

var caseNumber = Request(“caseNumber”);

tamino = new ActiveXObject(“TAMINOX.TaminoX1”);
tamino.Initialize();
tamino.csDatabaseURL(“http://mercury/tamino/govME”);
query = “permits/permit/[@caseNumber="”+caseNumber+“"]”;
dom = tamino.doQuery(query);
objNodeList = dom.getElementsByTagName(“permit”);
var permitNumber = dom.getAttributeNode(“caseNumber”);
var permitDetails = dom.getElementsByTagName(“detail”);

Response.Write(“

”)
Response.Write(“”);


for (var i=0; i<objNodeList.length; i++) {
Response.Write(“

”);
Response.Write(“”);
}
Response.Write(“
Case Number
” + permitNumber.item(i).text + “
” + permitDetails.item(i).text + “
”)

x = tamino.insert(dom);

Any help is greatly appreciated!

In your example you are using objNodeList.length to control the iteration of permit Details, but objNodeList is set using
objNodeList = dom.getElementsByTagName(“permit”);
so it contains only one (permit) Element.

If you use permitDetails.length to control your loop, you should iterate properly over all of the details.

I have attached a html/javascript example.
test.html (726 Bytes)

Bill,
Thanks this code works well now, but when I try to ust the get attributes feature of the dom it says that this is not supported by the tamino object so how do I capture the attribute names and values in tamino/javascript?:

var caseNumber = Request(“caseNumber”);

tamino = new ActiveXObject(“TAMINOX.TaminoX1”);
tamino.Initialize();
tamino.csDatabaseURL(“http://mercury/tamino/govME/permits”);
query = “/permits/permit[@caseNumber="”+caseNumber+“"]”;
dom = tamino.doQuery(query);
objNodeList = dom.getElementsByTagName(“permit”);
//var permitNumber = dom.getElementsByTagName(“permit”);
var permitDetails = dom.getElementsByTagName(“detail”);

Response.Write(“

”)
Response.Write(“”);


for (var i=0; i<permitDetails.length; i++) {
//Response.Write(“

”);
Response.Write(“”);
}
Response.Write(“
Case Number
” + permitNumber.item(i).text + “
” + permitDetails.item(i).text + “
”)

Hi,

Methods getAttributeNode() and getAttribute() apply to Elements, so before you use them you need to get from the DOM itself to the Element you’re interested in.

For example,

var permitNumber = objNodeList.item(0).getAttribute(“caseNumber”);

By the way, the full MSXML SDK including documentation is available at

MSDN Download

HTH!

<%@ language=“javascript” %>
<%

var caseNumber = Request(“caseNumber”);

tamino = new ActiveXObject(“TAMINOX.TaminoX1”);
tamino.Initialize();
tamino.csDatabaseURL(“http://mercury/tamino/dev/permits”);
query = “/permits/permit[@caseNumber="”+caseNumber+“"]”;
dom = tamino.doQuery(query);
objNodeList = dom.getElementsByTagName(“detail”);
var permitDetails = dom.getElementsByTagName(“detail”);
var recDate = objNodeList.item(0).getAttribute(“description”);
var issueDate = objNodeList.item(1).getAttribute(“description”);
var finalDate = objNodeList.item(2).getAttribute(“description”);
var status = objNodeList.item(3).getAttribute(“description”);
var comments = objNodeList.item(4).getAttribute(“description”);
var typeWork = objNodeList.item(5).getAttribute(“description”);
var numWC = objNodeList.item(6).getAttribute(“description”);
var numSinks = objNodeList.item(7).getAttribute(“description”);
var numWT = objNodeList.item(8).getAttribute(“description”);
var gWHeater = objNodeList.item(9).getAttribute(“description”);
var eWHeater = objNodeList.item(10).getAttribute(“description”);

Response.Write(“

”);
Response.Write(“
”);

Response.Write(“

”)
Response.Write(“”);
Response.Write(“”);
Response.Write(“”);
Response.Write(“”);
Response.Write(“”);
Response.Write(“”);
Response.Write(“”);
Response.Write(“”);
Response.Write(“”);
Response.Write(“”);
Response.Write(“”);
Response.Write(“”);

Response.Write(“

Case Number: ” + caseNumber + “
” + recDate + “ ”+ permitDetails.item(0).text +“
” + issueDate + “ ” + permitDetails.item(1).text +“
” + finalDate + “ ” + permitDetails.item(2).text +“
” + status + “ ” + permitDetails.item(3).text +“
” + comments + “ ” + permitDetails.item(4).text +“
” + typeWork + “ ” + permitDetails.item(5).text +“
” + numWC + “ ” + permitDetails.item(6).text +“
” + numSinks + “ ” + permitDetails.item(7).text +“
” + numWT + “ ” + permitDetails.item(8).text +“
” + gWHeater + “ ” + permitDetails.item(9).text +“
” + eWHeater + “ ” + permitDetails.item(10).text +“
”)

Response.Write(“

”);