locked
question about linq and XML RRS feed

  • Question

  • User932259438 posted

    Hi,

    -<betOfferResponse>
    
    
    -<events>
    
    <name>Tottenham - Sunderland</name>
    
    <homeName>Tottenham</homeName>
    
    <awayName>Sunderland</awayName>
    
    <start>2016-01-16T12:45Z</start>
    
    <group>Premier League</group>
    
    <type>ET_MATCH</type>
    
    <sport>FOOTBALL</sport>
    
    <state>NOT_STARTED</state>
    
    <liveBetOffers>true</liveBetOffers>
    
    <openForLiveBetting>false</openForLiveBetting>
    
    <id>1002750478</id>
    
    <groupId>1000094985</groupId>
    
    <sportId>1000093190</sportId>
    
    
    -<path>
    
    <id>1000093190</id>
    
    <name>Football</name>
    -<betOfferResponse>
    
    
    -<events>
    
    <name>Tottenham - Sunderland</name>
    
    <homeName>Tottenham</homeName>
    
    <awayName>Sunderland</awayName>
    
    <start>2016-01-16T12:45Z</start>
    
    <group>Premier League</group>
    
    <type>ET_MATCH</type>
    
    <sport>FOOTBALL</sport>
    
    <state>NOT_STARTED</state>
    
    <liveBetOffers>true</liveBetOffers>
    
    <openForLiveBetting>false</openForLiveBetting>
    
    <id>1002750478</id>
    
    <groupId>1000094985</groupId>
    
    <sportId>1000093190</sportId>
    
    
    -<path>
    
    <id>1000093190</id>
    
    <name>Football</name>


    I got:
    Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

    Source Error:

    Line 44:         var distDates = (from c in reposne.Descendants("events")
    Line 45:                          where  (Convert.ToDateTime(c.Element("start").Value.Replace("Z", "").Replace("T", " ")).AddHours(1) > DateTime.Now)//&& c.Element("awayName").Value == "Tottenham" //Convert.ToDateTime(c.Element("start").Value.Replace("Z", "").ToLocalDate().AddHours(1).CompareTo(DateTime.Now)
    Line 46:                          select new
    



    Why not got groupid? Other values I got, but groupid not got,

    groupid is in the same "events"

    Friday, January 15, 2016 3:14 PM

Answers

  • User-821857111 posted

    You haven't really shown the code you are using to get the groupid, or the actual code that causes the error you posted about.

    Also (not the cause of your problem), I don't know why you use string.Replace on the <start> value. It's a UTC time. The following code gives you the same result:

    where  (DateTime.Parse(c.Element("start").Value) > DateTime.UtcNow)
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, January 15, 2016 9:27 PM