Tải bản đầy đủ

OReilly developing feeds with RSS and atom apr 2005 ISBN 0596008813

DevelopingFeedswithRSSandAtom
ByBenHammersley
...............................................
Publisher:O'Reilly
PubDate:April2005
ISBN:0-596-00881-3
Pages:272

TableofContents|Index|Errata

Perhapsthemostexplosivetechnologicaltrendoverthepasttwoyearshasbeen
blogging.Asamatteroffact,it'sbeenreportedthatthenumberofblogsduringthattime
hasgrownfrom100,000to4.8million-withnoendtothisgrowthinsight.What'sthe
technologythatmakesbloggingtick?TheanswerisRSS--aformatthatallowsbloggersto
offerXML-basedfeedsoftheircontent.It'salsothesametechnologythat'sincorporated
intothewebsitesofmediaoutletssotheycanoffermaterial(headlines,links,articles,etc.)
syndicatedbyothersites.Asthemaintechnologybehindthisrapidlygrowingfieldof
contentsyndication,RSSisconstantlyevolvingtokeeppacewithworldwidedemand.
That'swhereDevelopingFeedswithRSSandAtomstepsin.Itprovidesbloggers,web
developers,andprogrammerswithathoroughexplanationofsyndicationingeneraland
themostpopulartechnologiesusedtodevelopfeeds.Thisbooknotonlyhighlightsallthe

newfeaturesofRSS2.0-themostrecentRSSspecification-butalsoofferscomplete
coverageofitsclosesecondintheXML-feedarena,Atom.Thebookhasbeen
exhaustivelyrevisedtoexplain:metadatainterpretationthedifferentformsofcontent
syndicationtheincreasinguseofwebserviceshowtousepopularRSSnewsaggregators
onthemarketAfteranintroductionthatexaminesInternetcontentsyndicationingeneral
(itspurpose,limitations,andtraditions),thisstep-by-stepguidetacklesvariousRSSand
Atomvocabularies,aswellastechniquesforapplyingsyndicationtoproblemsbeyond
newsfeeds.Mostimportantly,itgivesyouafirmhandleonhowtocreateyourownfeeds,
andconsumeorcombineotherfeeds.Ifyou'reinterestedinproducingyourowncontent
feed,DevelopingFeedswithRSSandAtomistheonebookyou'llwantinhand.


DevelopingFeedswithRSSandAtom
ByBenHammersley
...............................................
Publisher:O'Reilly
PubDate:April2005
ISBN:0-596-00881-3
Pages:272

TableofContents|Index
















































Copyright
Preface
Audience
AssumptionsThisBookMakes
HowThisBookIsOrganized
ConventionsUsedinThisBook
UsingCodeExamples
SafariEnabled
CommentsandQuestions
Acknowledgments
Chapter1.Introduction
Section1.1.WhatAreRSSandAtomfor?
Section1.2.AShortHistoryofRSSandAtom
Section1.3.WhySyndicateYourContent?
Section1.4.LegalImplications
Chapter2.UsingFeeds
Section2.1.Web-BasedApplications
Section2.2.DesktopApplications
Section2.3.OtherCunningTechniques
Section2.4.FindingFeedstoRead
Chapter3.FeedsWithoutProgramming
Section3.1.FromEmail
Section3.2.FromaSearchEngine
Section3.3.FromOnlineStores
Chapter4.RSS2.0












































































Section4.1.BringingThingsUptoDate
Section4.2.TheBasicStructure
Section4.3.ProducingRSS2.0withBloggingTools
Section4.4.IntroducingModules
Section4.5.CreatingRSS2.0Feeds
Chapter5.RSS1.0
Section5.1.MetadatainRSS2.0
Section5.2.ResourceDescriptionFramework
Section5.3.RDFinXML
Section5.4.IntroducingRSS1.0
Section5.5.TheSpecificationinDetail
Section5.6.CreatingRSS1.0Feeds
Chapter6.RSS1.0Modules
Section6.1.ModuleStatus
Section6.2.SupportforModulesinCommonApplications
Section6.3.OtherRSS1.0Modules
Chapter7.TheAtomSyndicationFormat
Section7.1.IntroducingAtom
Section7.2.TheAtomEntryDocumentinDetail
Section7.3.ProducingAtomFeeds
Chapter8.ParsingandUsingFeeds
Section8.1.ImportantIssues
Section8.2.JavaScriptDisplayParsers
Section8.3.ParsingforProgramming
Section8.4.UsingRegularExpressions
Section8.5.UsingXSLT
Section8.6.Client-SideInclusion
Section8.7.Server-SideInclusion
Chapter9.FeedsintheWild
Section9.1.OnceYouHaveCreatedYourSimpleRSSFeed
Section9.2.PublishandSubscribe
Section9.3.RollingYourOwn:LinkPimpPubSub
Section9.4.LinkpimpClient.pl
Chapter10.UnconventionalFeeds
Section10.1.ApacheLogfiles
Section10.2.CodeTODOstoRSS
Section10.3.DailyDoonesbury
Section10.4.Amazon.comWishlisttoRSS
Section10.5.FedExParcelTracker



















































Section10.6.GoogletoRSSwithSOAP
Section10.7.Last-ModifiedFiles
Section10.8.InstalledPerlModules
Section10.9.TheW3CValidatortoRSS
Section10.10.GameStatisticstoExcel
Section10.11.FeedsbySMS
Section10.12.PodcastingWeatherForecasts
Section10.13.HavingAmazonProduceItsOwnRSSFeeds
Section10.14.Cross-PosterforMovableType
Chapter11.DevelopingNewModules
Section11.1.NamespacesandModulesWithinRSS2.0andAtom
Section11.2.CaseStudy:mod_Book
Section11.3.ExtendingYourDesktopReader
Section11.4.IntroducingAmphetaDesk
AppendixA.TheXMLYouNeedforRSS
SectionA.1.WhatIsXML?
SectionA.2.AnatomyofanXMLDocument
SectionA.3.ToolsforProcessingXML
AppendixB.UsefulSitesandSoftware
SectionB.1.UberResources
SectionB.2.SpecificationDocuments
SectionB.3.MailingLists
SectionB.4.Validators
SectionB.5.DesktopReaders
Colophon
Index


Copyright©2005O'ReillyMedia,Inc.Allrightsreserved.
PrintedintheUnitedStatesofAmerica.
PublishedbyO'ReillyMedia,Inc.,1005GravensteinHighway
North,Sebastopol,CA95472.
O'Reillybooksmaybepurchasedforeducational,business,or
salespromotionaluse.Onlineeditionsarealsoavailablefor
mosttitles(http://safari.oreilly.com).Formoreinformation,
contactourcorporate/institutionalsalesdepartment:(800)
998-9938orcorporate@oreilly.com.
NutshellHandbook,theNutshellHandbooklogo,andthe
O'ReillylogoareregisteredtrademarksofO'ReillyMedia,Inc.
DevelopingFeedswithRSSandAtom,theimageofan
Americankestrel,andrelatedtradedressaretrademarksof
O'ReillyMedia,Inc.
Manyofthedesignationsusedbymanufacturersandsellersto
distinguishtheirproductsareclaimedastrademarks.Where
thosedesignationsappearinthisbook,andO'ReillyMedia,Inc.
wasawareofatrademarkclaim,thedesignationshavebeen
printedincapsorinitialcaps.
Whileeveryprecautionhasbeentakeninthepreparationofthis
book,thepublisherandauthorsassumenoresponsibilityfor
errorsoromissions,orfordamagesresultingfromtheuseof
theinformationcontainedherein.


Preface
ThisbookisaboutRSSandAtom,thetwomostpopular
content-syndicationtechnologies.Fromdistributingthelatest
websitecontenttoyourdesktopandpoweringlooselycoupled
applicationsontheInternet,toprovidingthebuildingblocksof
theSemanticWeb,thesetwotechnologiesareamongthe
Internet'sfastestgrowing.
TherearemillionsofRSSandAtomfeedsavailableacrossthe
Webtoday;thisbookshowsyouhowtoreadthem,howto
createyourown,andhowtobuildapplicationsthatusethem.It
covers:
RSS2.0anditspredecessors
RSS1.0andtheSemanticWeb
Atomandthelatestgenerationoffeedtechnology
Howtocreateandparsefeeds
ExtendingRSSandAtomthroughmodules
UsingRSSandAtomonthedesktop,ontheWeb,andinthe
enterprise
BuildingRSS-andAtom-basedapplications


Audience
Thisbookwaswrittenwithtwosomewhatinterrelatedgroupsin
mind:

Webdevelopersandwebsiteauthors
Thisbookshouldbereadbyallwebdeveloperswhowantto
sharetheirsitewithothersbyofferingfeedsoftheir
content.Thisgroupincludeseveryonefromwebloggersand
amateurjournaliststothoserunninglarge-budget,
multiusersites.Whetheryou'reworkingonprojectsfor
multinationalnewsorganizationsorneighborhoodsports
groups,withRSSandAtom,youcanextendthereach,
power,andutilityofyourproduct,andmakeyourlifeeasier
andyourworkmoreproductive.Thisbookshowsyouhow.

Developers
Thisbookisalsofordeveloperswhowanttousethe
contentotherpeoplearesyndicatingandbuildapplications
thatproducefeedsastheiroutput.Thisgroupincludes
everyonefromfan-sitedeveloperswantingthelatest
gamingnewsandintranetbuildersneedingup-to-date
financialinformationonthecorporateWeb,todevelopers
lookingtoincorporatenewsfeedsintoartificiallyintelligent
systemsorbuilddata-sharingapplicationsacrossplatforms.
Foryou,thisbookdelvesintotheinterpretationof
metadata,differentformsofcontentsyndication,andthe
increasinguseofwebservicestechnologyinthisfield.We'll
alsolookathowyoucanextendthedifferentflavorsofRSS
andAtomtofityourneeds.


Dependingonyourinterests,youmayfindsomechaptersmore
necessarythanothers.Don'tbeafraidtoskiparoundorlook
throughtheindex.ThereareallkindsofwaystouseRSSand
Atom.


AssumptionsThisBookMakes
Thetechnologyusedinthisbookisnotallthathardto
understand,andtheconceptsspecifictoRSSandAtomarefully
explained.ThebookassumessomefamiliaritywithHTMLand,
specifically,XMLanditsprocessingtechniques,althoughyou
willberemindedofimportanttechnicalpointsandgivenplaces
tolookforfurtherinformation.(AppendixAprovidesabrief
introductiontoXMLifyouneedone.)
MostofthecodeinthisbookiswritteninPerl,butthe
examplesarecommentedsufficientlytomakethingsclearand
easilyportable.TherearealsosomeexamplesinPHPandRuby.
However,usersofanylanguagewillgetalotfromthisbook:
theexplanationsofthestandardsandtheusesofRSSand
Atomarelanguage-agnostic.


HowThisBookIsOrganized
BecauseRSSandnowAtomcomeinanumberofflavors,and
therearelotsofwaystousethem,thisbookhasalotofparts.
Chapter1explainswherethesethingscamefromandwhy
thereissomuchdiversityinwhatseemsonthesurfacetobea
relativelysimplefield.Chapter2andChapter3lookatwhat
youcandowithRSSandAtomwithoutwritingcodeorgetting
closetothedata.Chapter2looksatthesetechnologiesfrom
theordinaryuser'sperspective,showinghowtoreadfeedswith
anumberoftools.Chapter3digsdeeperintothechallengeof
creatingRSSandAtomfeeds,butdoessousingtoolsthatdon't
requireanyprogramming.
Thenextfourchapterslookatthemostcommonvarietiesof
syndicationfeedsandhowtocreatethem.Chapter4examines
RSS2.0,inheritorofthe0.91lineofRSS.Chapter5looksat
RSS1.0,anditsratherdifferentphilosophy.Chapter6explores
themanymodulesavailabletoextendRSS1.0.Chapter7looks
atathirdalternative:therecentlyemergingAtomspecification.
Chapter8throughChapter11focusonissuesthatdevelopers
buildingandconsumingfeedswillneedtoaddress.Chapter8
looksatthecomplexworldofparsingthesemanyflavorsof
feeds,andthechallengesofparsingfeedsthataren'talways
quiteright.Chapter9looksatwaystointegratefeedswith
publishingmodels,particularlypublish-and-subscribe.Chapter
10demonstratesanumberofapplicationsforfeedsthataren't
theusualblogentriesornewsinformation,andChapter11
describeshowtoextendRSS2.0orRSS1.0withnewmodules
incasetheexistingfeedstructuresdon'tdoeverythingyou
need.
Finally,therearetwoappendixes.AppendixAprovidesaquick
tutorialtoXMLthatshouldgiveyouthefoundationyouneedto


workwithfeeds,whileAppendixBprovidesalistofsitesand
softwareyoucanexplorewhilefiguringouthowbesttoapply
thesetechnologiestoyourprojects.


ConventionsUsedinThisBook
Thefollowingfontconventionsareusedinthisbook:
Italicisusedfor:
Unixpathnames,filenames,andprogramnames
Internetaddresses,suchasdomainnamesandURLs
Newtermswheretheyaredefined
Constantwidthisusedfor:

Commandlinesandoptionsthatshouldbetypedverbatim
Namesandkeywordsinprograms,includingmethod
names,variablenames,andclassnames
XMLelementtagsandURIs
Constantwidthitalicisusedfor:

Replaceableitems,suchasvariablesoroptionalelements,
withinsyntaxlinesorcode

Thisiconsignifiesatip,suggestion,orgeneralnote.


Thisiconindicatesawarningorcaution.


UsingCodeExamples
Theexamplesfromthisbookarefreelydownloadablefromthe
book'swebsiteat
http://www.oreilly.com/catalog/deveoprssatom.
Thisbookisheretohelpyougetyourjobdone.Ingeneral,you
mayusethecodeinthisbookinyourprogramsand
documentation.Youdonotneedtocontactusforpermission
unlessyou'rereproducingasignificantportionofthecode.For
example,writingaprogramthatusesseveralchunksofcode
fromthisbookdoesnotrequirepermission.Sellingor
distributingaCD-ROMofexamplesfromO'Reillybooksdoes
requirepermission.Answeringaquestionbycitingthisbook
andquotingexamplecodedoesnotrequirepermission.
Incorporatingasignificantamountofexamplecodefromthis
bookintoyourproduct'sdocumentationdoesrequire
permission.
Weappreciate,butdon'trequire,attribution.Anattribution
usuallyincludesthetitle,author,publisher,andISBN.For
example:"DevelopingFeedswithRSSandAtom,byBen
Hammersley.Copyright2005O'ReillyMedia,Inc.,0-596-008813."
Ifyoufeelyouruseofcodeexamplesfallsoutsidefairuseor
thepermissiongivenabove,feelfreetocontactusat
permissions@oreilly.com.


SafariEnabled

WhenyouseeaSafari®Enabledicononthecoverof
yourfavoritetechnologybook,itmeansthebookisavailable
onlinethroughtheO'ReillyNetworkSafariBookshelf.
Safarioffersasolutionthat'sbetterthane-books.It'savirtual
librarythatletsyoueasilysearchthousandsoftoptechbooks,
cutandpastecodesamples,downloadchapters,andfindquick
answerswhenyouneedthemostaccurate,currentinformation.
Tryitforfreeathttp://safari.oreilly.com.


CommentsandQuestions
Pleaseaddresscommentsandquestionsconcerningthisbookto
thepublisher:
O'ReillyMedia,Inc.
1005GravensteinHighwayNorth
Sebastopol,CA95472
(800)998-9938(intheUnitedStatesorCanada)
(707)829-0515(internationalorlocal)
(707)829-0104(fax)
Wehaveawebpageforthisbook,wherewelisterrata,
examples,andanyadditionalinformation.Youcanaccessthis
pageat:
http://www.oreilly.com/catalog/deveoprssatom
Tocommentorasktechnicalquestionsaboutthisbook,send
emailto:
bookquestions@oreilly.com
Formoreinformationaboutourbooks,conferences,Resource
Centers,andtheO'ReillyNetwork,seeourwebsiteat:
http://www.oreilly.com


Acknowledgments
Thanks,asever,gotomyeditorSimonSt.Laurentandmy
technicalreviewersRoyOwens,TonyHammond,TimoHannay,
andBenLund.ThanksalsotoMarkPilgrim,JonasGalvez,Jorge
Velázquezfortheirlovelycode.BillKearney,KevinHemenway,
andMicahDubinkoearnedmanythanksfortheirtechnicalreviewinggeniusonthefirstedition.NottoforgetDaveWiner,
JeffBarr,JamesLinden,DJAdams,RaelDornfest,Brent
Simmons,ChrisCroome,KevinBurton,andDanBrickley.
CheerstoErhanErdem,DanLibby,DavidKandasamy,and
CastedoEllermanfortheirmemoriesoftheearlydaysofCDF
andRSSandtoYo-YoMaforhisrecordingofBach'sCelloSuite
No.1,towhichmuchofthisbookwaswritten.
Butmostofall,ofcourse,toAnna.


Chapter1.Introduction
"Data!Data!Data!"hecriedimpatiently.
SirArthurConanDoyle,TheAdventureoftheCopperBeeches
Inthischapter,I'llfirsttalkaboutwhatRSSandAtomarefor
andthentakealookatalittleoftheirhistory.Wethenmoveon
tothebusinesscasesforsyndicatingyourowncontentanda
discussionofthephilosophybehindcontentsyndication.The
chapterfinisheswithabriefdiscussionofthelegalissues
surroundingtheprovisionanduseofsyndicationfeeds.


1.1.WhatAreRSSandAtomfor?
Theoriginal,andstillthemostcommon,useforRSSandAtom
istoprovideacontentsyndicationfeed:aconsistent,machinereadablefilethatallowswebsitestosharetheircontentwith
otherapplicationsinastandardway.Originally,asshowninthe
nextsection,thiswasusedtosharedataamongwebsites,but
nowit'smostcommonlyusedbetweenasiteandadesktop
applicationcalledareader.
Feedscanbeanythingfromjustheadlinesandlinkstostories
totheentirecontentofthesite,strippedofitslayoutandwith
metadataliberallyapplied.Contentsyndicationallowsusersto
experienceasiteonmultipledevicesandbenotifiedofupdates
overavarietyofservices.Itcanrangefromasimplelistof
linkssentfromsitetositetothebeginningsoftheSemantic
Web.
However,feedsarestartingtobeusedascontentintheirown
right:peoplearebuildingservicesthatonlyoutputtoafeed
anddon'tactuallyhavea"real"siteatall.Inlaterchaptersof
thisbook,we'lllookatthecoolthingsyoucandowiththis,and
buildsomeofourown.


1.2.AShortHistoryofRSSandAtom
IntheDeveloper'sBarsoftheworldthosedark,sordidplaces
filledwithgrizzledcodersandtheirclansaspecialcorneris
alwaysreservedforthedevelopersofcontent-syndication
standards.There,weepingintotheirbeer,you'llfindthe
veteransofalonganddifficultprocess.Mostlikely,theywill
havetheThousandYardStareofthosewhohaveseenmore
thantheyshould.Thestandardsyouwillreadaboutinthisbook
werenotbornfreshandinnocent,ofastreamlinedprocess
overseenbytheWiseandGood.Rather,thefollowingchapters
havebeendraggedintotheworldandtemperedthrough
brawls,knifefights,andtheoccasionalriot.Whathassurvived,
itishoped,ishardyenoughtoprosperfortheforeseeable
future.
Tofullyunderstandthesewaywardchildren,andtogetthe
mostoutofthem,itisnecessarytounderstandthemotivations
behindthedifferentstandardsandhowtheyevolvedintowhat
theyaretoday.

1.2.1.HotSauce:MCFandRDF
Thedeepest,darkestoriginsofthecurrentversionsofRSS
beganin1995withtheworkofRamanathanV.Guha.Knownto
mostsimplybyhissurname,Guhadevelopedasystemcalled
theMetaContentFramework(MCF).Rootedintheworkof
knowledge-representationsystemssuchasCycL,KRL,andKIF,
MCF'saimwastodescribeobjects,theirattributes,andthe
relationshipsbetweenthem.
MCFwasanexperimentalresearchprojectfundedbyApple,so
itwaspleasingformanagementthatagreatapplicationcame
outofit:ProjectX,laterrenamedHotSauce.Bylate1996,afew


hundredsiteswerecreatingMCFfilesthatdescribed
themselves,andAppleHotSaucealloweduserstobrowse
aroundtheseMCFrepresentationsin3D.Documentationstill
existsontheWebforMCFandHotSauce.See
http://www.eclectica-systems.co.uk/complex/hotsauce.phpand
Example1-1formore.

Example1-1.AnexampleofMCF
begin-headers:
MCFVersion:0.95
name:"Eclectica"
end-headers:
unit:"tagging.mco"
name:"TaggingandAcrobatIntegration"
default_genl_x:-109
default_genl_y:-65
typeOf:#"SubjectCategory"
unit:"http://www.nplum.demon.co.uk/temptin/temptin.htm"
name:"TemptInInformationManagementTemplate"
genls_pos:["tagging.mco"-85-137]
unit:"http://www.nplum.demon.co.uk/temptin/tryout.htm"
name:"DownloadTry-outVersion"
genls_pos:["tagging.mco"-235120]

Itwaspopular,butexperimental,andwhenSteveJobs'sreturn
toApple'smanagementin1997heraldedtheendofmuchof
Apple'sresearchactivity,GuhaleftforNetscape.
There,hemetwithTimBray,oneoftheoriginalXMLpioneers,
andstartedmovingMCFovertoanXML-basedformat.(XML


itselfwasnewatthattime.)Thisprojectlaterbecamethe
ResourceDescriptionFramework(RDF).RDFis,astheWorld
WideWebConsortium(W3C)RDFPrimersays,"ageneralpurposelanguageforrepresentinginformationintheWorld
WideWeb."Itisspecificallydesignedfortherepresentationof
metadataandtherelationshipsbetweenthings.Initsfullest
form,itisthebasisfortheconceptknownastheSemantic
WebtheW3C'svisionwhereincomputerscanunderstandthe
meaningof,andtherelationshipsbetween,documentsand
otherdata.Youcanread
http://en.wikipedia.org/wiki/Semantic_Webformoredetails.

1.2.2.ChannelDefinitionFormat
In1997,XMLwasstillinitsinfancy,andmuchoftheInternet's
attentionwasfocusedontheincreasinglyfranticwarbetween
MicrosoftandNetscape.
MicrosofthadbeenwatchingtheHotSauceexperience,and
earlythatyeartheInternetExplorerdevelopmentteam,along
withsomeothers,principallyacompanycalledPointcast,
createdasystemcalledtheChannelDefinitionFormat(CDF).
ReleasedonMarch8,1997,andsubmittedasastandardtothe
W3Ctheverynextday,CDFwasXML-basedanddescribedboth
thecontentandasite'sparticularratings,scheduling,logos,
andmetadata.ItwasintroducedinMicrosoft'sInternetExplorer
4.0andlaterintotheWindowsdesktopitself,whereitprovided
thebackboneforwhatwasthencalledActiveDesktop.TheCDF
specificationdocumentisstillonlineat
http://www.w3.org/TR/NOTE-CDFsubmit.html,andExample1-2
showsasample.

Example1-2.AnexampleCDFdocument




VALUE="http://www.foosports.com/channel-setup.html"/>













totheboneandcomeoutontop."/>













playoffsagain!"/>






losstotheRangers"/>























Verysoonafteritsrelease,thepotentialofastandard,XMLbasedsyndicationformatbecameapparent.ByApril14,1997,
justoveramonthsinceMicrosoftgavethestandarditsfirst
publicviewing,DaveWiner'sUserLandSoftwarereleased
supportfortheformatintoitsFrontierproduct.WrittenbyWes
Felter,andbuiltuponbyDaveWiner,itwouldbethecompany's
firstforayintoXML-basedsyndication,butbynomeansitslast.
UserLandwastobecomeamajorcharacterinourstory.
CDFwasanexcitingtechnology.IthadarrivedjustasXMLwas
beinglaudedastheNextBigThing,andthatcombinationofa
usefultechnologywithawholenewthingtoplaywithmadeit
ratherirresistibleforthenascentwebloggingcommunity.CDF,
however,wasreallydesignedforthebiggerpublishers.Alotof
theelementswereoverkillforthesmallercontentproviders
(who,atanyrate,didn'tconsiderthemselvescontentproviders
atall),andsoalotofwebloggersstartedtolookintocreatinga
simplerspecification.


Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay

×