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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Anthony PerkinsCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
NorushCommented:
Replace line 20 with:

uname = xmlSource.selectSingleNode("user/username").text
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
XML

From novice to tech pro — start learning today.