Solved

How can i find XML list using  xmlDoc.documentElement.selectNodes?

Posted on 2001-09-05
5
280 Views
Last Modified: 2012-06-27
<BOOKINFO>
   <BOOKNAME>xyz</BOOKNAME>
   <PUBLISHERNAME>xyz1</PUBLISHERNAME>
   <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 BOOKNAME and PUBLISHERNAME for only ENGLISH author


i'm trying something like this
Set ElemList = xmlDoc.documentElement.selectNodes("//BOOKINFO/*/AUTHORS/ENGLISH/NAME")
but how can i get name of  BOOKNAME and PUBLISHERNAME only in ElemList


or is there any other way i can do this?
0
Comment
Question by:bcp5190
  • 2
  • 2
5 Comments
 
LVL 4

Expert Comment

by:edmund_mitchell
ID: 6458146
Hello bcp5190

Try selectNodes("/BOOKINFO/AUTHORS/ENGLISH/NAME")

HTH

Edmund
0
 

Author Comment

by:bcp5190
ID: 6458270
selectNodes("/BOOKINFO/AUTHORS/ENGLISH/NAME") will gives me all english name but i'm intrested in bookname and publisher name if any book has english authour.
i'm sorry for any confusion about question.
0
 
LVL 4

Accepted Solution

by:
sdussinger earned 25 total points
ID: 6458488
Try this:

selectNodes ("/BOOKINFO/AUTHORS[ENGLISH/NAME]/../BOOKNAME | /BOOKINFO/AUTHORS[ENGLISH/NAME]/../PUBLISHERNAME");

The problem with this approach is that it will return the PUBLISHERNAME and BOOKNAME elements in the same list. This may or may not be what you want. If you want to just get the parent node of anything which contains an english author, use this:

selectNodes ("/BOOKINFO/AUTHORS[ENGLISH/NAME]/..");

Then you can get the PUBLISHERNAME and BOOKNAME by:

bookinfoNode.selectNode ("PUBLISHERNAME");
bookinfoNode.selectNode ("BOOKNAME");

HTH

--Steve
0
 
LVL 4

Expert Comment

by:edmund_mitchell
ID: 6458494
OK
For all booknames and publisher names of any book that has an english author:
selectNodes("/BOOKINFO/BOOKNAME[following-sibling::AUTHORS[1]/ENGLISH/NAME] | /BOOKINFO/PUBLISHERNAME[following-sibling::AUTHORS[1]/ENGLISH/NAME]")

should do the trick.

I hope that answers your question, but if not, just let us know.

Edmund
0
 

Author Comment

by:bcp5190
ID: 6461374
last answer is also correct but i don't know how to give point to both of you. sorry and thanks to all of you.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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.
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

743 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

12 Experts available now in Live!

Get 1:1 Help Now