Solved

selectSingleNode from XML where value = ?

Posted on 2007-12-06
4
1,995 Views
Last Modified: 2010-05-18
I'm an ASP/SQL guy and have inherited an XML file:

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

  <employee id="4-2"  dept="mktg" email="jane.doe@test.com" firstName="Jane" lastName="Doe" phone="2822" position="Staff Marketer" />
</personnel>

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!
0
Comment
Question by:CG_HD
  • 2
  • 2
4 Comments
 
LVL 12

Accepted Solution

by:
jkmyoung earned 500 total points
ID: 20424039
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";
0
 

Author Comment

by:CG_HD
ID: 20429840
I've tried that and I'm getting an error:
Microsoft VBScript runtime  error '800a01a8'
Object required

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

what object is the error referencing?
0
 

Author Comment

by:CG_HD
ID: 20430553
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.
0
 
LVL 12

Expert Comment

by:jkmyoung
ID: 20444801
Use the value property of the attribute to write it back, as shown here, eg attr.value = "James";
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
A short film showing how OnPage and Connectwise integration works.

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now