Solved

selectSingleNode from XML where value = ?

Posted on 2007-12-06
4
1,993 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Use the value property of the attribute to write it back, as shown here, eg attr.value = "James";
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

762 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

10 Experts available now in Live!

Get 1:1 Help Now