Getting child node in XmlNodeList


I have extracted a nodelist.  I can then loop through each node.

XmlNodeList mNodes = piXML.SelectNodes("library/Book ");

      <title>Three Little Pigs</title>

This works okay, but give  that I have node[“title”].innertext how can I get it to return the value held within the author element?

I’ve tried node[“title\author”].innertext but I get an error.

Any suggestions appreciated.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rikin ShahMicrosoft Dynamics CRM ConsultantCommented:

node[“author”].innertext will do the thing!!

I *think* what you mean is you want to retrieve the Author for the current Title?

If so, you will need to keep track of the current loop iteration (not tested):
var currentAuthor;
var currentTitle;
var output = new Array();
books = xml.getNodes("book"); 
  //build an array of objects representing book title and author:

Open in new window

Once you have the currentAuthor and currentTitle for each book stored in the 'output' object, you can do what you want with it. The key point is that you now have an object where - for a given book - the title is associated with the author, and you can refer to - for example - the third book like so:
var 3rdAuthor = output[2].author;
var 3rdTitle = output[2].title;

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
andyw27Author Commented:
ok thanks.
no problem :-)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.