.netfeedatom-feedopensearchsyndicationfeed

Confused about namespaces in Atom feed


Is there any difference between

<opensearch:totalResults>1000</opensearch:totalResults>

and

<totalResults xmlns="opensearch">1000</totalResults>

I'm using the SyndicationFeed class in .NET to generate an Atom feed, and I need to add some elements for the opensearch standard, but it keeps adding elements like the latter one above when I want it to add them like the former one.

The code:

feed.ElementExtensions.Add("totalResults", "opensearch", "2");

EDIT

The root feed tag looks like this

<feed xml:lang="en-US" p1:opensearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:p1="xmlns" xmlns="http://www.w3.org/2005/Atom">

After changing my code as @Reddog suggested, the totalresults element looks like this

<totalResults xmlns="http://a9.com/-/spec/opensearch/1.1/">1000</totalResults>

The code that adds the namespace to the feed tag looks like this

feed.AttributeExtensions.Add(
    new XmlQualifiedName("opensearch", "xmlns"),
    @"http://a9.com/-/spec/opensearch/1.1/");

And the code that adds the totalresults element now looks like this

feed.ElementExtensions.Add("totalResults", @"http://a9.com/-/spec/opensearch/1.1/", "1000");

Solution

  • Nevermind. I realized that I was adding the namespace incorrectly. It should be

    feed.AttributeExtensions.Add(
       new XmlQualifiedName("opensearch", "http://www.w3.org/2000/xmlns/"),
       "http://a9.com/-/spec/opensearch/1.1/");