Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 260643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:21:55+00:00 2026-05-11T22:21:55+00:00

I was writing a generic class to read RSS feed from various source and

  • 0

I was writing a generic class to read RSS feed from various source and to consolidate in one collection of object in VB.net.

Basically the function – using LINQ to XML – is working properly, but I have a problem when the RSS feed I am trying to read does not contain one of the node (as you know, many of them are optional). I would the returned value to be an empty string or nothing, but instead I get a runtime error back.
I searched the web for the same problem and I found this post http://forums.asp.net/p/1351226/2762834.aspx#2762834 that apparently explain a workaround, but it does not work with my code.

I am also surprised by the little resources I am finding about this issue, so I am now wondering if I am even putting the question in the right terms…

Following you can find the code:

Dim PostsEnum = From BlogPost In XMLSource.Descendants("item")
    Order By DateTime.Parse(BlogPost.Element("pubDate").Value) Descending
    Select New Post() With {
        .Title = BlogPost.Element("title").Value,
        .Link = BlogPost.Element("link").Value,
        .Description = BlogPost.Element("description").Value,
        .AuthorText = BlogPost.Element("author").Value,
        .Category = (From tag In BlogPost.Descendants("category")
            Select cat = tag.FirstNode.ToString).ToList,
        .PubDate = DateTime.Parse(BlogPost.Element("pubDate").Value),
        .GUID = BlogPost.Element("guid").Value
     }

i tried this on http://neatlydoc.codeplex.com/Project/ProjectRss.aspx and it worked, but the following code will generate the exception:

Dim PostsEnum = From BlogPost In XMLSource.Descendants("item")
    Order By DateTime.Parse(BlogPost.Element("pubDate").Value) Descending
    Select New Post() With {
        .Title = BlogPost.Element("title").Value,
        .Link = BlogPost.Element("link").Value,
        .Description = BlogPost.Element("description").Value,
        .AuthorText = BlogPost.Element("author").Value,
        .Category = (From tag In BlogPost.Descendants("category")
             Select cat = tag.FirstNode.ToString).ToList,
        .PubDate = DateTime.Parse(BlogPost.Element("pubDate").Value),
        .GUID = BlogPost.Element("guid").Value,
        .Source = CType(BlogPost.Element("source").Value, String)
    }

Any help will be appreciated.

Thanks

Luca

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T22:21:55+00:00Added an answer on May 11, 2026 at 10:21 pm

    If you try to evaluate .Value (etc) – then yes, it will break – however, you might try casting (apols, but my example is C# – you’ll have to imagine the VB):

        select new {
          Name = (string)el.Element("abc")
          ...
        }
    

    The explicit static conversion operator accepts null nodes and returns nulls appropriately. For more complex scenarios, just test it:

          let child = el.Element("SomeChild")
          select new {
             Name = child == null ? (string)null : (string)child.Attribute("Name")
             ...
          }
    

    Hard to be more specific without example xml/code…


    Edit re your update; the problem is that you are still reading .Value; change it to:

    .Source = CType(BlogPost.Element("source"), String)
    

    There is a conversion operator from XElement to string; you don’t need to look at .Value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 121k
  • Answers 122k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer ddddddddddddddddddddddddddddddddddddddddddddddddddddddd is > 181px. Its obviously going to overflow because… May 12, 2026 at 12:35 am
  • Editorial Team
    Editorial Team added an answer Firstly (and out of curiosity) how does the current schema… May 12, 2026 at 12:35 am
  • Editorial Team
    Editorial Team added an answer Html.Password helper does not use ViewData automatically (see ASP.NET MVC… May 12, 2026 at 12:35 am

Related Questions

I was writing a toString() for a class in Java the other day by
I was writing some ASP.NET control when I came to the scenario where I
Hy, I'm writing a class which should help me in unit tests. The class
When writing xml documentation you can use <see cref=something>something</see> , which works of course.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.