Solved

selectSingleNode from XML where value = ?

Posted on 2007-12-06
4
2,002 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
In sql, how to roll up multiple rows to only one row. 4 66
window close link 7 63
CURL sending XML without spaces PHP 5 74
add 'N to prepared ASP/VB insert statement 1 38
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 …
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

751 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