I have the following SOAP response and I want to get the value from the tag element a:Year1. How can I achieve this using c#?
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<GetPerformanceAndRiskByTypeCodeResponse xmlns="http://tempuri.org/">
<GetPerformanceAndRiskByTypeCodeResult xmlns:a="http://schemas.datacontract.org/2004/07/FE.Toolkit.Services.DataContracts.ResponsiveChartingTool" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<IsSuccessful xmlns="http://schemas.datacontract.org/2004/07/FE.Toolkit.Services.DataContracts">false</IsSuccessful>
<ResponseCode xmlns="http://schemas.datacontract.org/2004/07/FE.Toolkit.Services.DataContracts">0</ResponseCode>
<ResponseMessage i:nil="true" xmlns="http://schemas.datacontract.org/2004/07/FE.Toolkit.Services.DataContracts" />
<TotalRows xmlns="http://schemas.datacontract.org/2004/07/FE.Toolkit.Services.DataContracts">0</TotalRows>
<a:CalendarPerformanceAs>2019-12-31T00:00:00</a:CalendarPerformanceAs>
<a:CumulativePerformanceAs>2020-10-01T00:00:00</a:CumulativePerformanceAs>
<a:DiscretePerformanceAs>2020-09-30T00:00:00</a:DiscretePerformanceAs>
<a:InstrumentInformation>
<a:InstrumentInformation>
<a:CalendarPerformance>
<a:IncomeBasisPriceType>2</a:IncomeBasisPriceType>
<a:PerformanceCurrency>USD</a:PerformanceCurrency>
<a:Year1>19.031154</a:Year1>
<a:Year2>-13.434495</a:Year2>
<a:Year3>23.004020</a:Year3>
<a:Year4>-5.584117</a:Year4>
<a:Year5>-2.882996</a:Year5>
</a:CalendarPerformance>
</a:InstrumentInformation>
</a:InstrumentInformation>
<a:RiskAs>2020-09-30T00:00:00</a:RiskAs>
</GetPerformanceAndRiskByTypeCodeResult>
</GetPerformanceAndRiskByTypeCodeResponse>
</s:Body>
</s:Envelope>
I tried the following but no luck:
var str = XElement.Parse(xml.Response.XmlResponse.ToString());
var result = str.Element("InstrumentInformation").Element("InstrumentInformation")[0].Element("CalendarPerformance").Element("Year1").Value;
Console.WriteLine("RESULT" + result);
The error is
Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.