Creascripts wrote:
I'm having some problem with reading an .xml file:
<?xml version="1.0" encoding="utf-8"?>
<UserInfoListResult xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://tempuri.org/">
<Result>true</Result>
<ResultCode>0</ResultCode>
<Message />
<Users>
<UserInfo>
<UserName>test</UserName>
<Password>test</Password>
<FirstName>test</FirstName>
<LastName />
<IsSystemAdmin>false</IsSystemAdmin>
<IsDomainAdmin>true</IsDomainAdmin>
</UserInfo>
<UserInfo>
<UserName>test2</UserName>
<Password>test2</Password>
<FirstName>test2</FirstName>
<LastName />
<IsSystemAdmin>false</IsSystemAdmin>
<IsDomainAdmin>false</IsDomainAdmin>
</UserInfo>
</Users>
</UserInfoListResult>
How could I retrieve in a loop username,password,firstname?
Thanks very much
<%
option explicit
dim xdoc, uname, pwd, fname, users, details
set xdoc=createobject("msxml2.domdocument")
xdoc.load server.mappath("xml/yourfile.xml")
If xdoc.parseError.errorCode = 0 Then
Response.Write "<table><tr><th>UserName</th><th>" & _
"Password</th><th>First Name</th><tr>"
set users = nothing
set users = xdoc.selectnodes("/UserInfoListResult/Users/UserInfo")
if not users is nothing then
for each details in users
Response.write "<tr><td>"
set uname=nothing
set uname= details.selectsinglenode("UserName")
if not uname is nothing then
Response.Write server.HTMLEncode(uname.text)
else
Response.Write " "
end if
Response.Write "</td><td>"
set pwd=nothing
set pwd= details.selectsinglenode("Password")
if not pwd is nothing then
Response.Write server.HTMLEncode(pwd.text)
else
Response.Write " "
end if
Response.Write "</td><td>"
set fname=nothing
set fname= details.selectsinglenode("FirstName")
if not fname is nothing then
Response.Write server.HTMLEncode(fname.text)
else
Response.Write " "
end if
Response.Write "</td></tr>"
next
Response.Write "</table>"
else
Response.Write "Either the xml contained no user info " & _
"or the xpath query was badly stated"
end if
Else
' error parsing data
With xdoc.parseError strError = "Error Parsing XML Data:" & "
" & "
" & _ "Error Code: " & .errorCode & "
" & _ "Error Description: " & .reason & "
" & _ "Error Line: " & .line & "
" & _ "Error Line Position: " & .linepos & "
" & _ "Error File Position: " & .filepos & "
" & _ "Error Source: " & .srcText End With
Response.Write "<Error>" & strError & "</Error>"
End If
%>
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"