Avatar of nthawkins1971
nthawkins1971
Flag for Hong Kong asked on

Classic ASP and XML - Selecting a specific node

Hi, I' need to select a specific node in an xml doc... i have this which gives me everything

For Each xmlNode In objXML.documentElement.selectNodes("Data")

but i need a single node and its related nodes that has a specific value.. please see the xml

for example: I need to select only the Data where Bookcode = NEA-CSOP

Thank you

<DocumentElement>
<Data>
  <BookCode>NEA-CSOP</BookCode>
  <BPSday>3</BPSday>
  <BPSwk>6</BPSwk>
  <BPSmth>8</BPSmth>
  <Trackday>-44.6</Trackday>
  <TrackPnL>0</TrackPnL>
  <WAIVImv>0.239</WAIVImv>
  <WAIVexp>0.252</WAIVexp>
  <x90Day>0.256</x90Day>
</Data>

<Data>
<BookCode>NEA-EA1</BookCode>
<BPSday>18</BPSday>
<BPSwk>39</BPSwk>
<BPSmth>44</BPSmth>
<Trackday>-23.5</Trackday>
<TrackPnL>0</TrackPnL>
<WAIVImv>0.219</WAIVImv>
<WAIVexp>0.217</WAIVexp>
<x90Day>0.256</x90Day>
</Data>

<Data>
<BookCode>NEK-MV4</BookCode>
<BPSday></BPSday>
<BPSwk></BPSwk>
<BPSmth></BPSmth>
<Trackday></Trackday>
<TrackPnL></TrackPnL>
<WAIVImv></WAIVImv>
<WAIVexp></WAIVexp>
<x90Day></x90Day>
</Data>
<DocumentElement>

Open in new window

Node.jsASPXMLJavaScript

Avatar of undefined
Last Comment
Ryan Chong

8/22/2022 - Mon
Flabio Gates

Can you try:
For Each xmlNode In objXML.documentElement.selectNodes("Data[text()='NEA-CSOP']")

Open in new window

nthawkins1971

ASKER
Doesn't seem to work, however it doesnt cause an error.. should I add BookCode in some way... like, Data.BookCode[text()='NEA-CSOP' ?


For Each xmlNode In objXML.documentElement.selectNodes("Data[text()='NEA-CSOP']")
Flabio Gates

Data/BookCode[text()='NEA-CSOP']
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Flabio Gates

But that would get you the BookCode node.
You'll need to get back up 1 level to the Data node.
Not sure as I'm on my phone but it would look like
Data/BookCode[text()='NEA-CSOP']/parent-node::*
Ryan Chong

try this instead.

Data[BookCode/text()='NEA-CSOP']

Open in new window

nthawkins1971

ASKER
Absolutely perfect! thanks
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
Flabio Gates

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Ryan Chong

well, absolutely perfect but yet not accepted as answer?