parserblockquote

blockquote  时间:2021-05-19  阅读:()
CopyrightIBMCorporation2010TrademarksThinkingXML:TheXMLflavorofHTML5Page1of9ThinkingXML:TheXMLflavorofHTML56recommendationsfordevelopersusingthenextgenerationoftheweb'snativelanguageUcheOgbujiJuly08,2010(FirstpublishedJuly06,2010)Forawhile,therehasbeenastruggleforthefutureofmarkupontheweb,astrugglebetweentheW3C'sXHTML2andHTML5,developedbythemajorbrowservendorsunderaseparateorganizationalumbrella.
First,theW3CtookoverHTML5,andnowitrecentlyannouncedthesunsetoftheXHTML2effort.
ThismakesasignificantdifferencetothefutureofXMLontheweb,andfurthermore,becauseofHTML5'smomentum,itisnowatechnologythateveryXMLdeveloperalreadyhastodealwith.
ButfansofXMLneednotdespair:HTML5supportsaproperXMLserialization.
LearnabouttheXMLformofHTML5includingsomekeydifferencesfromolderXHTMLconventionsandlearnhowtopracticallyapplythisvocabularyinmodernwebbrowsers.
Viewmorecontentinthisseries08Jul2010:AddedtwoRelatedtopicsperauthorrequest:Tip:AlwaysuseanXMLdeclarationandthankstoMichaelSmith.
FrequentlyusedacronymsAPI:ApplicationProgrammingInterfaceDOM:DocumentObjectModelHTML:HypertextMarkupLanguageHTTP:HypertextTransferProtocolMIME:MultipurposeInternetMailExtensionsSGML:StandardGeneralizedMarkupLanguageURL:UniformResourceLocatorW3C:WorldWideWebConsortiumXHTML:ExtensibleHypertextMarkupLanguageExtensibleMarkupLanguageXML:ExtensibleMarkupLanguageThehistoryofHTMLhasbeencontroversialateveryturn.
Despitethebesteffortsofwebarchitects,thewebhasalwaysbeenawildfrontierofmessy,confusing,andsometimesjustdiabolicallybrokenmarkup(nicknamedtagsoup).
OneambitionofXMLhasalwaysbeentohelpdeveloperWorksibm.
com/developerWorks/ThinkingXML:TheXMLflavorofHTML5Page2of9cleanupthismess,henceXML'sdesignationas"SGMLfortheweb"(SGMListhemeta-languageofwhichHTMLisjustoneflavor).
XMLcameonthesceneandimmediatelymadealotofwaves.
TheW3Cexpected,reasonablyenough,thatXMLmightalsofindsuccessinthebrowser,andsetupXHTMLasthemostnaturalevolutionfromHTMLtosomethingmorecoherent.
Unfortunately,unexpectedproblemskeptpoppinguptosabotagethisambition.
Deceptivelysimpleconceptssuchasnamespacesandlinkingturnedintofirestormsoftechnologicalpolitics.
TheresultingcontroversiesanddelaysweremorethanenoughtoconvincebrowserdevelopersthatXMLmighthelpescapetheknownproblems,butitwasofferingupplentyofnewandpossiblyunknownonesofitsown.
EvenwithoutthemountingevidencethatXMLisnotapanacea,browserdeveloperswerealwaysgoingtohavedifficultymigratingtoastrictXML-basedpathforthewebgiventheenormouslegacyofpagesusingtagsoup,andconsideringPostel'sLaw,namedafterlegendarycomputerscientistJohnPostel.
Thislawstates:Beconservativeinwhatyoudo;beliberalinwhatyouacceptfromothers.
ThestricturesofXMLarecompatiblewiththislawontheserverordatabaseside,wheremanagerscanimposeconservatismasamatterofpolicy.
Asaresult,thisiswhereXMLhasthrived.
Awebbrowserisperhapstheultimateexampleofhavingtoacceptinformationfromothers,sothat'swheretensionisthegreatestregardingXMLandPostel'slaw.
XHTMLisdead.
LongliveXHTMLAllthistensioncametoaheadinthepastfewyears.
BrowservendorshadbeenlargelyignoringtheW3C,andhadformedtheWebHypertextApplicationTechnologyWorkingGroup(WHATWG)inordertoevolveHTML,creatingHTML5.
SupportforW3CXHTMLwasstagnant.
TheW3CfirstrecognizedthepracticalitiesbyprovidingaplacetocontinuetheHTML5work,anditaccepteddefeatbyretiringXHTMLeffortsin2009.
There'snosimplewaytoassesswhetherornotthismeanstheendofXHTMLinpractice.
HTML5certainlyisnotatalldesignedtobeXMLfriendly,butitdoesatleastgivelipserviceintheformofanXMLserializationforHTML,which,inthisarticle,I'llcallXHTML5.
Nevertheless,thematterisfarfromsettled,asoneoftheHTML5FAQentriesdemonstrates:IfI'mcarefulwiththesyntaxIuseinmyHTMLdocument,canIprocessitwithanXMLparserNo,HTMLandXMLhavemanysignificantdifferences,particularlyparsingrequirements,andyoucannotprocessoneusingtoolsdesignedfortheother.
However,sinceHTML5isdefinedintermsoftheDOM,inmostcasestherearebothHTMLandXHTMLserializationsavailablethatcanrepresentthesamedocument.
Thereare,however,afewdifferencesexplainedlaterthatmakeitimpossibletorepresentsomeHTMLdocumentsaccuratelyasXHTMLandviceversa.
ThesituationisveryconfusingforanydeveloperwhoisinterestedinthefutureofXMLontheweb.
Inthisarticle,IshallprovideapracticalguidethatillustratesthestateofplaywhenitcomestoXMLintheHTML5world.
ThearticleiswrittenforwhatIcallthedesperatewebhacker:someonewhoisnotaW3Cstandardsguru,butinterestedineithergeneratingXHTML5ontheweb,orconsumingitinasimpleway(thatis,toconsumeinformation,ratherthanworryingabouttheibm.
com/developerWorks/developerWorksThinkingXML:TheXMLflavorofHTML5Page3of9enormouscomplexityofrendering).
I'lladmitthatsomeofmyrecommendationswillbepainfulformetomake,asalong-timeadvocateforprocessingXMLtherightway.
RememberthatHTML5isstillaW3Cworkingdraft,anditmightbeawhilebeforeitbecomesafullrecommendation.
Manyofitsfeaturesarestable,though,andalreadywell-implementedontheweb.
ServingupdocumentstoberecognizedasXHTML5Unfortunately,Ihavemorebadnews.
YoumightnotbeabletouseXHTML5asofficiallydefined.
Thatisbecausesomespecificationssaythat,inordertobeinterpretedasXHTML5,itmustbeservedupusingtheapplication/xhtml+xmlorapplication/xmlMIMEtype.
Butifyoudoso,allfullyreleasedversionsofMicrosoftInternetExplorerwillfailtorenderit(you'refinewithallothermajor,modernwebbrowsers).
YouronlypragmaticsolutionistoserveupsyntacticXHTML5usingthetext/htmlMIMEtype.
ThisistechnicallyaviolationofsomeversionsoftheHTML5spec,butyoumightnothavemuchchoiceunlessyoucanexcludesupportforInternetExplorer.
Toaddtotheconfusionthisisaverycontentiouspointintherelevantworkinggroup,andinatleastsomedraftsthislanguagehasbeentoneddown.
InternetExplorer9beta(alsoknownasa"platformpreview")doeshavefullsupportforXHTMLservedwithanXMLMIMEtype,sooncethisversioniswidespreadamongyourusers,thisproblemshouldgoaway.
Meanwhile,ifyouneedtosupportInternetExplorer6orolder,eventheworkaroundsintroducedinthisarticlearenotenough.
YouprettymuchhavetosticktoHTML4.
x.
Recommendationforthedesperatewebhacker:ServeupsyntacticXHTML5usingthetext/htmlMIMEtype.
FunwithDOCTYPEOnepieceofgoodnews,fromadesperatewebhackerperspective,isthatXHTML5bringsfewerworriesaboutdocumenttypedeclaration(DTDecl).
XHTML1.
xand2requiredtheinfamousconstructsuchas:.
ThebiggestproblemwiththiswasthatanaiveprocessorislikelytoloadthatDTDURL,whichmightbeanunwantednetworkoperation.
Furthermore,thatoneURLincludesmanyothers,anditwasn'tuncommonforyoutounnecessarilyendupdownloadingdozensoffilesfromtheW3Csite.
Everynowandthen,theW3C-hostedfilesevenhadproblems,whichleadtoextraordinarilyhard-to-debugproblems.
InXHTML5,theXMLnatureofthefileisentirelydeterminedbyMIMEtype,andanyDTDecliseffectivelyignored,soyoucanomitit.
ButHTML5doesprovideaminimalDTDecl,.
IfyouusethisDTDecl,thenalmostallbrowserswillswitchto"standards"mode,which,evenifnotfullyHTML5,isgenerallymuchmorecompliantandpredictable.
NoticethattheHTML5DTDecldoesnotreferenceanyseparatefileandsoavoidssomeoftheearlierXHTMLproblems.
Recommendationforthedesperatewebhacker:UsetheHTMLminimaldocumenttypedeclaration,,inXHTML5.
SinceyouarenotusinganyexternalDTDcomponents,youcannotusecommonHTMLentitiessuchas or©.
ThesearedefinedinXHTMLDTDswhichyouarenotdeclaring.
Ifyoutrytousethem,anXMLprocessorwillfailwithanundefinedentityerror.
TheonlysafenameddeveloperWorksibm.
com/developerWorks/ThinkingXML:TheXMLflavorofHTML5Page4of9characterentitiesare:<,>,&,",and'.
Usenumericalequivalentsinstead.
Forexample,use ratherthan and©ratherthan©.
Recommendationforthedesperatewebhacker:Donotuseanynamedcharacterentitiesexceptfor:<,>,&,",and'Technicallyspeaking,ifyouserveupthedocumentastext/html,accordingtothefirstrecommendation,youwon'tgeterrorsfrommostbrowsersusingHTMLnamedcharacterentities,butrelyingonthisaccidentisverybrittle,andrememberthatbrowsersarenottheonlyconsumerofXML.
OtherXMLprocessorswillchokeonsuchdocuments.
FunwithnamespacesThelastlayerintheover-elaboratecakeofmechanismsforrecognizingtheXMLformat,afterMIMEtypeandDTDecl,isthenamespace.
You'reprobablyusedtostartingXHTMLdocumentswithalinesuchasthefollowing.
Thepartinboldtype(xmlns="http://www.
w3.
org/1999/xhtml")isthenamespace.
InXHTML5,thisnamespaceisstillrequired.
IfyouincludeotherXMLvocabularies,suchasScalableVectorGraphics(SVG),puttheseintheirrespective,requirednamespaces.
Recommendationforthedesperatewebhacker:AlwaysincludethedefaultnamespaceatthetopofXHTML5documentsandusetheappropriatenamespacesforother,embeddedXMLformats.
Ifyoudoincludeothervocabularies,theirnamespacedeclarationsmustbeintheoutermoststarttagsoftheembeddedsections.
Ifyoudeclarethemonthehtmlelement,youcommitatext/htmldocument-conformanceerror.
WorkingwithXHTML5contentXHTML5requiresthatyouspecifythemediatypeeitherinaprotocolheader,suchasHTTPContent-Typeheader,usingaspecialcharactermarkercalledaUnicodeByteOrderMark(BOM)orusingtheXMLdeclaration.
Youcanuseanycombinationoftheseaslongastheydonotconflict,butthebestwaytoavoidproblemsistobecarefulinhowyoucombinemechanisms.
Unfortunately,usinganXMLdeclarationisapotentialproblem,becauseitcausesallInternetExplorerversions8andbelowtoswitchtoquirksmode,resultingintheinfamousrenderinganomaliesforwhichthatbrowserisfamous.
Recommendationforthedesperatewebhacker:OnlyuseUnicodeencodingsforXHTML5documents.
OmittheXMLdeclaration,andusetheUTF-8encoding,oruseaUTF-16UnicodeByteOrderMark(BOM)atthebeginningofyourdocument.
UsetheContent-TypeHTTPheaderwhileservingthedocumentifyoucan.
ThefollowingisanexampleofsuchanHTTPheader:ibm.
com/developerWorks/developerWorksThinkingXML:TheXMLflavorofHTML5Page5of9Content-Type:"text/html;charset=UTF-8"ThenewsemanticmarkupelementsHTML5introducesnewelementsthatprovideclearersemanticsforcontentstructure,suchassectionandarticle.
ThesearethepartsofHTML5thatmightstillbesubjecttochange,butchangeswillnotlikelybedrastic,andtheriskisbalancedbytheimprovedexpressionprovidedbythenewelements.
OneproblemisthatInternetExplorerdoesn'tconstructtheseelementsinDOM,so,ifyouuseJavaScript,you'llneedtoemployanotherworkaround.
RemySharpmaintainsaJavaScriptfixthatyoucandeploybyincludingthefollowingsnippetinyourdocumenthead(seeRelatedtopicsforalink).
YoumightalsoneedtodefineCSSrulesfortheelementsjustincaseanybrowsersdorenderyourdocumentinHTML4stylewhichdefaultsunknownelementstoinlinerendering.
ThefollowingCSSshouldwork.
header,footer,nav,section,article,figure,aside{display:block;}Recommendationforthedesperatewebhacker:UsethenewHTML5elements,butincludetheHTML5shivJavaScriptanddefaultCSSrulestosupportthem.
BringingitalltogetherI'vemademanyseparaterecommendations,soI'llbringthemalltogetherintoacompleteexample.
Listing1isXHTML5thatmeetstheserecommendations.
WhenservingitoverHTTP,usetheheaderContent-Type:"text/html;charset=UTF-8"unlessyoucanaffordtorefusesupportforInternetExplorer,inwhichcaseusetheheaderContent-Type:"application/xhtml+xml;charset=UTF-8".
Listing1.
CompleteXHTML5exampleAmicroblog,inXHTML5header,footer,nav,section,article,figure,aside{display:block;}OtherJavaScriptgoeshere.
.
.
-->developerWorksibm.
com/developerWorks/ThinkingXML:TheXMLflavorofHTML5Page6of9AmicroblogThereissomethingimportantIwanttosay:Astitchintimesavesnine.
Bytheway,areyouasexcitedabouttheWorldCupasIamWelcometomynewXHTML5weblogArchivesApril2010May2010June2010©2010byUcheOgbujiHomeAboutHomeListing1usestheHTML5DTDeclanddeclaresthedefaultnamespaceatthetop.
Thestyleandscriptelementsinthisexamplejustprovideworkaroundsforreal-worldbrowserissues.
ThescriptelementisonlyneededifyouareusingotherJavaScript.
ThedocumentusesalotofthenewHTML5elements,whichIwon'tgointoindetailsincetheyarenotspecifictotheXMLnature.
SeeRelatedtopicsformoreinformationabouttheseelements.
Noticethe"self-closed"syntaxusedfortheimgelement(inotherwords,itendsin/>),andtheuseofnumericentityformforthecopyrightsymbol,©.
YoucanrefertoTable1forasummaryofhowtheaboveexamplewillbehavewithvariousbrowsers.
Table1.
BrowsersupportforXHTML5thatmeetstherecommendationsinthisarticleBrowserBehaviorLegacybrowser(forexampleInternetExplorer6.
xorlower,Netscape,Firefox1.
x)Renderingwillbeunpredictable.
Forexample,"self-closed"elementsmightbemistakenforendtags.
YouwillnotgetanyerrorsifyouuseHTMLnamedentities.
ibm.
com/developerWorks/developerWorksThinkingXML:TheXMLflavorofHTML5Page7of9InternetExplorer7or8Renderingwillberegular"tagsoup"HTML,becauseoftext/htmlMIMEtype,butthepresenceofanyDTDeclwilltrigger"standardsmode,"suchasInternetExploreroffersit.
NoerrorreportforHTMLnamedentities.
Modern,HTML5-awarebrowser,suchasFirefox3.
x,Safari4,orrecentOperaorGoogleChromeRenderingwillbeHTML5(notXHTML5)becauseoftheMIMEtype,butin"standardsmode.
"NoerrorreportforHTMLnamedentities.
AnystandardXML1.
xprocessorTheMIMEtypewillnotbeconsidered.
Theparserwillseeallelementsgenerically,intheXHTMLnamespace.
YouwillreceiveerrormessagesifyouuseanybogusHTMLnamedentities.
WrapupOneimportant,recentdevelopmentisthattheW3CHTMLWorkingGrouppublishedaFirstPublicWorkingDraft,"PolyglotMarkup:HTML-CompatibleXHTMLDocuments,"(seeRelatedtopicsforalink)withtheintentionofgivingXHTML5amorethorough,accurateandup-to-datebasis.
Again,ithasbeenverypainfulformetomakemanyoftherecommendationsinthisarticle.
Suchhack-aroundscomefromlong,painfulexperience,andaretheonlywaytoavoidanightmareofhard-to-reproducebugsandstrangeincompatibilitieswhenmixingXMLintotherealHTMLworld.
ThiscertainlydoesnotmeanthatIhavestoppedadvocatingcarefulXMLdesignandbestpractices.
ItisbesttosaveXHTML5fortheveryoutermostcomponentsthatconnecttobrowsers.
AllflavorsofXHTMLarebetterseenasrenderinglanguagesthaninformation-bearinglanguages.
YoushouldcarrythemaininformationthroughoutmostofyoursysteminotherXMLformats,andthenconverttoXHTML5onlyatthelastminute.
YoumightwonderwhatisthepointofcreatingXHTML5evenatthelastminute,butrememberPostel'slaw,whichrecommendsbeingstrictinwhatyouproduce.
ByproducingXHTML5forbrowsers,youmakeiteasierforotherstoextractinformationfromyourwebsitesandapplications.
Inthisageofmash-ups,webAPIs,anddataprojects,thatisavaluablecharacteristic.
ThankstoMichaelSmithforbringingmyattentiontorecentdevelopmentsinthisspace.
developerWorksibm.
com/developerWorks/ThinkingXML:TheXMLflavorofHTML5Page8of9RelatedtopicsTheHTML5syntaxissuessectionoftheWHATWGFAQ:JointhediscussionofXMLissues.
TheW3CworkingdraftstandardforXHTML5:KeepupwithsyntaxforusingHTMLwithXML,whetherinXHTMLdocumentsorembeddedinotherXMLdocuments.
"PolyglotMarkup:HTML-CompatibleXHTMLDocuments"(W3CHTMLWorkingGroup,June2010):ReadthisrecentlypublishedWorkingDraftwithamorerigorousbasisforXHTML5.
Newelements,attributesandotherlanguagefeaturesinHTML5:LearnaboutthenewelementsavailableinXHTML5.
Tip:AlwaysuseanXMLdeclaration(UcheOgbuji,developerWorks,June,2007):Unfortunately,becauseofbrowserinconsistencies,thisarticlerecommendsnotusingtheXMLdeclarationinXHTML5filesservedforbrowsers.
Readwhyitisalwaysagoodideatodosoingeneralinthistip.
ThankstoMichaelSmithforbringingmyattentiontorecentdevelopmentsinthisspace.
LearnmoreaboutHTML5indeveloperWorksarticlesandtutorials:NewelementsinHTML5Structureandsemantics(ElliotteRustyHarold,August2007):ExplorenewstructuralandinlineelementsinHTML5.
CreatemodernwebsitesusingHTML5andCSS3(JoeLennon,March2010):ImplementthecanvasandvideoelementsofHTML5inthishands-onintroductiontoHTML5andCSS3.
BuildwebapplicationswithHTML5(MichaelGalpin,March2010):Createtomorrow'swebapplicationstodaywithpowerfulHTML5featuressuchasmulti-threading,geolocation,embeddeddatabases,andembeddedvideo.
HTML5—XML'sStealthWeapon(JonnyAxelsson,July2009):ReadareasonablesummaryofthehistorythatledtoXHTML5.
Postel'slaw:Learnmoreaboutthis.
Itisalsocalledtherobustnessprinciple.
html5libproject:IfyouwanttoeasilyconsumeHTMLorXHTML5,checkoutPythonandPHPimplementationsofaHTMLparser,whichincludesbindingsforPython,C,PHPandRuby.
NewtoXML:IfyouarenewtoXML,startexploringXMLandallyoucandowithit.
Readersofthiscolumnmightbetooadvancedforthispage,butit'sagreatplacetogetyourcolleaguesstarted.
AllXMLdeveloperscanbenefitfromtheXMLzone'scoverageofmanyXMLstandards.
IBMcertification:FindouthowyoucanbecomeanIBM-CertifiedDeveloper.
ThedeveloperWorksXMLzone:FindmoreXMLresources,includingpreviousinstallmentsoftheThinkingXMLcolumn.
Ifyouhavecommentsonthisarticle,oranyothersinthiscolumnpleasepostthemontheThinkingXMLforum.
XMLtechnicallibrary:SeethedeveloperWorksXMLZoneforawiderangeoftechnicalarticlesandtips,tutorials,standards,andIBMRedbooks.
IBMproductevaluationversions:Getyourhandsonapplicationdevelopmenttoolsandmiddlewareproducts.
ibm.
com/developerWorks/developerWorksThinkingXML:TheXMLflavorofHTML5Page9of9CopyrightIBMCorporation2010(www.
ibm.
com/legal/copytrade.
shtml)Trademarks(www.
ibm.
com/developerworks/ibm/trademarks/)

美国G口/香港CTG/美国T级超防云/物理机/CDN大促销 1核 1G 24元/月

[六一云迎国庆]转盘活动实物礼品美国G口/香港CTG/美国T级超防云/物理机/CDN大促销六一云 成立于2018年,归属于西安六一网络科技有限公司,是一家国内正规持有IDC ISP CDN IRCS电信经营许可证书的老牌商家。大陆持证公司受大陆各部门监管不好用支持退款退现,再也不怕被割韭菜了!主要业务有:国内高防云,美国高防云,美国cera大带宽,香港CTG,香港沙田CN2,海外站群服务,物理机,...

HostHatch(15美元)大硬盘VPS,香港NVMe,美国、英国、荷兰、印度、挪威、澳大利亚

HostHatch在当地时间7月30日发布了一系列的促销套餐,涉及亚洲和欧美的多个地区机房,最低年付15美元起,一次买2年还能免费升级双倍资源。商家成立于2011年,提供基于KVM架构的VPS主机,数据中心包括中国香港、美国、英国、荷兰、印度、挪威、澳大利亚等国家的十几个地区机房。官方网站:https://hosthatch.com/NVMe VPS(香港/悉尼)1 CPU core (12.5%...

PQ.hosting:香港HE/乌克兰/俄罗斯/荷兰/摩尔多瓦/德国/斯洛伐克/捷克vps,2核/2GB内存/30GB NVMe空间,€3/月

PQ.hosting怎么样?PQ.hosting是一家俄罗斯商家,正规公司,主要提供KVM VPS和独立服务器,VPS数据中心有香港HE、俄罗斯莫斯科DataPro、乌克兰VOLIA、拉脱维亚、荷兰Serverius、摩尔多瓦Alexhost、德国等。部分配置有变化,同时开通Paypal付款。香港、乌克兰、德国、斯洛伐克、捷克等为NVMe硬盘。香港为HE线路,三网绕美(不太建议香港)。免费支持wi...

blockquote为你推荐
支持ipad支持ipad《个人收入的分配过关检测》columnios5itunes备份如何用iTunes备份iPhonegoogle中国地图强大的谷歌地图,为什么中国不用起来css选择器css有哪些选择器google统计怎样将Google分析转换成中文显示Google中文专题交流chrome18请问chrome18怎么关闭硬件加速?android5.1安卓5.0和安卓5.1的区别在哪里?
2019年感恩节 dreamhost softbank官网 双12活动 12306抢票助手 帽子云 什么是刀片服务器 腾讯实名认证中心 免费高速空间 备案空间 新加坡空间 空间申请 腾讯网盘 umax 贵州电信 九零网络 .htaccess 发证机构 服务器操作系统 傲盾代理 更多