0
<?xml version="1.0" encoding="utf-8" ?>
<Response success="true">
  <data>
    <class name="getId" classValue=" this is a class value"></class>
  </data>
</Response>

string strPath = @"C:\Users\Fale\Documents\practice\xpathNavigator\xpathNavigator\1.xml";
XDocument Xdco = XDocument.Load(strPath);

var list = from i in Xdco.Root.Descendants("Response")
           where i.Attribute("success").Value == "true"
           select i.Element("data").Element("class").Attribute("classValue").Value;

How to check response is true and then to get attribute value using linq c#?

har07
  • 88,338
  • 12
  • 84
  • 137
yash fale
  • 235
  • 1
  • 4
  • 19
  • have a look: http://stackoverflow.com/questions/670563/linq-to-read-xml – Riad Oct 02 '16 at 12:29
  • this is working , its my mistake, i used root,descendants , so it was giving wrong result , var list = from i in Xdco.Descendants("Response") where i.Attribute("success").Value == "true" select i.Element("data").Element("class").Attribute("classValue").Value; – yash fale Oct 02 '16 at 12:36

1 Answers1

0
var list = from i in Xdco.Descendants("Response") 
           where i.Attribute("success").Value == "true" 
           select i.Element("data").Element("class").Attribute("classValue").V‌​alue;
Gilad Green
  • 36,708
  • 7
  • 61
  • 95
yash fale
  • 235
  • 1
  • 4
  • 19