Retrieve XML data based on node id attribute

I need to find out how to access the xml data for only a certain store id.  I've attached a sample xml code and would like to know how I can retrieve just the data found for store with id "C1".  I want to store the childnode values into their respective variables e.g. <ccompanyname>Company1</ccompanyname> would be stored in a ccompany variable.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<store_variables xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<store id="C1">
		<ccompanyname>Company1</ccompanyname>
		<caddress>Address1A</caddress>
		<caddress2>Address2A</caddress2>
		<ccity>City1</ccity>
		<cstate>CA</cstate>
		<czip>90045</czip>
		<cemail>email1</cemail>
		<cphonenumber>phone1</cphonenumber>
		<cfaxnumber>fax1</cfaxnumber>
	</store>
	<store id="C2">
		<ccompanyname>Company2</ccompanyname>
		<caddress>Address1B</caddress>
		<caddress2>Address2B</caddress2>
		<ccity>City2</ccity>
		<cstate>CA</cstate>
		<czip>90045</czip>
		<cemail>email2</cemail>
		<cphonenumber>phone2</cphonenumber>
		<cfaxnumber>fax2</cfaxnumber>
	</store>
	<store id="C3">
		<ccompanyname>Company3</ccompanyname>
		<caddress>Address3A</caddress>
		<caddress2>Address3B</caddress2>
		<ccity>City3</ccity>
		<cstate>CA</cstate>
		<czip>90045</czip>
		<cemail>email3</cemail>
		<cphonenumber>phone3</cphonenumber>
		<cfaxnumber>fax3</cfaxnumber>
	</store>
	<store id="C4">
		<ccompanyname>Company4</ccompanyname>
		<caddress>Address4A</caddress>
		<caddress2>Address4B</caddress2>
		<ccity>City4</ccity>
		<cstate>CA</cstate>
		<czip>90045</czip>
		<cemail>email4</cemail>
		<cphonenumber>phone4</cphonenumber>
		<cfaxnumber>fax4</cfaxnumber>
	</store>
</store_variables>

Open in new window

LVL 3
UndisputedAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hieloCommented:
assuming your xml is from a file
Dim xml

xml="file.xml"
Set xmlDoc=Server.CreateObject("MSXML2.DOMDocument")
xmlDoc.load xml


xmlDoc.setProperty "SelectionLanguage", "XPath"

'this select the specific node you are after
Set node = xmlDoc.documentElement.selectSingleNode("//store_variables/store[@id='C1']")

'store has several nodes. The following iterates through these
For Each child in node.childnodes
	Response.write( "<br>"+child.text )
Next
Set node = Nothing
Set xmlDoc = Nothing

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
hieloCommented:
If you already have the xml as a string in some variable named "xml", then use:
Set xmlDoc =Server.CreateObject("MSXML2.DOMDocument")
xmlDoc.loadXML xml


xmlDoc.setProperty "SelectionLanguage", "XPath"
Set node = xmlDoc.documentElement.selectSingleNode("//store_variables/store[@id='C1']")
For Each child in node.childnodes
	document.write( "<br>"+child.text )
Next
Set node = Nothing
Set xmlDoc = Nothing

Open in new window

0
UndisputedAuthor Commented:
Thanks Hielo!  This is exactly what I needed.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.