c# code to check the xml node value

HI my new requirement is....

below is an xml file,

<bookstore>
<ID>id123<ID>
<book>boook1<book>
<author>J k rowling</author>
</bookstore>


here first it checks for id value and then it goes for author name..below is the code..

value i=xml.getelementbytagname("ID")[0].Innerxml;

If(value=="Id123")
{
if((xml.getelementbytagname("author")[0].InnerXml).contains("j k Rowling"))


This works fine,but my problem is below.pls check it


<bookstore>
<name1>
<book>boook1<book>
<author>J k rowling</author>
</name1>
<name2>
<book>boook1<book>
<author>J k rowling</author>
</name2>
</bookstore>

now my requirement is i want the c# code to check the name2 tag is present or not and then  verify wheter author name is "J k rowling " or not...

Based on my above code how will do it..revert back to me asap..needed urgently.....
sandydv85Asked:
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.

Carl TawnSystems and Integration DeveloperCommented:
Is you XML format fixed? Ordinarily you wouldn't give names an ordinal index because it kinda defeats the purpose of XML. Normally you would just use a collection of <name> elements without them having an ordinal index number tagged on. Largely in order to avoid the issue you currently have :)
0
sandydv85Author Commented:
yes they are fixed.but in the names place there may be diffferent tags..but i need only one tag name

for ex say " name2 "tag  in that tag it has to check author name by using the above code..thats it
0
sandydv85Author Commented:
Needed ASAP..please
0
Introduction to Web Design

Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.

Carl TawnSystems and Integration DeveloperCommented:
Well, very simplisticly, given your somewhat ropey Xml format, you could use:
XmlNode node = xml.GetElementsByTagName("name2")[0];

if((node.GetElementsByTagName("author")[0].InnerXml).Contains("j k Rowling"))

Open in new window

0

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
sandydv85Author Commented:
Hai carl..I cant read node.GetElementBytag Name ..please check it..and send me yar..
0
sandydv85Author Commented:
HI krunal, i was unable to get the solution here my requirement is..as follows..

of all the xml file, I have only one <name2> tag...so no need to check and..and in
that name2 tag , in second row,author is present..please send me the code to verify that..the author is" jk rowling " or not..
0
sandydv85Author Commented:
Thanks Carl
0
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
.NET Programming

From novice to tech pro — start learning today.