Link to home
Start Free TrialLog in
Avatar of niidmore
niidmoreFlag for United Kingdom of Great Britain and Northern Ireland

asked on

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

Avatar of Norush
Norush
Flag of Netherlands image

2 Questions:

1. What error do you get?

2. Can you show the structure of the xml files ?
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
Avatar of niidmore

ASKER

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>
ASKER CERTIFIED SOLUTION
Avatar of Anthony Perkins
Anthony Perkins
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial