Link to home
Start Free TrialLog in
Avatar of bcp5190
bcp5190

asked on

how can i use getElementsByTagName with parent where conditions?

<BOOKINFO>
    <NAME>xyz</NAME>
    <AUTHORS>
         <ENGLISH>
             <NAME>name1</NAME>
         <ENGLISH>
         <SPANISH>
             <NAME>name2</NAME>
         </SPANISH>
    </AUTHORS>
</BOOKINFO>

I have xml string similiar to shown as above now
using DOM how can i find name of the author if BOOKINFO.NAME = "xyz"

First choice should be english authour if not only then spenish author

i'm trying something like this
Set ElemList = xmlDoc.getElementsByTagName("NAME")
but how can i have name of the authors for only xyz book

or is there any other way i can do this?
Avatar of chabaud
chabaud

A good idea should be to use XPath:

Set ElemList = xmlDoc.documentElement.selectNodes("//BOOKINFO/Name['xyz']/AUTHORS//NAME")
Avatar of bcp5190

ASKER

i try it but didn't work i think because AUTHORS is not child of NAME .
AUTHORS is child of BOOKINFO
ASKER CERTIFIED SOLUTION
Avatar of chabaud
chabaud

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial