Solved

selectSingleNode from XML where value = ?

Posted on 2007-12-06
4
1,999 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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

808 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