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/)

pia云低至20/月,七折美国服务器

Pia云是一家2018的开办的国人商家,原名叫哔哔云,目前整合到了魔方云平台上,商家主要销售VPS服务,采用KVM虚拟架构 ,机房有美国洛杉矶、中国香港和深圳地区,洛杉矶为crea机房,三网回程CN2 GIA,带20G防御,常看我测评的朋友应该知道,一般带防御去程都是骨干线路,香港的线路也是CN2直连大陆,目前商家重新开业,价格非常美丽,性价比较非常高,有需要的朋友可以关注一下。活动方案...

CYUN专注海外精品服务器资源 国庆钜惠 最低5折起 限量促销

国庆钜惠 最低5折起 限量促销CYUN专注海外精品服务器资源,主营香港CN2 GIA、美国CERA、美国高防服务器资源,实体公司,ISP/IDC资质齐全,客服配备齐全。本次针对国庆推出非常给力的促销活动,旗下所有平台同享,新老客户同享,限时限量,售完截止。活动截止时间:2021年10月9日官网地址:www.cyun.net参与机型:香港CN2 GIA云服务器、香港双程CN2云服...

Virmach款低价VPS可选可以选择多个机房,新增多款低价便宜VPS主机7.2美元起

Virmach商家我们是不是比较熟悉?速度一般,但是人家价格低,而且机房是比较多的。早年的时候有帮助一个有做外贸也许需要多个机房且便宜服务商的时候接触到这个商家,有曾经帮助够买过上百台这样的低价机器。这里需要提醒的,便宜但是速度一般,尤其是中文业务速度确实不快,如果是外贸业务,那肯定是没有问题。这几天,我们有看到Virmach推出了夏季优惠促销,VPS首年8折,最低年付仅7.2美元,多机房可选,如...

blockquote为你推荐
deduplicationchrome桂林飞宇科技股份有限公司V1.2股份一卡通系统杭州市西湖区翠苑第四幼儿园智慧校园采购项目支持ipad支持ipad支持ios图书馆学、情报学期刊投稿指南Descriptionios5columnios5
海外虚拟主机空间 vps主机 厦门域名注册 xenvps 如何注销域名备案 permitrootlogin 太原联通测速平台 日本bb瘦 怎样建立邮箱 169邮箱 美国免费空间 多线空间 跟踪路由命令 东莞服务器托管 lamp的音标 摩尔庄园注册 中国联通宽带测速 后门 zcloud 蓝队云 更多