Tải bản đầy đủ - 0 (trang)
Chapter 22. FileMaker and Web Services

Chapter 22. FileMaker and Web Services

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

AboutWebServices

SowhatisaWebservice?It'scertainlyapopularbuzzword,but

whatdoesitmean?Well,looselyspeaking,thetermrefersto

thecapabilityofcomputersthatareremotefromeachotherto

exchangeinformationandmessagesovertheWorldWideWeb

(whichwe'llgenerallyrefertosimplyas"theWeb").

Asanexample,let'ssaythere'sacomputeroutthere

somewhereontheInternetthatknowsthecurrenttemperature

atvariouspointsallovertheworld.Ifyousendthatcomputera

latitudeandlongitude,inthecorrectformat,theremote

computersendsbackthenearestcurrenttemperatureitcan

find.SuchatransactionisshowninFigure22.1.



Figure22.1.AdesktopPCqueriesaremote

serverfortemperaturedataovertheWeband

receivesananswerinXMLformat.



You'llnoticeacoupleofthingsaboutthispicture.Themachine

makingtherequest,whichwe'vecalledtheWebServicesClient,

hassentitsrequestintheformofaURL(auniformresource



locator,thestandardwayofmakingarequestforcontentover

theWeb).Andtherespondingcomputerhassenttherequested

informationbackinataggedmessageformatthatyoumight

recognizeasXML.

Theimportantthingaboutthistransactionisthatitdoesn't

requireanyspecializedcommunicationprotocolstoexist

betweenthetwomachines.Therequestandresponsebothuse

standardHTTP,thewell-establishedprotocolthatpowersthe

entireWeb.Andthedatareturnedbytheserverispresentedas

XMLastandardizedandwidelyacceptedwaytopresentdata.

Sothat'sourdefinition:AWebserviceisameansof

exchanginginformationandmessagesbetweentwocomputers,

whichusesXMLdatasentovertheWebviaHTTP.NotallWeb

servicesinvolvesendingXMLoverHTTP.Butmanydo,andit'sa

suitablewaytothinkaboutWebservicesforthepurposeof

workingwithFileMakerPro.

BeforeyoucandelveveryfarintohowFileMakerworkswith

Webservices,though,youneedtolearnsomeofthebasicsof

howFileMakercanworkwithXMLdata.Forthefirsthalfofthis

chapterwediscusshowFileMakerinteractswithXML,andinthe

secondhalf,weapplythatknowledgetoworkingwithactual

Webservices.



FileMakerandXML

BeforeyoucanappreciateFileMaker'sWebservicecapabilities,

youneedtolearnmoreaboutthethingsFileMakercandowith

XMLdata.Toputitbriefly,FileMakercanbothimportand

exportdataasXML.Thiscapabilityhasseveralinterestinguses:

Foronething,itmeansFileMakercanparticipateinWeb

servicestransactions,asyou'llseeinthischapter.Foranother,

itmeansFileMakercanexchangedatawithotherapplications

viaXML.Beforewedelvedeeper,though,abriefoverviewof

XMLmaybeuseful.



TheBasicsofXML

XMLisalargetopic,onwhichmanybookshavebeenwritten.

We'llhavetocontentourselveswithaquickoverview;youcan

findfurtherreadingsuggestionsinthisbook'scompanion

volume,theFileMaker8FunctionsandScriptsDeskReference.

XMLisatext-basedmeansofrepresentingdata,whichisatthe

sametimerichandportable.By"rich,"wemeanthatthedata

ismorethanmeretext:AnXMLdocumentiscapableof

describingitsownstructure,sothatinlookingatanXML

documentyoucantellachapterheadingfromabulletpoint,or

apersonnelIDfromahealth-insurancedeductible.Byportable,

wemeanthatXMLdocumentsarestoredasplaintextandcan

bereadbyawidevarietyofprogramsonawidevarietyof

computersandoperatingsystems.

Asanexample,considertheXMLdocumentthatappearsin

Listing22.1.Thisisashortdocumentcontaininginformation

aboutmotors.You'llnoticethedocumentisfulloftags(called

markup)thatmightlooksuperficiallyfamiliartoyouifyou've

seensomeHTMLbefore.You'llnoticethatthetagsalwaysoccur



inpairs,withsomecontentbetweenthem,andyou'llnotice

thatthetagsseemtodescribethedatatheycontain.Thesetag

pairsareknowninXMLjargonaselements.



Listing22.1.ASmallXMLFileContainingMotor

Data









Rotary17

1200

M3110A-3

312







ThisXMLdocumentisrich,inthesensethatitcontainstwo

kindsofinformation:Itcontainsrawdata,butitalsocontains

tagstellingareaderwhatthedatameans.Inthisdocument,

M3110A-3isnotjustastringofnumbersandletters;it's

specificallyapartnumber.

Thedocumentisalsoportableinthesensethatit'sstoredas

plaintext,meaningyoudon'tneedaspecial"motorprocessing"

applicationtoreadit.Anytoolorprogramthatcanreadplain

textcanworkwiththisdata.

XMLdocumentshavetofollowsomesimplerules.Eachmust

beginwithanXMLdeclaration,likethefirstlineofListing22.1.

Eachmusthaveasingleoutermost,ordocument,elementin

Listing22.1,thedocumentelementiscalledmotors.Eachtag

mustbeproperlyclosedifyouhaveatag,you'dbetter

haveitsclosingcounterpart,called
.And,althoughtags

maybenested(forexample,inListing22.1,theweightelement

iscompletelyenclosedwithinthemotorelement),itisnot



permissiblefortagstooverlap.Therefore,somethinglike

Rotary500



wouldnotbeallowedbecausetheweighttag,ratherthanbeing

completelyenclosedinthemodeltag,insteadoverlapsit.

XMLdocumentsthatfollowthesefewsimplerules,aswellas

somerulesaboutallowablecharacters,aresaidtobewellformed.



Note

XMLisarigorousstandard,withplentyoftechnical

documentsthatdescribeitinexactdetail.Inthis

bookweoptforclarityoverrigor,soweencourage

youtogetholdofadditionalresourcestoexplorethe

fulldetailsofXMLconceptssuchaswell-formedness.

Thedescriptionwe'vegivenisfairlycomplete,but

thelastwordcanbefoundat

http://www.w3.org/TR/2004/REC-xml20040204/#sec-well-formed.



FileMaker'sXMLGrammars

XMLsyntaxrules,asyoumayhavenoticed,don'tsayanything

abouthowtomarkupyourdata.XMLdoesn'tforceyoutouse

amotorelementwhentalkingaboutmotors,norwoulditspecify

whatotherelementsamotorelementshouldcontain.Ifyou're

designinganXMLdocument,theexactstructureofthe



document,asfaraswhatdataitcontainsandhowthatdatais

markedup,remainsuptoyou,thedocumentdesigner.

FileMakeriscapableofpresentingitsdataasXML,andwhenit

doesso,itusesitsown,FileMaker-specificsetofelementsto

describeitsdata.FileMakercanactuallypresentitsdatain

eitheroftwoXMLstructures,calledgrammars;you,astheuser

ordeveloper,gettochoosewhichonesuitsyourcurrent

situationbest.



Note

FileMakercanactuallypresentitsdatainasmanyas

fourXMLgrammars,buttwooftheseareonly

meaningfulinthecontextofCustomWebPublishing,

whichisthesubjectofthenextchapter.



ExportingFileMakerDataasXML:TheFMPDSORESULT

Grammar

SupposethatyouhavesomeproductdatainaFileMakertable,

whichlookslikeFigure22.2.



Figure22.2.Somesamplewidgetdataina

FileMakertable.



[Viewfullsizeimage]



ToexporttheserecordsasXML,chooseFile,ExportRecords,

andthenchooseafiletypeofXMLinthefollowingdialog.When

youdothis,beforeseeingthefamiliarExportdialog,youseean

XMLoptionsdialog,asshowninFigure22.3.



Figure22.3.FileMaker'sXML/XSLexportoptions

dialog.



[Viewfullsizeimage]



HereyoucanchoosewhichofFileMaker'sXMLgrammarsto

apply.(YoucanalsoapplyanXSLstylesheettotheoutput,

whichisanimportanttopicwe'lldealwithinitsownsection

laterinthischapter.)Ifyou'retryingthisforthefirsttime,you



mightwanttochooseFMPDSORESULT.Fromthere,you'llseethe

familiarExportdialog,whereyoucanchoosewhichfieldsto

export,andinwhatorder.

Ifyouopentheresultingexportedfile,you'llseesomethinglike

thedocumentinListing22.2.



Listing22.2.RecordsExportedUsingFileMaker's

FMPDSORESULTGrammar









0

Widget.fp7





W1

MediumFrobisher

Mauve

12.2





W2

GossetSocketeer

Red

4





W3

TripleHexPingNut

Steel

2.3







FileMakerhasapplieditsownXMLstructuretotheexported

datainthiscasetheFMPDSORESULTstructure.AnFMPDSORESULT

documenthasadocumentelement(thetop-levelelement)

called.Thatelementinturncontainselementsfor

ERRORCODE(generally0unlesstherewassomeerrorintheexport



process),forDATABASE(totelluswhichdatabasefilethedatawas

drawnfrom)andLAYOUT,aswellasoneelementforeach

recordinthetablefromwhichwe'reexporting.The

elementsinturncontainadditionalelements,namedforthe

fieldsthatwereselectedforexport.



AbouttheFMPDSORESULTGrammar

Youmighthavenoticed,inListing22.2,thatthesecondlineofthegenerated

XMLcontainsawarning:"ThisgrammarhasbeendeprecateduseFMPXMLRESULT

instead."Deprecationisatermusedincomputerlanguagedesigntoindicate

thatalanguage'sdesignersareactivelydiscouragingyoufromusinganelement

orfeature.Thisisgenerallybecausethelanguagedesignersbelievethatnewer

featuresrepresentanimprovementonthedeprecatedfeature.Theoldfeature

continuestowork(asdoesFMPDSORESULTinFileMaker7),butyouarediscouraged

fromusingitandencouragedtouseadifferentornewerfeatureinstead.

AlthoughFMPDSORESULTisnowformallydeprecated,wechosetouseithereanyway

becauseofitsvalueinteachingXML.It'saverbosegrammarthatcreatesXML

elementnamesbasedonFileMakerfieldnames.Thismakesitveryeasyforan

XMLnovicetoseehowtheFileMakerdatamapsontotheXMLoutput,andthis

makesFMPDSORESULTausefulteachingtool.

So,what'swrongwithFMPDSORESULT?Threethings,allofthemtiedtothefactthat

FileMakergeneratestheelementnamesforthisgrammardirectlyfromFileMaker

fieldnames.Inthefirstplace,ifyourFileMakerfieldnamesareofanylength,

theXMLelementnamesaresimilarlylong,andthegeneratedfilescanbecome

massive.Second,theelementstructureofanFMPDSORESULTdocumentobviously

variesdependingontheFileMakerfieldnamesthatliebehindit.Allsuch

documentswillhaveanFMPDSORESULTelement,containingoneormoreROW

elements,butwithineachROWelementthere'snowaytopredictwhatthe

subelementswillbe.Thismakesitimpossibletovalidatethesedocumentsviaa

singleDocumentTypeDefinitiondocument,orDTD.(Wedon'tdealwithDTDs

muchinthisbook,butmanyXMLenvironmentsandworkflowsmakesignificant

useofthem,andtheabilitytoconformtoasingleDTDisuseful.)

ThethirdandmostseriousproblemwithFMPDSORESULT,though,isthatitcan

generateXMLthatisliterallyinvalid.Totakeasimpleexample,XMLelement

namesmaynotbeginwithanumber.There'snosuchrestrictiononFileMaker

fieldnames.AFileMakerfilewithafieldnamed2004Resultswillgeneratean

FMPDSORESULTXMLdocumentwithelementscalled<2004Results>.That'snotavalid

XMLelementname,andanyXMLparserthattriestoprocessadocument

containingsuchanamewillgenerateanerror.

So,paycarefulattentiontothefactthatthisgrammarisdeprecated.Although

weuseditinthissectionforteachingpurposes,werecommendthatyoubegin

usingtheFMPXMLRESULTgrammarassoonasyoufeelcomfortablewiththismore

complexgrammar.



ExportingFileMakerDataasXML:TheFMPXMLRESULT

Grammar

TheFMPDSORESULTgrammarisconsideredtobeFileMaker'smore

readableexportgrammar.It'sabitmorelegibletohumans,but

it'snottheoneFileMakerusesmostheavily.Thathonoris

reservedfortheothergrammar,calledFMPXMLRESULT.Ifyouwere

toexportthewidgetdataasXMLwiththisgrammar,you'dsee

somethinglikethedocumentinListing22.3.



Listing22.3.DataExportedUsingFMPXMLRESULT

Grammar

[Viewfullwidth]







0























W1





MediumFrobisher





Mauve





12.2









W2





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

Chapter 22. FileMaker and Web Services

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

×