Click here to Skip to main content
16,016,460 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
<Materials>
  <Material>
    <mtlCode>1</mtlCode>
    <mtlName>Activa</mtlName>
  </Material>
  <Material>
    <mtlCode>2</mtlCode>
    <mtlName>Ancor</mtlName>
  </Material>
</Materials
-----------------------------------------


doc.Load(xmlFilePath);
XmlNodeList xmlnode = doc.SelectNodes"/Materials/Material[mtlCode=2]/mtlName");
string stringNode = xmlnode[0].Value;
------------------------------------------

But this code return null always.
How can I get the value (ie. Ancor) as per mtlCode=2;

Plz provide corrected code..
Posted

Hi,

Try replacing the Value with InnerText, like:
string stringNode = xmlnode[0].InnerText;
 
Share this answer
 
Comments
SHAJANCHERIAN 11-Apr-11 1:00am    
Thanks
Wendelius 11-Apr-11 9:47am    
You're welcome :)
Hello,

You also can try something like this.

string stringNode = doc.SelectSingleNode("/Materials/Material[mtlCode=2]/mtlName").InnerText;

OR

string stringNode = doc.SelectNodes("/Materials/Material[mtlCode=2]/mtlName").Item(0).InnerText
 
Share this answer
 
Comments
SHAJANCHERIAN 11-Apr-11 0:59am    
Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900