分布式系统-XML

上传人:hao****021 文档编号:240715321 上传时间:2024-05-02 格式:PPT 页数:246 大小:2.17MB
返回 下载 相关 举报
分布式系统-XML_第1页
第1页 / 共246页
分布式系统-XML_第2页
第2页 / 共246页
分布式系统-XML_第3页
第3页 / 共246页
点击查看更多>>
资源描述
1XMLStevenHolzner,SamsTeachYourselfXMLin21Days,ThirdEdition._.21.XML基础3MarkupLanguagesHelloFromHTMLAnHTMLDocumentThisisanHTMLdocument!标记是文档中数据的描述和解释4XMLeXtensibleMarkupLanguage元语言,创建标记语言的语言5ElementsarenestedRootelementcontainsallothers Element(or tag)namesExampleelementsRootRoot elementEmptyelementattributesdeclaration6MoreTerminologyJohnisanicefellow21MainSt.Opening tagClosing tag:WhatisopenmustbeclosedNested element,child of PersonPersonParent of AddressAddress,Ancestor of numbernumber“standalone”text,not useful as dataChild of AddressAddress,Descendant of PersonPersonContent of PersonPerson7IE中浏览XML文档8AnXMLDocumentUsingaStyleSheetJohnisanicefellow21MainSt.9Persondisplay:block;font-size:18pt;color:#0000ff;text-align:left10使用JavaScript抽取数据HelloFromXMLThisisanXMLdocument!11使用JavaScript抽取数据RetrievingdatafromanXMLdocumentfunctiongetData()xmldoc=document.all(firstXML).XMLDocument;nodeDoc=;nodeHeading=;outputMessage=Heading:+;=outputMessage;12使用JavaScript抽取数据RetrievingdatafromanXMLdocument13使用JavaScript抽取数据14使用Java从XML文档中抽取数据import.*;importorg.w3c.dom.*;import.*;publicclassch01_06staticpublicvoidmain(Stringargv)tryDocumentBuilderFactorydbf=();DocumentBuilderdb=null;trydb=();catch(ParserConfigurationExceptionpce)Documentdoc=null;doc=db.parse(ch01_02.xml);15使用Java从XML文档中抽取数据for(Nodenode=doc.getDocumentElement().getFirstChild();node!=null;node=()if(nodeinstanceofElement)if(node.getNodeName().equals(heading)StringBufferbuffer=newStringBuffer();for(Nodesubnode=();subnode!=null;subnode=subnode.getNextSibling()if(subnodeinstanceofText)();();catch(Exceptione)();16使用Java从XML文档中抽取数据java ch01_06 Hello From XML 17Well-formedXMLDocumentsMusthavearoot elementEveryopening tagmusthavematchingclosing tagElementsmustbeproperly nestedisano-noAnattributenamecanoccurat most onceinanopeningtag.Ititoccurs,Itmust have a value(booleanattrs,likeinHTML,arenotallowed)Thevaluemust be quoted(with“or)XML processors are not supposed to try and fix ill-formed documents(unlike HTML browsers)18ValidXMLDocuments!DOCTYPEdocumentHelloFromXMLThisisanXMLdocument!ValidXMLDocumentAvalidXMLdocumentisdefinedbytheW3Casawell-formedXMLdocumentwhichalsoconformstotherulesofaDocumentTypeDefinition(DTD)oranXMLSchema/ski:m/(XSD)1920XML应用XML用于存储、传输、结构化数据纯文本格式使它容易被在互联网上传输并被不同平台上的应用所处理过去5年中,已经出现了上百种XML子语言21使用MathML显示4x25x+6=04⁢x2-5⁢x+6=022在Amaya浏览器中显示MathML文档23XHTMLExtensibleHypertextMarkupLanguage更加严格允许增加自己的标记(当前版本)24AnXHTMLDocumentAnXHTMLPageWelcometoXHTML!ThisisanXHTMLdocument.Prettycool,eh?25在IE中显示26AnSVGDocumentSVGExample27练习validXML文档一定是well-formed吗?well-formedXML文档一定是valid吗?28编辑XML文档XML编辑器XMLSpyVisualStudioXMLDesignerXRayXML浏览器IE,MostpowerfulgeneralJumbo,CMLbrowser29Jumbo30XMLValidatorsMakesureitiswellformedandvalidScholarlyTechnologyGroupsvalidatorMicrosoftsVisualStudio.NET31!DOCTYPEdocumentHelloFromXMLThisisanXMLdocument!3233XMLvalidationinVisualStudio.NET34建立一个完整的XML文档HelloFromXMLThisisanXMLdocument!35XML文档PrologsXMLdeclarationsProcessinginstructionsElementsandattributesCommentsCDATAsectionsEntities36字符编码问题ASCII仅有256个字符Chinese,Armenian,Hebrew,Thai,Tibetan从数量上、通用上,ASCII不能在Web上使用Unicode(http:/),65,536个字符前256个对应ASCII但让所有的软件转去支持Unicode太困难UCSTransformationFormat-8(UTF-8)37UTF-8所有ASCII字符的编码保持不变(8bit)其它Unicode字符使用2字节,直至6字节编码W3CrequiresallXMLprocessorstosupportbothUTF-8,UTF-16大部分支持UTF-838字符实体引用HelloFromXMLThistextisinsidea<message>element.39字符实体引用40字符实体引用<Replacedwith&Replacedwith"Replacedwith'Replacedwith实体实体是一大段文本的别名假如你为你的信件署名定义了一个实体lettersign,它代表下面这一大段文本:张三某网络公司销售部门北京市海淀区中关村88号,10000041实体邮件收件人李四/收件人主题hello/主题正文晚上吃饭!&lettersign;/正文/邮件42一般实体和参数实体一般实体声明:!ENTITYlettersign张三某网络公司销售部门北京市海淀区中关村88号,100000参数实体声明:!ENTITY%实体名文本内容43实体引用&;注意:在引用XML实体之前,必须已经在XML文件中对此实体进行过声明;在实体引用中不能出现空格。也就是说,&lettersign;和&letterhead;的用法都会引起错误。尽管在一个实体中可以再引用其它实体,但是不能出现循环引用。也就是说,一个实体不能引用它自己;同样,也不能出现实体A引用实体B,然后实体B再反过来引用实体A的情况。实体引用不能在DOCTYPE声明中出现。实体引用的文本必须是形式良好的XML。4445!DOCTYPE联系人列表张三A公司&A公司地址姓名gt;李四B公司&B公司地址/地址王五B公司&B公司地址/地址一旦哪个公司搬家了,只须改变实体声明中有关该公司的地址,所有这个公司的联系人的地址也就都改过来了46空白Spaces,carriagereturns,linefeeds,andtabsarealltreatedaswhitespaceHelloFromXMLThisisanXMLdocument!headingHelloFromXMLThisisanXMLdocument!47Prologs(序言)XMLdeclarationsXMLcommentsprocessinginstructionswhitespacedoctypedeclarations48!DOCTYPEdocumentKellyGraceOctober15,2005PrinterXMLDeclarationXMLCommentsProcessingInstruction由处理器定义RootElementElement属性49CDATACDATAstandsforcharacterdata,PCDATAstandsforparsedcharacterdata.50Hereshowtheelementstarts:!CDATAKellyGraceOctober15,2005Printer111$111.00.51InternetExplorertreatsthisCDATAsectionasunparsedtext52练习一个文本编辑器保存XML文档时,并不提示字符集。该编辑器是否可用?把文本数据“Thisisaelement”包含在元素中,怎样做才不会迷惑XMLprocessor?XMLprolog可以包含哪些项目?53XMLNamespaces解决文档内和文档间名字冲突的机制Namespacedeclaration NamespaceNamespace符号串,通常为URL Prefix Prefix 名字空间的缩写,相当于别名Actualname(elementorattribute)prefix:nameDeclarations/prefixes作用范围作用范围(scopescope)与begin/end类似Example:backpackcyberpetDefaultnamespacetoy namespacereserved keyword54Namespaces(续)Scopesofdeclarationsarecolor-coded:New default;overshadows old defaultRedeclaration of cdecde;overshadows old declaration55Namespaces(续)xmlns=“http:/bar”并不意味着此URL上有一个文档,这种格式仅仅是个约定俗成。一个namespace仅仅是个标识符一些前缀已经成为标准。E.g.,xsdxslEtc.56Valid&DTD!DOCTYPEdocument57KellyGraceOctober15,2005Printer111$111.00Laptop222$989.0058GrantCaryOctober20,2005Desktop333$2995.00Scanner444$200.00GableClarkOctober25,2005Keyboard555$129.00Mouse666$25.00在NetBeans中新建XML文档59在NetBeans中新建XML文档60CheckXML61XMLcheckingstarted.Checkingfile:/F:/work/DS2011/SimpleHttpServer/src/test.xml.XMLcheckingfinished.ValidateXML62XMLvalidationstarted.Checkingfile:/F:/work/DS2011/SimpleHttpServer/src/test.xml.XMLvalidationfinished.63Validatinghttp:/64Validating制造一个错误,比如改为重新使用ValidateXML命令65DocumentTypeDefinition(DTD)DTD定义了XML文档的语法DTD是可选的如果文档符合它的DTD,该文档就称为valid66DTD(续)DTD作为文档的一部分:67DTD(续)DTD作为单独的文件:单独的DTD文件6869DTD(续)DTD作为单独的文件:绝对路径引用方式相对路径引用方式:DTD与XML文档同一路径相对路径引用方式:DTD与XML文档相对路径70DTD(续)system关键字主要用于引用一个作者或组织所编写的众多XML文件中通用的DTD。还存在一种外部DTD,它是一个由权威机构制订的,提供给特定行业或公众使用的DTD。因此,另一个引用外部DTD的办法是使用关键字public,引用这一类公开给公众使用的DTD例根元素DTD名称(所有者/类型/语言)DTD的URL71DTD成分注意:注意:ELEMENT读读 lmntATTRIBUTE读 trbjut可选72Valid&DTD!DOCTYPEdocument根元素0个或多个子元素被分析的字符数据序列选择空元素73子元素x+x出现1次或多次.x*x出现0次或多次.x?x可选,不出现或出现一次.x,yx的后继是y.顺序Sequencex|yx或y但不同时.Choice顺序74张三张三重复75张三张三成组76张三李四或:必取其一77张三或78张三张三86268438混合元素既包括子元素又包括文字79!DOCTYPECONTACTS张三(010)62345678这是关于张三的信息80空元素KellyGraceDTD注意81在定义元素时,ETD的顺序是无关紧要的。因此和所定义的文件结构是完全相同的。DTD注意82元素名的第一个字母必须是字母、或下划线_、或冒号:后跟字母、数字、句号.、冒号、下划线、连结号-的组合不能包含空白符,不能以“xml”开头。83提问属性84缺省值85属性取值约束REQUIREDIMPLIEDFIXED默认86REQUIRED关键字REQUIRED说明XML文件中必须为这个属性给出一个属性值87IMPLIED当使用IMPLIED关键字时,XML分析器不再强行要求你在XML文件中给该属性赋值而且也无须在DTD中为该属性提供缺省值88FIXED需要为一个特定的属性提供一个缺省值并且不希望XML文件的编写者把缺省值替代掉。89默认如果不使用上面任何一种关键字的话,该种属性就是属于这种类型。对于这种属性,你需要在DTD中为它提供一个缺省值。而在XML文件中可以为该属性给出新的属性值来覆盖事先定义的缺省值,也可以不另外给出属性值90属性类型CDATAEnumeratedIDIDREFIDREFSENTITYENTITIES91NMTOKENNMTOKENSNOTATIONCDATACDATA指的是纯文本,即由字符、符号“&”、小于号“”和引号“”组成的字符串。当然,使用实体&代替“&”,<代替“”,"代替“”。92枚举93!DOCTYPE购物篮IDID是用属性值的方式为文件中的某个元素定义唯一标识的方法,它的作用类似于HTML文件中的内部链接在一个文档中,任何两个元素的ID属性值不同一个元素只能有一个ID属性9495!DOCTYPE联系人列表张三IDREFIDREF类型允许一个元素的属性使用文件中的另一个元素,方法就是把那个元素的ID标识值作为该属性的取值存放多个其它元素的ID值,以空白分开9697!DOCTYPE联系人列表张三李四李四实体实体在XML中充当着宏或别名的角色它的定义方式是:或利用SYSTEM定义外部实体,方式为:引用方式为:&实体名;9899!DOCTYPE联系人列表张三100DTD局限性不支持namespaces仅支持字符串数据类型一致性约束非常弱(ID/IDREF/IDREFSonly)不能够很方便地表达无序(unorder)的内容所有元素的名字是全局的101练习1指出错误!DOCTYPEdocumentOctober15,2005GraceKelly102练习2指出错误!DOCTYPEdocumentOctober15,2005GraceKelly103练习3指出错误!DOCTYPEdocumentOctober15,2005GraceKelly104!DOCTYPEdocumentOctober15,2005GraceKellyOctober16,2005MyrnaLoyMurielBlandings4.指出错误105练习!DOCTYPEdocumentKellyGraceOctober15,2005106属性默认值-立即值!DOCTYPEdocument.107属性默认值-#REQUIRED!DOCTYPEdocumentKellyGrace108属性默认值-#IMPLIEDKellyGrace.109属性默认值-#FIXEDKellyGraceOctober15,2005110属性类型-CDATAKellyGrace.111属性类型-ID.112属性类型-IDREFKellyGraceOctober15,2005GrantCaryOctober20,2005113属性类型-ENTITYKellyGraceOctober15,2005GrantCaryOctober20,2005114练习1.在元素中约束married属性的取值为yes或者no,默认值no?2.使用DTD定义可选的CDATA属性,属性名date,其值格式4/1/05;属性sex,取值male和female;一个必须的(required)属性name.并建立其实例文档。115XMLschema编辑工具XMLspyXRayMicrosoftVisualStudio.NET116XMLschemavalidatingVisualStudio.NETInternetExplorerXercesXRay117WelcometoXMLSchemas!118119XRayvalidating120XMLSchemas(andDTDs)用途定义:实例文档的结构thiselementcontainstheseelements,whichcontainstheseotherelements,etc每个元素/属性的数据类型thiselementshallholdanintegerwiththerange0to12,000(DTDsdontdotoowellwithspecifyingdatatypeslikethis)121XMLSchemas动机人们对DTDs不满:语法与XML不同YouwriteyourXML(instance)documentusingonesyntaxandtheDTDusinganothersyntax-bad,inconsistent有限的数据类型DTDssupportaverylimitedcapabilityforspecifyingdatatypes.Youcant,forexample,expressIwanttheelementtoholdanintegerwitharangeof0to12,000DesireasetofdatatypescompatiblewiththosefoundindatabasesDTDsupports10datatypes;XMLSchemassupports44+datatypes122XMLSchemas特性增强的数据类型44+versus10CancreateyourowndatatypesExample:Thisisanewtypebasedonthestringtypeandelementsofthistypemustfollowthispattern:ddd-dddd,wheredrepresentsadigit.与实例文档的语法相同lesssyntaxtoremember面向对象Canextendorrestrictatype(derivenewtypedefinitionsonthebasisofoldones)可以表达集合,i.e.,candefinethechildelementstooccurinanyorder123124ATTLISTELEMENTID#PCDATANMTOKENENTITYCDATABookStoreBookTitleAuthorDateISBNPublisherThisisthevocabularythatDTDsprovidetodefineyournewvocabulary125elementcomplexTypeschemasequencestringintegerbooleanBookStoreBookTitleAuthorDateISBNPublisherhttp:/(targetNamespace)ThisisthevocabularythatXMLSchemasprovidetodefineyournewvocabulary126 xsd=Xml-SchemaDefinition(explanations onsucceeding pages)127128AllXMLSchemashaveschemaastherootelement.129Theelementsanddatatypesthatareusedtoconstructschemas-schema-element-complexType-sequence-stringcomefromthehttp:/XMLSchemanamespace130elementcomplexTypeschemasequenceXMLSchemaNamespacestringintegerboolean131Indicatesthattheelementsdefinedbythisschema-BookStore-Book-Title-Author-Date-ISBN-Publisheraretogointhehttp:/namespace132BookStoreBookTitleAuthorDateISBNPublisherhttp:/(targetNamespace)BookNamespace(targetNamespace)133ThisisreferencingaBookelementdeclaration.TheBookinwhatnamespace?SincethereisnonamespacequalifieritisreferencingtheBookelementinthedefaultnamespace,whichisthetargetNamespace!Thus,thisisareferencetotheBookelementdeclarationinthisschema.Thedefaultnamespaceishttp:/whichisthetargetNamespace!134实例文档中的任何元素必须指定名字空间135在XML实例文档中引用schemaMyLifeandTimesPaulMcCartneyJuly,199894303-12021-43892McMillinPublishing.1.声明默认的名字空间,告诉schema-validator本实例文档中所有元素来自于http:/名字空间2.schemaLocation告诉schema-validator名字空间http:/由定义3.告诉schema-validator属性schemaLocation在XMLSchema-instance名字空间中123136schemaLocationtypenoNamespaceSchemaLocationXMLSchema-instanceNamespacenil137在XML实例文档中引用schematargetNamespace=http:/schemaLocation=http:/-defineselementsinnamespacehttp:/-useselementsfromnamespacehttp:/Aschemadefinesanewvocabulary.Instancedocumentsusethatnewvocabulary.138验证(schema-for-schemas)ValidatethatthexmldocumentconformstotherulesdescribedinValidatethatisavalidschemadocument,i.e.,itconformstotherulesdescribedintheschema-for-schemas139(seeexample02)Notethathttp:/XMLSchemaisthedefaultnamespace.Consequently,therearenonamespacequalifierson-schema-element-complexType-sequence-string140HerewearereferencingaBookelement.WhereisthatBookelementdefined?Inwhatnamespace?Thebk:prefixindicateswhatnamespacethiselementisin.bk:hasbeensettobethesameasthetargetNamespace.141bk:ReferencesthetargetNamespaceBookStoreBookTitleAuthorDateISBNPublisherhttp:/(targetNamespace)bkelementcomplexTypeschemasequencestringintegerbooleanConsequently,bk:BookreferstotheBookelementinthetargetNamespace.142内联元素声明143Notethatwehavemovedalltheelementdeclarationsinline,andwearenolongerrefingtotheelementdeclarations.Thisresultsinamuchmorecompactschema!Thiswayofdesigningtheschema-byinliningeverything-iscalledtheRussian Doll design.144Anonymoustypes(noname)145NamedTypes使用命名的complexType的等价定义.146 NamedtypeTheadvantageofsplittingoutBookselementdeclarationsandwrappingtheminanamedtypeisthatnowthistypecanbereusedbyotherelements.147Please note that:is equivalent to:ElementAreferencesthecomplexTypefoo.ElementAhasthecomplexTypedefinitioninlinedintheelementdeclaration.148定义元素小结(两种方式)Asimpletype(e.g.,xsd:string)orthenameofacomplexType(e.g.,BookPublication)12AnonnegativeintegerAnonnegativeintegerorunboundedNote:minOccurs and maxOccurs can only be used in nested(local)element declarations.149问题日期不同于字符串ISBN格式:d-ddddd-ddd-dord-ddd-ddddd-dord-dd-dddddd-d,150数据类型151gYear数据类型Abuilt-indatatype(Gregoriancalendaryear)ElementsdeclaredtobeoftypegYearmustfollowthisform:CCYYrangeforCCis:00-99rangeforYYis:00-99Example:1999indicatesthegYear1999152 Herewearedefininganew(user-defined)data-type,calledISBNType.DeclaringDatetobeoftypegYear,andISBNtobeoftypeISBNType(definedabove)153新的数据类型ISBNType.它是字符串的约束:-模式1:1digitfollowedbyadashfollowedby5digitsfollowedbyanotherdashfollowedby3digitsfollowedbyanotherdashfollowedby1moredigit,or-模式2:1digitfollowedbyadashfollowedby3digitsfollowedbyanotherdashfollowedby5digitsfollowedbyanotherdashfollowedby1moredigit,or-模式3:1digitfollowedbyadashfollowedby2digitsfollowedbyanotherdashfollowedby6digitsfollowedbyanotherdashfollowedby1moredigit.正规表达式正规表达式154等价的表达式Theverticalbarmeansor155or?何时用complexTypeelement何时用simpleTypeelement?当定义子元素时使用complexTypeelement当基于一个内置类型建立新类型时,使用simpleTypeelement156内置数据类型PrimitiveDatatypesstringbooleandecimalfloatdoubledurationdateTimetimedategYearMonthgYeargMonthDayAtomic,built-inHello Worldtrue,false,1,0,12,12560,0,-0,INF,-INF,NAN,12,12560,0,-0,INF,-INF,NANformat:CCYY-MM-DDThh:mm:ssformat:format:CCYY-MM-DDformat:CCYY-MMformat:CCYYformat:-MM-DDNote:Tisthedate/timeseparatorINF=infinityNAN=not-a-number157内置数据类型(续)PrimitiveDatatypesgDaygMonthhexBinarybase64BinaryanyURIQNameNOTATIONAtomic,built-informat:-DD(notethe3dashes)format:-MM-ahexstringabase64stringhttp:/anamespacequalifiednameaNOTATIONfromtheXMLspec158内置数据类型(续)DerivedtypesnormalizedStringtokenlanguageIDREFSENTITIESNMTOKENNMTOKENSNameNCNameIDIDREFENTITYintegernonPositiveIntegerSubtypeofprimitivedatatypeAstringwithouttabs,linefeeds,orcarriagereturnsStringw/otabs,l/f,leading/trailingspaces,consecutivespacesanyvalidxml:langvalue,e.g.,EN,FR,.mustbeusedonlywithattributesmustbeusedonlywithattributesmustbeusedonlywithattributesmustbeusedonlywithattributespart(nonamespacequalifier)mustbeusedonlywithattributesmustbeusedonlywithattributesmustbeusedonlywithattributes456negativeinfinityto0159内置数据类型(续)DerivedtypesnegativeIntegerlongintshortbytenonNegativeIntegerunsignedLongunsignedIntunsignedShortunsignedBytepositiveIntegerSubtypeofprimitivedatatypenegativeinfinityto-1-9223372036854775808to 9223372036854775807 -2147483648to2147483647-32768to32767-127to1280toinfinity 0to 0to4294967295 0to655350to2551 toinfinityNote:thefollowingtypescanonlybeusedwithattributes(whichwewilldiscusslater):ID,IDREF,IDREFS,NMTOKEN,NMTOKENS,ENTITY,andENTITIES.160从基类型创建新数据类型facets Example.string有6个facets:lengthminLengthmaxLengthpatternenumerationwhitespace(legalvalues:preserve,replace,collapse)161通过指定facets的值创建新类型1.ThiscreatesanewdatatypecalledTelephoneNumber.2.Elementsofthistypecanholdstringvalues,3.Butthestringlengthmustbeexactly8characterslongand4.Thestringmustfollowthepattern:ddd-dddd,wheredrepresentsadigit.(Obviously,inthisexampletheregularexpressionmakesthelengthfacetredundant.)1234162又例Thiscreatesanewtypecalledshape.Anelementdeclaredtobeofthistypemusthaveeitherthevaluecircle,ortriangle,orsquare.163integer类型的Facetsinteger数据类型有8facets:totalDigitspatternwhitespaceenumerationmaxInclusivemaxExclusiveminInclusiveminExclusive164ExampleThiscreatesanewdatatypecalledEarthSurfaceElevation.Elementsdeclaredtobeofthistypecanholdaninteger.However,theintegerisrestrictedtohaveavaluebetween-1290and29035,inclusive.165通过指定Facet值建立新类型的一般格式Facets:-length-minlength-maxlength-pattern-enumeration-minInclusive-maxInclusive-minExclusive-maxExclusive.Sources:-string-boolean-number-float-double-duration-dateTime-time.166多个Facets-and还是or?AnelementdeclaredtobeoftypeTelephoneNumbermustbeastringoflength=8 and thestringmustfollowthepattern:3digits,dash,4digits.Anelementdeclaredtobeoftypeshapemustbeastringwithavalueofeithercircle,ortriangle,orsquare.Patterns,enumerations=orthemtogetherAllotherfacets=andthemtogether167从其它simpleType建立simpleType168ThissimpleTypeusesEarthSurfaceElevationasitsbasetype.169固定Facet的值simpleTypeswhichderivefromthissimpleTypemaynotchangethisfacet.170Error!Cannotchangethevalueofafixedfacet!171包含用户自定义简单类型的元素Example.Createaschemaelementdeclarationforanelevationelement.Declaretheelevationelementtobeanintegerwitharange-1290to290355240Heresonewayofdeclaringtheelevationelement:172包含用户自定义简单类型的元素Heresanalternativemethodfordeclaringelevation:ThesimpleTypedefinitionisdefinedinline,itisan anonymoussimpleTypedefinition.ThedisadvantageofthisapproachisthatthissimpleTypemaynotbereusedbyotherelements.173定义元素小结(3种方式)123174Codetocheckthestructureandcontent(datatype)ofthedataCodetoactuallydotheworkInatypicalprogram,upto60%ofthecodeisspentcheckingthedata!-sourceunknownXMLSchemas节约了$Continued-175CodetocheckthestructureandcontentofthedataCodetoactuallydotheworkIfyourdataisstructuredasXML,andthereisaschema,thenyoucanhandthedata-checkingtaskofftoaschemavalidator.Thus,yourcodeisreducedbyupto60%!Big$savings!XMLSchemas节约了$176XMLSchemas的经典使用(贸易伙伴-B2B)SupplierConsumerP.O.SchemaValidatorP.O.SchemaSoftwaretoProcessP.O.P.O.isokayP.O.(Schemaatthird-party,neutralwebsite)177参考资料ElliotteRustyHarold,XML Bible,SecondEdition,2001RogerL.Costello,XML Schema Tutorial,2001178XML&CSSTheDiscoursesEpictetusBookFourHeisfreewholivesashewishestolive;whoisneithersubjecttocompulsionnortohindrance,nortoforce;whosemovementstoactionarenotimpeded,whosedesiresattaintheirpurpose,andwhodoesnotfallintothatwhichhewouldavoid.179Stylesheets是stylerule的集合titledisplay:block;font-size:36pt;font-weight:bold;text-align:center;text-decoration:underlinephilosopherdisplay:block;font-size:16pt;text-align:centerbookdisplay:block;font-size:28pt;text-align:center;font-style:italicparagraphdisplay:block;margin-top:10SelectorRuleSpecificationproperty/valuepairs180XML&CSSTheDiscoursesEpictetusBookFourHeisfreewholivesashewishestolive;whoisneithersubjecttocompulsionnortohindrance,nortoforce;whosemovementstoactionarenotimpeded,whosedesiresattaintheirpurpose,andwhodoesnotfallintothatwhichhewouldavoid.181IE中的显示结果182格式化表格FirstNameLastNameLoanAmountFredTurner$100,000BillSaunders$120,000183格式化表格documentdisplay:table;border-style:solidheadersdisplay:table-header-group;headerdisplay:table-cell;padding:6px;background-color:lightblue;font-weight:bold;border-style:solidmortgagesdisplay:table-row-groupmortgagedisplay:table-row;firstNamedisplay:table-cell;padding:6px;border-bottom:solid1pxlastNamedisplay:table-cell;padding:6px;border-bottom:solid1pxamountdisplay:table-cell;border-bottom:solid1px184Netscape中效果IE中不能正常显示185XML&XSLTXSLT:XML变换语言XMLHTML纯文本RTFXMLXSLT引擎引擎186California33871648SacramentoQuailGoldenPoppy155959Massachusetts6349097BostonChickadeeMayflower7840NewYork18976457AlbanyBluebirdRose47214187AnXSLTStyleSheet188引擎服务器侧:.NetJSP客户侧:IE工具程序Javaapplicationxalan:AfreeXSLprocessor,implementedinJava,fromApache(http:/)xt:AfreeXSLprocessor,implementedinJava,fromJamesClark(http:/)saxon:AfreeXSLprocessor,implementedinJava,fromMichaelKay(http:/189xalan/xt/saxonXMLXSLHTML(orXMLortext)190AJSPPage191192生成的页面CaliforniaMassachusettsNewYork193Client-SideXSLTCalifornia33871648SacramentoQuailGoldenPoppy155959NewYork18976457AlbanyBluebirdRose47214194IE变换效果195JavaapplicationXSLTsupportbuiltintotheJavaprogramminglanguage,versions1.4andlater196import.*;import.*;import.*;publicclassch09_05publicstaticvoidmain(Stringargs)tryTransformerFactorytf=();Transformertr=tf.newTransformer(newStreamSource(newFile(args1);tr.transform(newStreamSource(newFile(args0),newStreamResult(newFile(args2);catch(Exceptionex)197%javach09_05ch09_01.xmlch09_02.xslCaliforniaMassachusettsNewYork198XSLT如何处理XML文档XML文档:结点树Document/PIElement1997种类型结点AttributeAnattribute.CommentThetextofacomment(excludingtheparts).ElementAnelement.NamespaceThenamespacesURI.ProcessinginstructionThetextoftheprocessinginstruction(excluding).RootnodeTheverysta
展开阅读全文
相关资源
相关搜索

最新文档


当前位置:首页 > 图纸专区 > 课件教案


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!