Solved

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

Posted on 2001-09-05
5
285 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
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.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

762 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