How to take out <atom: namespace

Topics: Argotic.Common
Dec 11, 2007 at 3:22 PM
Does any body know how do I get rid of namespace showing in every single atom tag ?

<atom: ....

BTW is there any place there for someone starting with argotic/feeds...?

thanks in advance for yourrhelp

Ja Nuhe
Madrid, Spain
Coordinator
Dec 11, 2007 at 4:10 PM
Januhe,

This is a minor issue in the implementation, as the framework is using the XmlWriter.WriteStartElement(prefix, localName, ns) method when it should actually be using XmlWriter.WriteStartElement(localName, ns) method. As long as there is a default XML namespace declared on the root element (e.g. xmlns="http://www.w3.org/2005/Atom") then the writer would not write a prefix to the element.

Having the 'atom:' prefix is still per spec however (http://www.atomenabled.org/developers/syndication/atom-format-spec.php), this just has the unfortunate affect of making the feed XML data larger than necessary. I will open a low priority issue on this to be fixed in the next release of the framework, thanks for the feedback!

See http://argotic.oppositionallydefiant.com/api/ for the framework API documentation, there are integrated examples in the compiled/online help documentation.
Dec 11, 2007 at 5:22 PM
I do see a default XML namespace declared on the root element, but the writer apparently ignores it, doesn't it?
Seems like I'm missing something.
Coordinator
Dec 13, 2007 at 3:57 PM
The internal write methods of the Atom feed entities in the framework are explicitly outputting the namespace prefix (which is unnecessary when a default XML namespace is present). This is the minor bug I mentioned above, and I have opened an issue to fix this problem.
Mar 17, 2008 at 6:27 PM
This still appears to be a problem in 2008 beta 1 for the 3.5 framework.
Coordinator
Mar 17, 2008 at 8:30 PM
When I run the Atom Feed Example, I am not seeing the atom: prefixing issue, as the XML namespace (xmlns="http://www.w3.org/2005/Atom") is the root of the document. Can you please send/post some example code that demonstrates your issue? I can't repro this with the Beta 1 bits.
Mar 17, 2008 at 11:12 PM
I'm actually having this problem with trying to read an Atom feed rather than create one. When I iterate through entries in the AtomFeed object, each entry.ID element has the xmlns tag around it. I'm trying to put together an example but this web permissions business is a pain in the ass...
Mar 17, 2008 at 11:47 PM
Ok, I put together an example. This actually worked fine with the old 2.0 version that I was using, but when I updated to 2008 beta 1 with the 3.5 framework, using the exact same feed, I now get the xmlns tags. I sent you an e-mail through Codeplex, if you reply to that I can send you the files for the example.
Coordinator
Mar 18, 2008 at 7:59 PM
Ok, that makes more sense, as the original issue was one of feed generation, where it sounds like your issue is on the read/parse side of things. Looking forward to getting the example from you, until then I will investigate based on your comments about AtomEntry.Id property . Can you post the URL of the AtomFeed you are consuming?
Coordinator
Mar 18, 2008 at 8:33 PM
Can you describe where/how you are seeing the atom: prefix on the AtomEntry? The only time I 'see' the xmlns attribute is if I was calling AtomEntry.ToString(), as there is no root xmlns to resolve the entity prefixing. Typically you would not use the ToString() method, and instead use the public API that Atom feed and entry classes expose.

The framework API isolates you from the raw XML representation, except in the case of the ToString() methods, so I guess I need more information, as I not not see any unexpected XML namespaces or namespace prefixes. Please feel free to post a brief code example that might clarify the issue you are having.

Atom feed/entry parsing example:

using System.IO;
using Argotic.Syndication;
 
AtomFeed feed   = AtomFeed.Create(new Uri("http://news.google.com/?output=atom"));
 
// Persist the first entry in the feed. Entry XML utilizes Atom root XML namepace, as expected
using (FileStream stream = new FileStream("GoogleNewsEntry.xml", FileMode.Create, FileAccess.Write))
{
    feed[0].Save(stream);
}
 
// Enumerate through feed entries
foreach (AtomEntry entry in feed.Entries)
{
    //  Entry unique identifer information (note this is a Uri and NOT a Url).
    AtomId entryId  = entry.Id;
    Uri entryUri    = entryId.Uri;  // Example: tag:news.google.com,2005:cluster=442c192b
    
    // Get web resources referenced by entry (rel = 'alternate', type = 'text/html', so points to full content for the entry)
    foreach (AtomLink link in entry.Links)
    {
        string title    = link.Title;
        string mimeType = link.ContentType;
        Uri url         = link.Uri;
    }
}
 
//  Persisted feed utilizes Atom root XML namepace, as expected
using (FileStream stream = new FileStream("GoogleNews.atom.xml", FileMode.Create, FileAccess.Write))
{
    feed.Save(stream);
}
Coordinator
Mar 19, 2008 at 12:35 AM
After looking at Stefan's test example, I wanted to make a point of clarification. If you were to do the following ,you would be implicitly calling the ToString() method of the entry's Id and Summary properties.

Uri address = new Uri("http://localhost/atomtest.xml");
AtomFeed feed = AtomFeed.Create(address);
foreach (AtomEntry entry in feed.Entries)
{
    Text1.Text += "ID: " + entry.Id + "\n\nSummary: " + entry.Summary;
}

If you were after the typical values for these properties, you might do the following instead:

Uri address = new Uri("http://localhost/atomtest.xml");
AtomFeed feed = AtomFeed.Create(address);
foreach (AtomEntry entry in feed.Entries)
{
    Text1.Text += "ID: " + entry.Id.Uri + "\n\nSummary: " + entry.Summary.Content;
}

Most of the framework syndication entities have overloaded the ToString() method to return either the XML representation of the entity, or a human readable representation when the entity does not map to a specific XML schema. This has to do with implementing the IComparable interface, and it is expected that framework entities will be accessed using their public properties. If you wish to use the ToString() method for an entity, please review the API documentation to determine if it returns an XML or human-readable representation and be prepared to parse the value accordingly.