开发者

How to parse XML in ASP/vbscript?

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开发者_StackOverflow中文版 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>


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.


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜