Tải bản đầy đủ - 0 (trang)
Hack 72. Program Yahoo! with ColdFusion

Hack 72. Program Yahoo! with ColdFusion

Tải bản đầy đủ - 0trang

Savethefollowingcodetoafilecalledyahoo_search.cfmand

uploadittoyourserver:








































  • #results[i].T

    # #results[i].Summary.xmlText#




    #results[i].Url.xmlText#








  • --ResultsPoweredbyYahoo!







    Takealookatthetaginthescript.Notethatthecharset

    attributeisutf-8andthatatagwasusedtoseta

    charsetheaderfortherequestwiththeutf-8value.Thisisabit

    ofextrawork,butit'snecessarytomakesureColdFusionand

    Yahoo!SearchWebServicesarespeakingthesamelanguage.



    4.7.2.RunningtheHack

    Bringupthepageinabrowsertoseeitinaction:

    http://example.com/yahoo_search.cfm?p=insertword



    SeparatemultiplewordswithURL-encodedspaces,asinthis

    searchfor"ColdFusionMX":

    http://example.com/yahoo_search.cfm?p=ColdFusion%20MX



    YoushouldseethetopYahoo!SearchresultsforColdFusionMX,as

    showninFigure4-8.



    Figure4-8.Yahoo!Searchresultsfor"ColdFusion

    MX"



    Asyoucansee,ColdFusionMXincludesallofthetoolsyou

    needtomakeYahoo!SearchWebServicesrequestsandwork

    withtheresponses.IntegratingYahoo!datawithexisting

    ColdFusionapplicationscanbeaccomplishedwithjustafew

    linesofcode.







    Hack73.ProgramYahoo!withXSLT



    TransformYahoo!SearchWebServicesresponsesinto

    HTMLwithanXSLTstylesheet.

    TheExtensibleStylesheetLanguage(XSL)isatag-based

    templatesystemthatcantransformanyXMLdocumentintoany

    othertextformat,includingotherflavorsofXMLor,more

    commonly,HTML.Likeascriptinglanguage,XSLdefineswhat

    datashouldgowhereonapage.You'llstillneedtousea

    scriptinglanguagetoperformthetransformationfromXMLinto

    HTML,andtheentireprocessisencapsulatedinthetermXSL

    transformationsorXSLT.

    Atfirstglance,anXSLstylesheetlooksalotlikeanHTMLpage,

    anditoftencontainsHTMLtags.ButunlikeHTML,each

    stylesheetmustbevalidXMLandmustcontainanumberof

    tagsthatdescribehowtheXMLshouldbeprocessed.Whilean

    HTMLdocumentcanhaveafewunclosedtagshereandthere

    andstilldisplayawebpage,XSLisverystrictandwillfailifit's

    notproperlyformed.

    ResponsesfromtheYahoo!SearchWebServicesareinXMLand

    canbetransformeddirectlyintoanHTMLpagewithabitof

    XSL.



    4.8.1.TheCode

    Eachstylesheetisorganizedintooneormoretemplatesthat

    definehowdatafromthesourceXMLdocumentshouldbe

    arranged.Thetemplateswithinastylesheetcontainamixof

    XSLprocessingtagsandHTML.



    Totryatransformationout,firstcreatethestylesheet.Savethe

    followingXSLtoatextfilecalledyahoo_search.xsl:








    Transform">








    SearchResults







    SearchResults



























    PoweredbyYahoo!


















































































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

    Hack 72. Program Yahoo! with ColdFusion

    Tải bản đầy đủ ngay(0 tr)

    ×