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 7533621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:46:38+00:00 2026-05-30T05:46:38+00:00

I am using this function public static IList<Item> ParseAtom(string url) { try { XDocument

  • 0

I am using this function public static

    IList<Item> ParseAtom(string url)
    {
        try
        {
            XDocument doc = XDocument.Load(url);

            // Feed/Entry
            var entries = from item in doc.Root.Elements().Where(i => i.Name.LocalName == "entry")
                          select new Item
                          {
                              FeedType = FeedType.Atom,
                              Content = item.Elements().First(i => i.Name.LocalName == "content").Value,
                              Link = item.Elements().First(i => i.Name.LocalName == "link").Attribute("href").Value,
                              PublishDate = ParseDate(item.Elements().First(i => i.Name.LocalName == "published").Value),
                              Title = item.Elements().First(i => i.Name.LocalName == "title").Value
                          };

            return entries.ToList();
        }
        catch
        {
            return new List<Item>();
        }
    }

I am using the following link
http://localhost/posts.atom/

When i open that link in the browser I see the list of links that direct me to each post item.

  1. 1 Link 2 Link 3 Link 4 Link

but I when I use it as a url to parse, my program return nothing. I suppose myself that I don’t understand what the link above actually means. I really need any of your help to offer me somemore explanation of atom feed, thank you very much .

The XML is created by another file that is stored as a stream as in the following format

<Root>
  <Child id=123456>
     <Child1>Child1
     </Child1>  
     <Child2>Child2
     </Child2>  
  </Child>
</Root>
  • 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-30T05:46:40+00:00Added an answer on May 30, 2026 at 5:46 am

    I strongly suspect that an exception is being thrown – but you can’t tell because you’re “handling” all exceptions by returning an empty list, without recording what the exception is or any kind of diagnostics. I would personally remove the try/catch altogether: if something is wrong, why hide that? If you must catch the exception, then catch specific exceptions, and log them so you know what’s happened.

    Your query can be simplified considerably, too:

    XDocument doc = XDocument.Load("atom.xml");
    XNamespace ns = "http://www.w3.org/2005/Atom";
    
    var entries = doc.Root
                     .Elements(ns + "entry")
                     .Select(item => new Item
                     {
                          FeedType = FeedType.Atom,
                          Content = (string) item.Element(ns + "content"),
                          Link = (string) item.Element(ns + "link").Attribute("href"),
                          PublishDate = (DateTime) item.Element(ns + "published"),
                          Title = (string) item.Element(ns + "title")
                      };
    

    Note that this will now set Content and Title to null if those elements don’t exist; change to using .Value again if you would rather it threw an exception. You can get the same behaviour for PublishDate by casting to DateTime? instead of DateTime, obviously after changing the type of the property too. Handling absent links would be slightly harder, but not too bad – let me know if you want a hand there.

    Basically I suspect it’s an absent element – quite possibly published. It’ll be easier to find out when you’re logging (or not catching) exceptions though.

    EDIT: Given your comment, it sounds like this has absolutely nothing to do with how you’re handling the XML – it’s loading the XML that’s causing the problem. This is where not swallowing exceptions is important…

    I don’t know of any way to provide credentials when loading XML via XDocument.Load – you may well need to use WebRequest or WebClient to fetch the data, then parse it with XDocument.Load(Stream).

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

Sidebar

Related Questions

I've got this function public static AdoEntity.Inspector GetInspectorWithInclude(int id, List<string> properties) { using (var
I have this function: public static string RenderViewToString(string controlName, object viewData) { ViewDataDictionary vd
Using this function in my C# exe, I try to pass a Unicode string
I wrote this utility function: public static <T> List<T> pluck(String fieldName, List list) throws
I have this fetch function: public static function fetch($class, $key) { try { $obj
I'm using an anonymous delegate in my code calling this example function: public static
I have the following function call: public static MvcHtmlString NavLinks( this HtmlHelper helper, IList<MenuItem>
I am having following function public static Date parseDate(String date, String format) throws ParseException
Consider this trivial function: public static bool IsPositive(IComparable<int> value) { return value.CompareTo(0) > 0;
I am trying to execute this function: public static int QueryInterface( IntPtr pUnk, ref

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.