Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you generate a good ID in ATOM documents?

Tags:

Apparently using the URL is no good - why is this the case, and how do you generate a good one?

like image 752
Rich Bradshaw Avatar asked Sep 29 '08 21:09

Rich Bradshaw


People also ask

What is the ID of an atom?

The number of protons in the nucleus of an atom is its atomic number (Z). This is the defining trait of an element: Its value determines the identity of the atom. For example, any atom that contains six protons is the element carbon and has the atomic number 6, regardless of how many neutrons or electrons it may have.

What is Atom entry?

The items of information that make up an Atom feed are known as Atom entries. A content provider publishes, or "syndicates", an Atom feed by making it available through a URL on the Internet and updating it with new items.

What is the root element of an Atom feed?

The root element of an Atom feed is the <feed> element, which contains metadata and a collection of <entry> elements. Text constructs (indicated with <<text>> in the diagram) may contain a type attribute with a value of text for plain text, html for escaped HTML, or xhtml for XHTML.


2 Answers

Mark Pilgrim's article How to make a good ID in Atom is good. Here's part of it:

Why you shouldn’t use your permalink as an Atom ID

It’s valid to use your permalink URL as your <id>, but I discourage it because it can create confusion about which element should be treated as the permalink. Developers who don’t read specs will look at your Atom feed, and they see two identical pieces of information, and they pick one and use it as the permalink, and some of them will pick incorrectly. Then they go to another feed where the two elements are not identical, and they get confused.

In Atom, <link rel="alternate"> is always the permalink of the entry. <id> is always a unique identifier for the entry. Both are required, but they serve different purposes. An entry ID should never change, even if the permalink changes.

“Permalink changes”? Yes, permalinks are not as permanent as you might think. Here’s an example that happened to me. My permalink URLs were automatically generated from the title of my entry, but then I updated an entry and changed the title. Guess what, the “permanent” link just changed! If you’re clever, you can use an HTTP redirect to redirect visitors from the old permalink to the new one (and I did). But you can’t redirect an ID.

The ID of an Atom entry must never change! Ideally, you should generate the ID of an entry once, and store it somewhere. If you’re auto-generating it time after time from data that changes over time, then the entry’s ID will change, which defeats the purpose.

like image 172
cjm Avatar answered Oct 11 '22 06:10

cjm


Use a GUID for the ID.

depends what language you use, but you could use

System.Guid for .NET.

like image 28
SpoiledTechie.com Avatar answered Oct 11 '22 07:10

SpoiledTechie.com