473,383 Members | 1,788 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

XML Reading


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

--
Creascripts
------------------------------------------------------------------------
Posted via http://www.codecomments.com
------------------------------------------------------------------------

Nov 11 '06 #1
2 1282
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 "&nbsp;"
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 "&nbsp;"
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 "&nbsp;"
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"
Nov 11 '06 #2
Bob Barrows [MVP] wrote:
>
<%
option explicit
dim xdoc, uname, pwd, fname, users, details
set xdoc=createobject("msxml2.domdocument")
xdoc.load server.mappath("xml/yourfile.xml")
You do, of course, need to change this to your path and file name.
--
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"
Nov 11 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Andy | last post by:
Hi, In the code below (not pretty I know but it's an early version :-P) I'm having problems reading the data object back in. If I move the reading code to immediately after the section where it...
6
by: Raymond Hettinger | last post by:
Found in a pamphlet at a pre-school: --------------------------------------- Reading improves vocabulary Reading raises cultural literacy through shared knowledge Reading develops writing skills...
4
by: Xah Lee | last post by:
# -*- coding: utf-8 -*- # Python # to open a file and write to file # do f=open('xfile.txt','w') # this creates a file "object" and name it f. # the second argument of open can be
24
by: Hendrik Schober | last post by:
Hi, I have a 'std::istream' and need to read its whole contents into a string. How can I do this? TIA; Schobi
19
by: Lionel B | last post by:
Greetings, I need to read (unformatted text) from stdin up to EOF into a char buffer; of course I cannot allocate my buffer until I know how much text is available, and I do not know how much...
4
by: Oliver Knoll | last post by:
According to my ANSI book, tmpfile() creates a file with wb+ mode (that is just writing, right?). How would one reopen it for reading? I got the following (which works): FILE *tmpFile =...
6
by: KevinD | last post by:
assumption: I am new to C and old to COBOL I have been reading a lot (self teaching) but something is not sinking in with respect to reading a simple file - one record at a time. Using C, I am...
3
by: Nick | last post by:
I have found a class that compresses and uncompresses data but need some help with how to use part of it below is the deflate method which compresses the string that I pass in, this works OK. At...
9
by: Mike Reed | last post by:
I must be having a "senile" day! I cannot recall, nor get to work, code to read a cookie's expiration date/time in an ASP page/VBScript. What am I missing? *** Sent via Developersdex...
4
by: Gaijinco | last post by:
I had a file named nap.in which looks like this: 4 10:00 12:00 Lectures 12:00 13:00 Lunch, like always. 13:00 15:00 Boring lectures... 15:30 17:45 Reading 4 10:00 12:00 Lectures 12:00 13:00...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.