CopyrightIBMCorporation2010TrademarksSimulateXQueryandXIncludefunctionalitywithPHPPage1of8SimulateXQueryandXIncludefunctionalitywithPHPEnjoythepowerofXMLdataprocessinginwebprogrammingColinBeckinghamSeptember21,2010ManybrowserscanhandleXMLingeneral,butarecurrentlyweakintheirsupportofXQueryandXInclude.
YouneedtoworkaroundthisissuewhenyoubuildwebapplicationsthatcombineandprocessXML-structureddatafrommultiplesources.
UsingPHPisonesolution.
ThisarticlefirstshowshowyourwebpagescandeliverdataextractsfromXMLusingXQueryandXIncludeexplicitly,andthenhowtodotheequivalentworkwithPHP,allwithinthecontextofacooperativeeffortamonggardencenters.
XIncludeandXQueryareXMLtoolsthathelpwebprogrammersprocessdatadynamically.
XIncludeletsyoutreatmultipleXMLfilesasiftheywereonefile,andXQuerycanprocessthecombineddataandprepareitforinclusionintooutputforweb-pagedisplay.
Together,theyperformthisserviceelegantlyandefficientlywithfewlinesofcode.
FrequentlyusedacronymsHTTP:HypertextTransferProtocolW3C:WorldWideWebConsortiumXHTML:ExtensibleHypertextMarkupLanguageXML:ExtensibleMarkupLanguageXSL:ExtensibleStylesheetLanguageMostbrowserscandisplayandprocessXMLfileseitherdirectlyorincooperationwithXSLtemplates.
Inanidealworld,browserswouldunderstandXQueryandXIncludedirectlytoo.
Butatthispointtheysupportthesetoolsonlybyplacingunreasonabledemandsonusers—forexample,byrequiringthemtoloadexperimentaladd-ons.
Fetchingthedatafromwidelydifferentsourcesandcombiningthemintoonelargedatasetforprocessingcanbeapainstakingtaskforthewebprogrammer.
Throughahypotheticalbusinessexample,thisarticlefirstshowsyouthestrengthofthecombinationofXQueryandXInclude.
Thenyou'lllearnhowtousePHPtosimulatethefunctionalitythatXQueryandXIncludeprovide.
MovingallthedataprocessingtotheserversidegivesyouaworkaroundtolimitedbrowsersupportforXQueryandXInclude.
AnotherbenefitisthatPHPgivesyoumuchfinercontroloverthefinaloutputpresentation.
developerWorksibm.
com/developerWorks/SimulateXQueryandXIncludefunctionalitywithPHPPage2of8Example:Garden-centercooperationImaginethatatownhasthreegardencenters.
Theycompetewithoneanotherbutprovidesufficientlydifferentservicesthattheycandosocooperativelyratherthanantagonistically.
Theydosomemarketresearchtogetfindouthowtheircustomersbuytheirplants.
Inthehorticulturebusiness,salesofhighlyperishableproductsoccurinhighvolumeinashortperiodoftime,andcustomerscanbequiteparticularaboutthetypeandqualityofproductstheywant.
Itisinthebestinterestofthebusinesstogetthehigh-maintenanceproducts(forexample,thosethatneedtobewateredandkeptfreeofpests)outthedoorassoonaspossibleandtokeepamercurialcustomerbasehappybyprovidingthemwiththerightproductsattherighttimeandintherightplace.
Otherwisecustomersflocktothecompetitionthatcan.
Researchshowsthatcustomersdonotlikephoningaroundtofindwheretheycangettheirplants,andthehighvolumeofcallsisinconvenienttothebusinessesaswell.
Atthebeginningoftheseason,allthebusinesseshaveplentyofproduct.
Laterintheseason,despitegoodplanning,productstartstorunoutunevenly.
Customerslookingforpetuniasmighthavetophoneorvisitallthreegardencentersbeforetheyfindthehotpinkcolorthey'relookingfor.
Ingeneral,customerswanttoknowwhohaswhichplant,inwhatsizepot,inwhatquantity,andatwhatprice.
TheproposedsetupThethreeITmanagersholdameeting.
Theydecidetocreateacommonwebsitewherecustomerscanfindoutwhichgardencenterhasspecificplantsinstock.
Althoughallthreegardencentersarecomputerized,eachusesadifferentsystemtostoreinformation.
ApplesandThingsusesaMicrosoftAccessdatabasesystem,BirchTreesUnlimitedusesaLinuxsystemwithMySQL,andCarnationTarnationusesMacOSXwithIBMDB2.
Broadly,theydecidetoworktowardanXML-basedarchitecture.
XMLisaconvenientdataformatbecauseeachoftheirsystemscanexportcurrentdatatoanXMLfilethatisavailableinthecloud.
AmasterXMLfilecollectstheindividualstores'dataintoonecentralplace,usingXInclude.
Finally,themainwebpageexaminesthemasterfile,extractsthedatausingXQuery,andrendersthefinaldisplay.
ProcessingtheXMLwithXIncludeandXQueryTheITmanagersdecidethateachstorewillproduceanXMLfilesimilartotheoneinListing1:Listing1.
StoreXMLfile.
.
.
.
.
.
.
.
.
ibm.
com/developerWorks/developerWorksSimulateXQueryandXIncludefunctionalitywithPHPPage3of8PetuniaPink,in4inchpots1003.
00Appletree'Spartan'625.
00.
.
.
Thisfilehasastorerootelementandtwochildelements.
Theinfochildelementcontainsinformationaboutthestoreingeneral.
Theplantschildelementcontainsmanyplantchildelements,eachofwhichcontainsfurtherinformationaboutthatplant,includingthename,description,quantityandprice.
Allthreestoresfollowthispatternexactly.
Listing2istheirversionofamainXMLfilethatcombinesallthreestorefilessotheyappeartobeonelargefile,maintainingdetailsabouttheproducts:Listing2.
MainXMLfileInListing2,XIncludeisusedtofetchdatafromthethreelocationsusingHTTPinthecloud.
Afterprocessing,itlookslikeListing3:Listing3.
MainXMLfileexpandedApples.
.
.
.
.
.
Birches.
.
.
.
.
.
.
.
.
developerWorksibm.
com/developerWorks/SimulateXQueryandXIncludefunctionalitywithPHPPage4of8InListing3,theincludeinstructionsfromListing2arereplacedbythecontentsoftheindividualstoreXMLfiles.
EachstoreelementisnowachildelementoftheglobalstoreDataelement.
YoucannowapplyXQuerytothecombineddataset,asinListing4:Listing4.
ApplyingXQuery{for$storeindoc("mainXMLfile.
xml")/storeData/storelet$plants:=$store/plants/plantreturn{for$plantin$plantsorderby$plant/namereturn{concat($plant/quantity,"of",$plant/name,"at",$store/info/name,"for",$plant/price,"each")}
轻云互联怎么样?轻云互联,广州轻云网络科技有限公司旗下品牌,2018年5月成立以来,轻云互联以性价比的价格一直为提供个人,中大小型企业/团队云上解决方案。本次轻云互联送上的是美国圣何塞cn2 vps(免费50G集群防御)及香港沙田cn2 vps(免费10G集群防御)促销活动,促销产品均为cn2直连中国大陆线路、采用kvm虚拟技术架构及静态内存。目前,轻云互联推出美国硅谷、圣何塞CN2GIA云服务器...
香港最便宜的vps要多少钱?最便宜的香港vps能用吗?香港vps无需备案,整体性能好,而且租用价格便宜,使用灵活,因为备受站长喜爱。无论是个人还是企业建站,都比较倾向于选择香港VPS。最便宜的香港vps能用吗?正因为有着诸多租用优势,香港VPS在业内颇受欢迎,租用需求量也在日益攀升。那么,对于新手用户来说,香港最便宜的vps租用有四大要点是务必要注意的,还有易探云香港vps租用最便宜的月付仅18元...
如何低价香港服务器购买?想要做一个个人博客,想用香港服务器,避免繁琐备案,性能不需要多高,只是记录一些日常而已,也没啥视频之类的东西,想问问各位大佬有没有低价的香港服务器推荐?香港距大陆近,相比美国服务器最大的优势在于延迟低,ping值低,但是带宽紧张,普遍都是1M,一般戏称其为“毛细血管”。同时价格普遍高,优质稳定的一般价格不菲。大厂云梯队阿里云、腾讯云两家都有香港服务器,要注意的是尽量不要选择...
file_get_contents为你推荐
documentcss支持ipad支持ipad支持ipad支持ipad敬请参阅报告结尾处免责声明iphone连不上wifi我的苹果手机连不上无线,其它手机能,怎么回事?只是家里的连不上iphonewifi为什么我的苹果手机连不上wifiicloudiphone没开启icloud的iphone怎么用find my iphone找回micromediamacromedia FreeHand MX是干什么用的?
天津虚拟主机 www二级域名 ddos 加勒比群岛 163网 长沙服务器 asp免费空间申请 银盘服务是什么 免费外链相册 web应用服务器 wordpress中文主题 浙江服务器 阿里云邮箱登陆地址 购买空间 wordpress空间 九零网络 sonya 达拉斯 极域网 winscpiphone 更多