views:

303

answers:

2

I have a result string with the following structure

<items>
    <item>
       <id> 

I must iterate through down to id and I have some other tags there also. I really don't know how to do it in vbscript. And I would like to have all id:s returned in an array.

Is there not really a method like this:

Dim doc
Dim thumbArray
Set doc = Server.CreateObject("MSXML2.DOMDocument")
doc.loadXML(searchresponse) 
thumbArray = doc.getElementsByTagName("id") 

for each tt in thumbArray
 Response.Write(tt & "<br>") 
next 

Especially this:

getElementsByTagName("id") 

Specifically I would like to do something like this:

<script type="text/javascript"> 
window.onload = function() {
    var content = document.getElementById("content"); 
    var ids = content.getElementsByTagName("thumbnail"); 
    var pics = document.getElementById("pics"); 
    var tts = []; 
    for(var i=0;i<ids.length;i++)
    {
        tts.push("<li>+ ids[i].innerHTML + </li>"); 
    }
    pics.innerHTML = tts.join(""); 


}
</script>
+1  A: 

It's been a while since I've worked with Vb Script but this should get you started.

Dim doc
Dim xmlString
Dim nodes
Dim idArray

Set doc = Server.CreateObject("MSXML2.DOMDocument")
doc.loadXML xmlString

Set nodes = doc.selectNodes("items/item/id")

idArray = Array()
Redim idArray(nodes.length)

For i = 0 To nodes.length
    idArray(i) = nodes(i)
Next
ChaosPandion
A: 

Try something like this.

Set thumbArray = doc.getElementsByTagName("id") 

for index = 0 to thumbArray.Length
    Response.Write(thumbArray[index].nodeValue & "<br>") 
next 

Take a look at this.

Tester101