XElement join throwing exception Object reference not set to an instance of an object.

  • Thread starter Thread starter Sudip_inn
  • Start date Start date
S

Sudip_inn

Guest
i have a xml file which has many element called TickerBrokerDateFormatMaps & TickerBrokerDateFormatMap

i am just joining two element by TickerBrokerDateFormatMaps_Id

this is my sample xml

<TickerBrokerDateFormatMaps BrokerTab_Id="0" Broker_Id="0" Ticker_Id="KDP">
<TickerBrokerDateFormatMaps_Id>1</TickerBrokerDateFormatMaps_Id>
<DateFormat>1Q,2Q,3Q,4Q,FY,SPACE</DateFormat>
<dgvcollection_Row_index>0</dgvcollection_Row_index>
</TickerBrokerDateFormatMaps>

<TickerBrokerDateFormatMap BrokerTab_Id="1" Broker_Id="0" Ticker_Id="KDP">
<StandardDate>2Q 2017A</StandardDate>
<ColumnCoordinate>Q</ColumnCoordinate>
<TickerBrokerDateFormatMaps_Id>1</TickerBrokerDateFormatMaps_Id>
<BrokerDate StandardDate="2Q 2017A" Broker_Id="0" BrokerTab_Id="1">
<year>2Q17 A</year>
<Quater>2Q17 A</Quater>
</BrokerDate>
</TickerBrokerDateFormatMap>


XElement AllDateMapElement = XElement.Load(pathTickerBroker);

var query1 = (from s7 in AllDateMapElement.Elements("TickerBrokerDateFormatMaps")
join s8 in AllDateMapElement.Elements("TickerBrokerDateFormatMap")
on (string)s7.Element("TickerBrokerDateFormatMaps_Id") equals (string)s8.Element("TickerBrokerDateFormatMaps_Id")
select new
{
Quater = Convert.ToString(s8.Element("BrokerDate").Element("Quater").Value),
YearQuater = Convert.ToString(s8.Element("BrokerDate").Element("year").Value)
}).ToList();

I am trying to fetch value from nested element of BrokerDate element and those elements are

Quater & YearQuater but getting exception. is there any syntax wrong ?

if i comment below two lines then not getting any exception.


Quater = Convert.ToString(s8.Element("BrokerDate").Element("Quater").Value),
YearQuater = Convert.ToString(s8.Element("BrokerDate").Element("year").Value)

i guess this syntax is ok s8.Element("BrokerDate").Element("year").Value

what wrong is there in my code for which i am getting error. please help. thanks

Continue reading...
 
Back
Top