unable to load xml files

Hello,
I have a bunch of XML files in the folder and I am trying to read all the files and write it back to some other location with slight changes in the file.
However, I am getting object error message on the selectNodes line.
Please can someone help me out in this.
Regards
Sam
<%
Dim xmlSource, fso, file, uname
Set xmlSource   = Server.CreateObject("MSXML2.DOMDocument")
Set fso         = Server.CreateObject("Scripting.FileSystemObject")
 
set theFolder = fso.getFolder("e:\account\data\groups")
 
for Each f In theFolder.files       
        xmlSource.load "e:\account\data\groups\" & f.name         
  uname = xmlSource.documentElement.selectSingleNode("username").text 
  
        s = s & "<user><DateCreated/><CreatedBy/><DataAccess/><ExpiryDate/>"
        s = s & "<ExcludeUser>False</ExcludeUser>"
        s = s & "<Username>" & uname & "</Username>"
        s = s & "<GroupName>CESUsers</GroupName>"
        s = s & "<DateLastUpdated>1/31/2008 4:06:30 PM</DateLastUpdated>"
        s = s & "<LastUpdatedBy>1234</LastUpdatedBy></user>"
        
        filename = uname & ".xml" 
        
        set file = fso.CreateTextFile("e:\test\" & filename) '"
		file.write s
		file.close
		cnt = cnt + 1
		s = ""
Next
 
%>

Open in new window

niidmoreAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Anthony PerkinsConnect With a Mentor Commented:
So why don't you add the appropriate code to find out what is the problem.  Something like this:

<%
Dim xmlSource, fso, file, uname
Set xmlSource   = Server.CreateObject("MSXML2.DOMDocument")
Set fso         = Server.CreateObject("Scripting.FileSystemObject")
 
set theFolder = fso.getFolder("e:\account\data\groups")
 
for Each f In theFolder.files      
      If xmlSource.load("e:\account\data\groups\" & f.name) Then
            uname = xmlSource.documentElement.selectSingleNode("username").text
            
            s = s & "<user><DateCreated/><CreatedBy/><DataAccess/><ExpiryDate/>"
            s = s & "<ExcludeUser>False</ExcludeUser>"
            s = s & "<Username>" & uname & "</Username>"
            s = s & "<GroupName>CESUsers</GroupName>"
            s = s & "<DateLastUpdated>1/31/2008 4:06:30 PM</DateLastUpdated>"
            s = s & "<LastUpdatedBy>1234</LastUpdatedBy></user>"
            
            filename = uname & ".xml"
            
            set file = fso.CreateTextFile("e:\test\" & filename) '"
            file.write s
            file.close
            cnt = cnt + 1
            s = ""
      Else
            Response.Write "Houston we have a problem! Error: " & xmlSource.parseError.Reason & "</br>"
      End If
Next
 
%>
0
 
NorushCommented:
2 Questions:

1. What error do you get?

2. Can you show the structure of the xml files ?
0
 
NorushCommented:
My first gues is that you need the correct xml-path to the username element.

So this might work:

uname = xmlSource.selectSingleNode("users/user/username").text       'Leave out the [documentElement]

But to know for sure i need to know the format of your xml files
0
 
niidmoreAuthor Commented:
hello norush,
thanks for your reply,
1) error
Microsoft VBScript runtime error '800a01a8'
Object required: '[object]'
/ces/loadcesusers.asp, line 20

line 20 is  uname = xmlSource.documentElement.selectSingleNode("username").text

2) structure
<user>
<username>001</username>
<GroupName>testUser</GroupName>
<DateLastUpdated>1/31/2008 4:06:30 PM</DateLastUpdated>
<LastUpdatedBy>1234</LastUpdatedBy>
</user>
0
 
NorushConnect With a Mentor Commented:
Replace line 20 with:

uname = xmlSource.selectSingleNode("user/username").text
0
All Courses

From novice to tech pro — start learning today.