selectSingleNode from XML where value = ?

I'm an ASP/SQL guy and have inherited an XML file:

<?xml version="1.0" encoding="UTF-8"?>
  <employee id="4-1"  dept="finance5" email="" firstName="John" lastName="Doe" phone="2821" position="Staff Accountant" />

  <employee id="4-2"  dept="mktg" email="" firstName="Jane" lastName="Doe" phone="2822" position="Staff Marketer" />

I'm trying to update the information via ASP.
I've managed to generate a dropdown to choose a user based on their ID and pass that to a form - I want to then get all user attributes where that id = locationpressed

Can someone help with syntax here?
I would have thought
Set node = objXMLDoc.documentElement.SelectSingleNode("/[@id = " & locationpressed & "]]")
would work - but it doesn't.
What's is the best way of selecting ALL values (dept, email, firstname, lastname, etc . . . ) where the ID = x?

Thanks you!
Who is Participating?
jkmyoungConnect With a Mentor Commented:
Looks like you're trying to select the employee node, first of all, and then change the values
Set node = objXMLDoc.documentElement.SelectSingleNode("//employee[@id = " & locationpressed & "]]")

Then to get/set the attribute values, you could use selectSingleNode again, or use the attibutes property.
Set attr = node.selectSingleNode("@firstName");
attr.value = "James";
CG_HDAuthor Commented:
I've tried that and I'm getting an error:
Microsoft VBScript runtime  error '800a01a8'
Object required

Set node = objXMLDoc.documentElement.SelectSingleNode("//employee[@id = " & locationpressed & "]")
Set attr = node.selectSingleNode("@firstName")
response.write attr.value

what object is the error referencing?
CG_HDAuthor Commented:
so after some time, it looks like it's simply not finding anything at all.
When I search on the id, I apparently neglected the single quotes . . . now it works.
Now I just need to understand how write different values back to the same XML file.
Use the value property of the attribute to write it back, as shown here, eg attr.value = "James";
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.