Xml Namespaces I've Loved and the Nature of RSS

by Kofi Sarfo 20. September 2009 17:02

Yesterday, during yet another interview, we didn't deliver quite  the finest explanation of what an XML Namespace is. Today, we're using them to parse a Stack Overflow feed so clearly we understand them, however, if part of the question's purpose is to assess our ability to express this simple idea simply then shitehawks! #fail

Take this feed, for example, which is the RSS for a useful post on Volatile vs. Interlocked vs. lock. In order to to be able to use XPath with XDocument to retrieve the question we rely on XmlNamespaceManager.

    var xDoc = XDocument.Load("http://stackoverflow.com/feeds/question/154551");

    var xmlNamespaceManager = new XmlNamespaceManager(new NameTable());
        xmlNamespaceManager.AddNamespace("atom", "http://www.w3.org/2005/Atom");

    var postedQuestion 
        = xDoc.XPathSelectElement("/atom:feed/atom:entry/atom:summary", xmlNamespaceManager);

This is another example of Stack Overflow brilliance. The feeds are in chronological order so that we can guarantee that the first item (or entry) is the original post. Following the Volatile trail leads to a Joe Duffy post on Volatile Reads and Writes, and Timeliness. For example, he writes the C# documentation for volatile is highly misleading with reference to the following MSDN documentation:

The volatile modifier is usually used for a field that is accessed by multiple threads without using the lock statement to serialize access. Using the volatile modifier ensures that one thread retrieves the most up-to-date value written by another thread.

Unfortunately, I can't find this specific RSS item within the Technology feed and the same is true for the RSS feed for this blog. Although it's possible to score a reference to the item if it appears within the list of entries as they each have a unique ID, should the category contain too many entries then the older posts don't show up. Soon I'll show why this might matter but I digress.

The quoted paragraph above came as some surprise and a few hours reading suggests that:
  1. This stuff is hard!
  2. It would take *years* at the exclusion of a whole lotta stuff to have a legitimate claim to deep understanding of the intricacies of threading in .NET
  3. A solid handle on this C# Threading series of posts might just be enough (for now).
The real trick, however, might be recall during interview. There's definitely a theme here.

Kiva Loans

  • Jackline

    Jackline

    Quarrying

    Requested loan: $300

    Amount raised: $0

    Mombasa, Kenya

    to buy a stone cutting machine and to boost her business.

    Loan Now »

  • Cecile

    Cecile

    Cereals

    Requested loan: $700

    Amount raised: $0

    Ouagadougou, Burkina Faso

    to buy 5 bags of fonio (millet) to save and improve the living conditions of her family.

    Loan Now »

  • Ambrose

    Ambrose

    Agriculture

    Requested loan: $825

    Amount raised: $0

    Lira, Uganda

    to buy agro-produce to sell in order to increase his income and educate his children.

    Loan Now »

To see more entrepreneurs »

Make a loan to an entrepreneur across the globe for as little as $25. Kiva is the world's first online lending platform connecting online lenders to entrepreneurs across the globe.