• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 255
  • Last Modified:

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?
0
bcp5190
Asked:
bcp5190
  • 2
1 Solution
 
chabaudCommented:
A good idea should be to use XPath:

Set ElemList = xmlDoc.documentElement.selectNodes("//BOOKINFO/Name['xyz']/AUTHORS//NAME")
0
 
bcp5190Author Commented:
i try it but didn't work i think because AUTHORS is not child of NAME .
AUTHORS is child of BOOKINFO
0
 
chabaudCommented:
Oops, try:

//BOOKINFO[Name='xyz']/AUTHORS//NAME
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now