|Page (1) of 1 - 05/06/10||email article||print page|
Real-World XML: Part 8 of 12Adding entry tags to the Atom feed
XML technologies offer web developers and designers more flexibility than ever before. In Real-World XML, industry expert Joe Marini covers the best programming practices with XML, including the tools needed to build effective XML structures. He demonstrates the implementation of XML formats, how these formats work in real-world situations, and how they can facilitate project planning and development. Exercise files accompany the course.
XML Essential Training is a prerequisite for getting the most out of this course.
- ?Understanding the Sitemap index format
- Integrating XML and design
- Using XML effectively in Firefox and Internet Explorer
- Avoiding common design mistakes
- Understanding and implementing DOM algorithms
- Building an XML tag set
- Using XML with RSS and Atom
- Processing XML data with XSLT
Adding entry tags to the Atom feed
Okay, let's move on and take a look at how we would add some entry tags to our Atom feed. You can see there on the screen I have a basic entry and it looks something like this XML construct. You can see that there's an entry tag that wraps some other tags. There's a title, a link and an id and updated date and a summary.
So we'll take a look at how we specify each one of these tags. Just like the feed tag, the entry tag has some required elements and not surprisingly, they are pretty much the same as the required elements of the feed tag. So the title for an entry is the name of the particular entry and you should not leave this blank because again this is how most feed readers will present the name of the entry to the user and you can see I have provided examples again for each one of these.
Click Play or press spacebar to start or stop video
The id again is unique identifier for this entry and like in the feed tag you can use any value here that's unique. Usually, you will use your website address domain along with some additional data that identifies the entry, either a path to the HTML file that specifies the entry or some other kind of identifier that your blogging system might use or some other type of unique identifier. The important thing here is that would be unique and the updated tag just like the feed tag indicates the last time that this entry was modified in a significant way and again the spec leaves it up to the publisher to determine what significant means.
So for example, if you fixed the typo, that's not necessarily significant. So you wouldn't need to update the date there. And again, dates here have to conform to the formats that the feed updated tag needs to conform to and I have provided an example but you can look any of these up on the web and see how they work. And like the feed tag, the entry tag comes along with some recommended elements. Now these are not required, but they are strongly recommended because they provide richer information about a particular entry.
So entries can have authors just like the feed can have an author. So the author tag specifies one author of the entry, and again just like the feed you can have multiple authors. Now if the feed tag that encloses the entries in this particular feed does not have an author tag, then the author tag becomes required for entries.
So you need to put authors on your entries if your feed does not have a tag and it's probably a good idea to put authors on there anyway in case your entry is for some reason copied or referenced somewhere else.
The link tag identifies a web page that's related to this entry somehow and the spec for Atom contains a lot more detailed information about what links can contain. But in this example, I have shown that this link tag links to a related web page that describes this particular entry. Now the content tag performs the bulk of the work in the entry because it contains or links to the complete content for this entry.
If there's no summary tag, which follows next then this should be provided and the content as we'll see later can contain text, or HTML content. It can contain a whole bunch of different things. And then finally the summary tag provides a brief summary of what this entry says. If there's no content or if the content is not provided in line in this particular entry, in other words it's linked to, then the entry should provide a summary.
Okay, let's finish up by taking a look at some of the optional elements of the entry tag. So entries can have contributors just like they can have authors and the contributor tag is used to indicate one of the contributors and it follows the same format as the author tag. You can have multiple of these for various contributors and one of the nice things about the Atom Specification is that contributors are distinct from authors. Entries can have a category tags as well. So the category tag specifies the category that an entry belongs to.
Over there on the right, you see I have a category and the term is news. The published date indicates the initial publication time that this entry was made available. Now this is different from the updated date, publish means this was the first time that the world got to see this particular entry and it follows the same date rules as the updated tag follows.
The source tag is used in the case where this particular entry was copied from another feed. The source tag is then used to preserve the child tags of the entry that the entry was copied from.
For example, if I had copied this entry from some other feed, I would use the source to provide necessary things like the title that it came from, when it was updated, the copyright information, so on and so forth and I would also provide the id. You can see on the right-hand side there, its main purpose in life is to preserve information about the source of this entry and then finally there's a rights tag and you can put any copyright notice that this entry might have in it and you can see I have provided some example there with a copyright and my name.
Okay, so let's go back and take a look at our updated entry tag. You can see that we have added the tags that we were looking at earlier. So in addition to the title and id and updated tag, I have added the link, a summary, a category, a published date and some content. Now to put it all together, this is what a finished Atom feed would look like.
Right at the top here, you have the XML declaration and then that's followed by the feed tag which encapsulates the entire feed and then we have a title and id and updated tags for the feed, those three are required and then we have a link that specifies where the feed came from and the author and that would be me and then we have our entry which we just looked at.
Okay, so this is a finished example of an Atom feed. Now like RSS, you can include HTML at various points inside your Atom feeds and specifically the tags, title, summary, content and rights can contain HTML code. There's a type attribute that you place on these tags that determine how this information is encoded. Now the default is text. So if you don't specify it then that's the default value, and if the type is text, then the element contains just plain text with no HTML in it. You can see there's an example of that right here.
If the type attribute contains the string HTML, then the element contains entity escaped HTML. And you see an example of that down here. So in this example of the content tag contains type of HTML and then inside the content, I have escaped out the angle brackets that you would normally see on HTML tags.
So instead of putting the term b and then new title with a closing b in order to make these words bold, I have to convert the angle brackets into their entity escaped equivalence. The ampersand and then less than with a semicolon and then the ampersand gt with a semicolon. There's a list of these and I'll get to those in a minute. And then finally, if the type is equal to XHTML, then the element contains, XHTML code and it is wrapped up in a single div tag. And that's an important thing you need to realize.
So here you see an example of that. The contents contains XHTML and I have a div tag with the XHTML name space on it and then right inside the div tag I can put XHTML code straight in there and I have to escape it or anything like that.
So I found a pretty good list on the web that lists all of the entity escaping characters that you can use inside XHTML and HTML. So if you want to follow that link, there you will see all the different ways that you can entity escape characters in HTML for inclusion in Atom.
Okay brings us to the close of the ATOM format. Hopefully, you learned enough now to go out and make your own Atom feeds or at least read existing ones and now we are going to move on the next chapter.
www.lynda.com is an award-winning provider of educational materials, including Hands-On Training instructional books, the Online Training Library, CD- and DVD-based video training, and events for creative designers, instructors, students, and hobbyists.
The lynda.com Online Training Library and CD-ROM titles include such subjects as Photoshop, Flash, Dreamweaver, Illustrator, Office, digital photography, Web design, digital video, and many others. lynda.com's all-star team of trainers and teachers provides comprehensive and unbiased movie-based training to an international membership of tens of thousands of subscribers. Considering the speed at which technology evolves, the Online Training Library is a great solution for keeping your skills current. Library subscriptions begin as low as $25 a month, with no long-term commitment required.
Joe Marini is the director for Microsoft's Visual Studio Industry Partner program, and has been active in the Web and graphics industries for more than 15 years. He was an original member of the Dreamweaver engineering team at Macromedia, and has also held prominent roles in creating products such as QuarkXPress, mFactory's mTropolis, and Extensis QX-Tools. He is regularly a featured speaker at industry conferences and has authored or co-authored several books on Web development. His book The Document Object Model is widely regarded as the definitive resource for working with the DOM.
Related Keywords:xml, Extensible Mark-Up Language, xml training, xml tutorial, xml techniques, xml design, web design, web site design, atom feed, entry tags