经典ASP - 显示XML记录

时间:2018-04-03 20:44:13

标签: xml asp-classic

我正在尝试获取每条记录的用户名和dbId。

这是代码,所以你可以看到我的尝试,但我被卡住了。

我只知道如何获取第一条记录(0),但如何循环显示所有记录?

非常感谢您提供任何帮助。

代码:

    Set http = Server.CreateObject("msxml2.ServerXMLHTTP.6.0")
    http.Open "GET", "http://URLWHERETHEXMLFILEISAT.COM", False, "USERNAME", "PASSWORD"
    http.setTimeouts 5000, 5000, 10000, 10000 'ms - resolve, connect, send, receive'
    http.setRequestHeader "Authorization", "Basic MY_AUTH_STRING"
    http.Send

Response.ContentType = "application/xml"    

Set items = http.responseXML.getElementsByTagName("list")

For Each item In items
'--> I would like to display the username and dbId for each record

Set username = item.getElementsByTagName("username")
    If NOT (username IS Nothing) Then 
        var_username = username(0).Text
    End If


response.write "Username: " & var_username & "</br>"

Response.write "</br>"
Next

.XML文件

<list>
<com.pedigree.external.User>
<dbId>1353</dbId>
<url>/api/users/1353</url>
<parentId>126561</parentId>
<firstName>JOHN</firstName>
<lastName>WILLIAMS</lastName>
<email/>
<username>johnw</username>
<cellPhone/>
<workPhone/>
<actorClass>User Driver</actorClass>
<active>true</active>
<isDriver>true</isDriver>
<customerId>2235470</customerId>
</com.pedigree.external.User>
<list>

0 个答案:

没有答案