Creascripts wrote:
I'm having some problem with reading an .xml file:
<?xml version="1.0" encoding="utf-8"?>
<UserInfoListRe sult 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>tes t</UserName>
<Password>tes t</Password>
<FirstName>test </FirstName>
<LastName />
<IsSystemAdmin> false</IsSystemAdmin>
<IsDomainAdmin> true</IsDomainAdmin>
</UserInfo>
<UserInfo>
<UserName>test2 </UserName>
<Password>test2 </Password>
<FirstName>test 2</FirstName>
<LastName />
<IsSystemAdmin> false</IsSystemAdmin>
<IsDomainAdmin> false</IsDomainAdmin>
</UserInfo>
</Users>
</UserInfoListRes ult>
How could I retrieve in a loop username,passwo rd,firstname?
Thanks very much
<%
option explicit
dim xdoc, uname, pwd, fname, users, details
set xdoc=createobje ct("msxml2.domd ocument")
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.selectnode s("/UserInfoListRes ult/Users/UserInfo")
if not users is nothing then
for each details in users
Response.write "<tr><td>"
set uname=nothing
set uname= details.selects inglenode("User Name")
if not uname is nothing then
Response.Write server.HTMLEnco de(uname.text)
else
Response.Write " "
end if
Response.Write "</td><td>"
set pwd=nothing
set pwd= details.selects inglenode("Pass word")
if not pwd is nothing then
Response.Write server.HTMLEnco de(pwd.text)
else
Response.Write " "
end if
Response.Write "</td><td>"
set fname=nothing
set fname= details.selects inglenode("Firs tName")
if not fname is nothing then
Response.Write server.HTMLEnco de(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"