《分布式系统-XML【优质参照】》由会员分享,可在线阅读,更多相关《分布式系统-XML【优质参照】(246页珍藏版)》请在金锄头文库上搜索。
1、XMLStevenHolzner,SamsTeachYourselfXMLin21Days,ThirdEdition.2003.1专业课件1.XML基础2专业课件MarkupLanguagesHelloFromHTMLAnHTMLDocumentThisisanHTMLdocument!标记是文档中数据的描述和解释3专业课件XMLeXtensibleMarkupLanguage元语言,创建标记语言的语言4专业课件ElementsarenestedRootelementcontainsallothers Element (or tag) namesExampleelementsRootRoot
2、elementEmptyelementattributesdeclaration5专业课件MoreTerminologyJohnisanicefellow21MainSt.Opening tagClosing tag: WhatisopenmustbeclosedNested element,child of PersonPersonParent of AddressAddress,Ancestor of numbernumber“standalone” text, not useful as dataChild of AddressAddress,Descendant of PersonPe
3、rsonContent of PersonPerson6专业课件IE中浏览XML文档7专业课件AnXMLDocumentUsingaStyleSheetJohnisanicefellow21MainSt.8专业课件ch01_04.cssPersondisplay:block;font-size:18pt;color:#0000ff;text-align:left9专业课件使用JavaScript抽取数据HelloFromXMLThisisanXMLdocument!10专业课件使用JavaScript抽取数据RetrievingdatafromanXMLdocumentfunctiongetD
4、ata()xmldoc=document.all(firstXML).XMLDocument;nodeDoc=xmldoc.documentElement;nodeHeading=nodeDoc.firstChild;outputMessage=Heading:+nodeHeading.firstChild.nodeValue;message.innerHTML=outputMessage;11专业课件使用JavaScript抽取数据RetrievingdatafromanXMLdocument12专业课件使用JavaScript抽取数据13专业课件使用Java从XML文档中抽取数据impor
5、tjavax.xml.parsers.*;importorg.w3c.dom.*;importjava.io.*;publicclassch01_06staticpublicvoidmain(Stringargv)tryDocumentBuilderFactorydbf=DocumentBuilderFactory.newInstance();DocumentBuilderdb=null;trydb=dbf.newDocumentBuilder();catch(ParserConfigurationExceptionpce)Documentdoc=null;doc=db.parse(ch01_
6、02.xml);14专业课件使用Java从XML文档中抽取数据for(Nodenode=doc.getDocumentElement().getFirstChild();node!=null;node=node.getNextSibling()if(nodeinstanceofElement)if(node.getNodeName().equals(heading)StringBufferbuffer=newStringBuffer();for(Nodesubnode=node.getFirstChild();subnode!=null;subnode=subnode.getNextSibli
7、ng()if(subnodeinstanceofText)buffer.append(subnode.getNodeValue();System.out.println(buffer.toString();catch(Exceptione)e.printStackTrace();15专业课件使用Java从XML文档中抽取数据javach01_06HelloFromXML16专业课件Well-formedXMLDocumentsMusthavearoot elementEveryopening tagmusthavematchingclosing tagElementsmustbeproperl
8、y 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)17专业课件ValidXMLDocuments!DOCTYPEdocumentHell
9、oFromXMLThisisanXMLdocument!18专业课件ValidXMLDocumentAvalidXMLdocumentisdefinedbytheW3Casawell-formedXMLdocumentwhichalsoconformstotherulesofaDocumentTypeDefinition(DTD)oranXMLSchema/ski:m/(XSD)19专业课件XML应用XML用于存储、传输、结构化数据纯文本格式使它容易被在互联网上传输并被不同平台上的应用所处理过去5年中,已经出现了上百种XML子语言20专业课件使用MathML显示4x25x+6=04&Invis
10、ibleTimes;x2-5⁢x+6=021专业课件在Amaya浏览器中显示MathML文档22专业课件XHTMLExtensibleHypertextMarkupLanguage更加严格允许增加自己的标记HTML4.01(当前版本)23专业课件AnXHTMLDocumentAnXHTMLPageWelcometoXHTML!ThisisanXHTMLdocument.Prettycool,eh?24专业课件在IE中显示25专业课件AnSVGDocumentSVGExample26专业课件练习validXML文档一定是well-formed吗?well-forme
11、dXML文档一定是valid吗?27专业课件编辑XML文档XML编辑器XMLSpyVisualStudioXMLDesignerXRayXML浏览器IE,MostpowerfulgeneralJumbo,CMLbrowser28专业课件Jumbo29专业课件XMLValidatorsMakesureitiswellformedandvalidScholarlyTechnologyGroupsvalidatorMicrosoftsVisualStudio.NET30专业课件error.xml!DOCTYPEdocumentHelloFromXMLThisisanXMLdocument!31专业课
12、件32专业课件XMLvalidationinVisualStudio.NET33专业课件建立一个完整的XML文档HelloFromXMLThisisanXMLdocument!34专业课件XML文档PrologsXMLdeclarationsProcessinginstructionsElementsandattributesCommentsCDATAsectionsEntities35专业课件字符编码问题ASCII仅有256个字符Chinese,Armenian,Hebrew,Thai,Tibetan从数量上、通用上,ASCII不能在Web上使用Unicode(http:/www.unico
13、de.org),65,536个字符前256个对应ASCII但让所有的软件转去支持Unicode太困难UCSTransformationFormat-8(UTF-8)36专业课件UTF-8所有ASCII字符的编码保持不变(8bit)其它Unicode字符使用2字节,直至6字节编码W3CrequiresallXMLprocessorstosupportbothUTF-8,UTF-16大部分支持UTF-837专业课件字符实体引用HelloFromXMLThistextisinsidea<message>element.38专业课件字符实体引用39专业课件字符实体引用<Replace
14、dwith&Replacedwith"Replacedwith'Replacedwith40专业课件实体实体是一大段文本的别名假如你为你的信件署名定义了一个实体lettersign,它代表下面这一大段文本:张三某网络公司销售部门北京市海淀区中关村88号,10000041专业课件实体邮件收件人李四/收件人主题hello/主题正文晚上吃饭!&lettersign;/正文/邮件42专业课件一般实体和参数实体一般实体声明:!ENTITYlettersign张三某网络公司销售部门北京市海淀区中关村88号,100000参数实体声明:!ENTITY%实体名文本内容43专业课件实体
15、引用&;注意:在引用XML实体之前,必须已经在XML文件中对此实体进行过声明;在实体引用中不能出现空格。也就是说,&lettersign;和&letterhead;的用法都会引起错误。尽管在一个实体中可以再引用其它实体,但是不能出现循环引用。也就是说,一个实体不能引用它自己;同样,也不能出现实体A引用实体B,然后实体B再反过来引用实体A的情况。实体引用不能在DOCTYPE声明中出现。实体引用的文本必须是形式良好的XML。44专业课件!DOCTYPE联系人列表张三A公司&A公司地址姓名gt;李四B公司&B公司地址/地址王五B公司&B公司地址/地址一旦哪个公司搬家了,只须改变实体声明中有关该公司的
16、地址,所有这个公司的联系人的地址也就都改过来了45专业课件空白Spaces,carriagereturns,linefeeds,andtabsarealltreatedaswhitespaceHelloFromXMLThisisanXMLdocument!headingHelloFromXMLThisisanXMLdocument!46专业课件Prologs(序言)XMLdeclarationsXMLcommentsprocessinginstructionswhitespacedoctypedeclarations47专业课件!DOCTYPEdocumentKellyGraceOctober
17、15,2005PrinterXMLDeclarationXMLCommentsProcessingInstruction由处理器定义RootElementElement属性48专业课件CDATACDATAstandsforcharacterdata,PCDATAstandsforparsedcharacterdata.49专业课件Hereshowtheelementstarts:!CDATAKellyGraceOctober15,2005Printer111$111.00.50专业课件InternetExplorertreatsthisCDATAsectionasunparsedtext51专
18、业课件练习一个文本编辑器保存XML文档时,并不提示字符集。该编辑器是否可用?把文本数据“Thisisaelement”包含在元素中,怎样做才不会迷惑XMLprocessor?XMLprolog可以包含哪些项目?52专业课件XMLNamespaces解决文档内和文档间名字冲突的机制Namespacedeclaration NamespaceNamespace符号串,通常为URL Prefix Prefix 名字空间的缩写,相当于别名Actualname(elementorattribute)prefix:nameDeclarations/prefixes作用范围作用范围 (scopescope)
19、 与begin/end类似Example: :backpackcyberpetDefaultnamespacetoy namespacereserved keyword53专业课件Namespaces(续)Scopesofdeclarationsarecolor-coded:New default; overshadows old defaultRedeclaration of cdecde; overshadows old declaration54专业课件Namespaces(续)xmlns=“http:/ lmntATTRIBUTE读 trbjut可选71专业课件Valid&DTD!DO
20、CTYPEdocument根元素0个或多个子元素被分析的字符数据序列选择空元素72专业课件子元素x+x出现1次或多次.x*x出现0次或多次.x?x可选,不出现或出现一次.x,yx的后继是y.顺序Sequencex|yx或y但不同时.Choice73专业课件顺序张三张三74专业课件重复张三张三75专业课件成组张三李四76专业课件或:必取其一张三77专业课件或张三张三8626843878专业课件混合元素既包括子元素又包括文字!DOCTYPECONTACTS张三(010)这是关于张三的信息79专业课件空元素KellyGrace80专业课件DTD注意在定义元素时,ETD的顺序是无关紧要的。因此和所定义
21、的文件结构是完全相同的。81专业课件DTD注意元素名的第一个字母必须是字母、或下划线_、或冒号:后跟字母、数字、句号.、冒号、下划线、连结号-的组合不能包含空白符,不能以“xml”开头。82专业课件提问83专业课件属性84专业课件缺省值85专业课件属性取值约束REQUIREDIMPLIEDFIXED默认86专业课件REQUIRED关键字REQUIRED说明XML文件中必须为这个属性给出一个属性值87专业课件IMPLIED当使用IMPLIED关键字时,XML分析器不再强行要求你在XML文件中给该属性赋值而且也无须在DTD中为该属性提供缺省值88专业课件FIXED需要为一个特定的属性提供一个缺省值
22、并且不希望XML文件的编写者把缺省值替代掉。89专业课件默认如果不使用上面任何一种关键字的话,该种属性就是属于这种类型。对于这种属性,你需要在DTD中为它提供一个缺省值。而在XML文件中可以为该属性给出新的属性值来覆盖事先定义的缺省值,也可以不另外给出属性值90专业课件属性类型CDATAEnumeratedIDIDREFIDREFSENTITYENTITIESNMTOKENNMTOKENSNOTATION91专业课件CDATACDATA指的是纯文本,即由字符、符号“&”、小于号“”和引号“”组成的字符串。当然,使用实体&代替“&”,<代替“”,"代替“”。92专业课件枚举
23、!DOCTYPE购物篮93专业课件IDID是用属性值的方式为文件中的某个元素定义唯一标识的方法,它的作用类似于HTML文件中的内部链接在一个文档中,任何两个元素的ID属性值不同一个元素只能有一个ID属性94专业课件!DOCTYPE联系人列表张三95专业课件IDREFIDREF类型允许一个元素的属性使用文件中的另一个元素,方法就是把那个元素的ID标识值作为该属性的取值存放多个其它元素的ID值,以空白分开96专业课件!DOCTYPE联系人列表张三李四李四libbb.org97专业课件实体实体在XML中充当着宏或别名的角色它的定义方式是:或利用SYSTEM定义外部实体,方式为:引用方式为:&实体名;
24、98专业课件!DOCTYPE联系人列表张三99专业课件DTD局限性不支持namespaces仅支持字符串数据类型一致性约束非常弱(ID/IDREF/IDREFSonly)不能够很方便地表达无序(unorder)的内容所有元素的名字是全局的100专业课件练习1指出错误!DOCTYPEdocumentOctober15,2005GraceKelly101专业课件练习2指出错误!DOCTYPEdocumentOctober15,2005GraceKelly102专业课件练习3指出错误!DOCTYPEdocumentOctober15,2005GraceKelly103专业课件!DOCTYPEdocu
25、mentOctober15,2005GraceKelly555.8888October16,2005MyrnaLoyMurielBlandings555.99994.指出错误104专业课件练习!DOCTYPEdocumentKellyGraceOctober15,2005105专业课件属性默认值-立即值!DOCTYPEdocument.106专业课件属性默认值-#REQUIRED!DOCTYPEdocumentKellyGrace107专业课件属性默认值-#IMPLIEDKellyGrace.108专业课件属性默认值-#FIXEDKellyGraceOctober15,2005109专业课件属
26、性类型-CDATAKellyGrace.110专业课件属性类型-ID.111专业课件属性类型-IDREFKellyGraceOctober15,2005GrantCaryOctober20,2005112专业课件属性类型-ENTITYKellyGraceOctober15,2005GrantCaryOctober20,2005113专业课件练习1.在元素中约束married属性的取值为yes或者no,默认值no?2.使用DTD定义可选的CDATA属性,属性名date,其值格式4/1/05;属性sex,取值male和female;一个必须的(required)属性name.并建立其实例文档。11
27、4专业课件XMLschema编辑工具XMLspyXRayMicrosoftVisualStudio.NET115专业课件XMLschemavalidatingVisualStudio.NETInternetExplorerXercesXRay116专业课件Welcome.xmlWelcometoXMLSchemas!117专业课件example.xsd118专业课件XRayvalidating119专业课件XMLSchemas(andDTDs)用途定义:实例文档的结构thiselementcontainstheseelements,whichcontainstheseotherelements
28、,etc每个元素/属性的数据类型thiselementshallholdanintegerwiththerange0to12,000(DTDsdontdotoowellwithspecifyingdatatypeslikethis)120专业课件XMLSchemas动机人们对DTDs不满:语法与XML不同YouwriteyourXML(instance)documentusingonesyntaxandtheDTDusinganothersyntax-bad,inconsistent有限的数据类型DTDssupportaverylimitedcapabilityforspecifyingdat
29、atypes.Youcant,forexample,expressIwanttheelementtoholdanintegerwitharangeof0to12,000DesireasetofdatatypescompatiblewiththosefoundindatabasesDTDsupports10datatypes;XMLSchemassupports44+datatypes121专业课件XMLSchemas特性增强的数据类型44+versus10CancreateyourowndatatypesExample:Thisisanewtypebasedonthestringtypeand
30、elementsofthistypemustfollowthispattern:ddd-dddd,wheredrepresentsadigit.与实例文档的语法相同lesssyntaxtoremember面向对象Canextendorrestrictatype(derivenewtypedefinitionsonthebasisofoldones)可以表达集合,i.e.,candefinethechildelementstooccurinanyorder122专业课件BookStore.dtd123专业课件ATTLISTELEMENTID#PCDATANMTOKENENTITYCDATABoo
31、kStoreBookTitleAuthorDateISBNPublisherThisisthevocabularythatDTDsprovidetodefineyournewvocabulary124专业课件elementcomplexTypeschemasequencehttp:/www.w3.org/2001/XMLSchemastringintegerbooleanBookStoreBookTitleAuthorDateISBNPublisherhttp:/www.books.org(targetNamespace)ThisisthevocabularythatXMLSchemaspro
32、videtodefineyournewvocabulary125专业课件BookStore.xsd xsd=Xml-SchemaDefinition(explanations onsucceeding pages)126专业课件127专业课件AllXMLSchemashaveschemaastherootelement.128专业课件Theelementsanddatatypesthatareusedtoconstructschemas-schema-element-complexType-sequence-stringcomefromthehttp:/XMLSchemanamespace12
33、9专业课件elementcomplexTypeschemasequencehttp:/www.w3.org/2001/XMLSchemaXMLSchemaNamespacestringintegerboolean130专业课件Indicatesthattheelementsdefinedbythisschema-BookStore-Book-Title-Author-Date-ISBN-Publisheraretogointhehttp:/books.orgnamespace131专业课件BookStoreBookTitleAuthorDateISBNPublisherhttp:/www.bo
34、oks.org(targetNamespace)BookNamespace(targetNamespace)132专业课件ThisisreferencingaBookelementdeclaration.TheBookinwhatnamespace?SincethereisnonamespacequalifieritisreferencingtheBookelementinthedefaultnamespace,whichisthetargetNamespace!Thus,thisisareferencetotheBookelementdeclarationinthisschema.Thede
35、faultnamespaceishttp:/www.books.orgwhichisthetargetNamespace!133专业课件实例文档中的任何元素必须指定名字空间134专业课件在XML实例文档中引用schemaMyLifeandTimesPaulMcCartneyJuly,199894303-12021-43892McMillinPublishing.1.声明默认的名字空间,告诉schema-validator本实例文档中所有元素来自于http:/www.books.org名字空间2.schemaLocation告诉schema-validator名字空间http:/www.book
36、s.org由BookStore.xsd定义3.告诉schema-validator属性schemaLocation在XMLSchema-instance名字空间中123135专业课件schemaLocationtypenoNamespaceSchemaLocationhttp:/www.w3.org/2001/XMLSchema-instanceXMLSchema-instanceNamespacenil136专业课件在XML实例文档中引用schemaBookStore.xmlBookStore.xsdtargetNamespace=http:/www.books.orgschemaLocat
37、ion=http:/www.books.orgBookStore.xsd-defineselementsinnamespacehttp:/www.books.org-useselementsfromnamespacehttp:/www.books.orgAschemadefinesanewvocabulary.Instancedocumentsusethatnewvocabulary.137专业课件验证BookStore.xmlBookStore.xsdXMLSchema.xsd(schema-for-schemas)Validatethatthexmldocumentconformstoth
38、erulesdescribedinBookStore.xsdValidatethatBookStore.xsdisavalidschemadocument,i.e.,itconformstotherulesdescribedintheschema-for-schemas138专业课件(seeexample02)Notethathttp:/XMLSchemaisthedefaultnamespace.Consequently,therearenonamespacequalifierson-schema-element-complexType-sequence-string139专业课件Herew
39、earereferencingaBookelement.WhereisthatBookelementdefined?Inwhatnamespace?Thebk:prefixindicateswhatnamespacethiselementisin.bk:hasbeensettobethesameasthetargetNamespace.140专业课件bk:ReferencesthetargetNamespaceBookStoreBookTitleAuthorDateISBNPublisherhttp:/www.books.org(targetNamespace)http:/www.w3.org
40、/2001/XMLSchemabkelementcomplexTypeschemasequencestringintegerbooleanConsequently,bk:BookreferstotheBookelementinthetargetNamespace.141专业课件内联元素声明142专业课件Notethatwehavemovedalltheelementdeclarationsinline,andwearenolongerrefingtotheelementdeclarations.Thisresultsinamuchmorecompactschema!Thiswayofdesig
41、ningtheschema-byinliningeverything-iscalledtheRussian Doll design.143专业课件Anonymoustypes(noname)144专业课件NamedTypes使用命名的complexType的等价定义.145专业课件 NamedtypeTheadvantageofsplittingoutBookselementdeclarationsandwrappingtheminanamedtypeisthatnowthistypecanbereusedbyotherelements.146专业课件Please note that:is e
42、quivalent to:ElementAreferencesthecomplexTypefoo.ElementAhasthecomplexTypedefinitioninlinedintheelementdeclaration.147专业课件定义元素小结(两种方式)Asimpletype(e.g.,xsd:string)orthenameofacomplexType(e.g.,BookPublication)12AnonnegativeintegerAnonnegativeintegerorunboundedNote: minOccurs and maxOccurs can only be
43、used in nested (local) element declarations.148专业课件问题日期不同于字符串ISBN格式:d-ddddd-ddd-dord-ddd-ddddd-dord-dd-dddddd-d,149专业课件数据类型150专业课件gYear数据类型Abuilt-indatatype(Gregoriancalendaryear)ElementsdeclaredtobeoftypegYearmustfollowthisform:CCYYrangeforCCis:00-99rangeforYYis:00-99Example:1999indicatesthegYear19
44、99151专业课件 Herewearedefininganew(user-defined)data-type,calledISBNType.DeclaringDatetobeoftypegYear,andISBNtobeoftypeISBNType(definedabove)152专业课件新的数据类型ISBNType.它是字符串的约束:-模式1:1digitfollowedbyadashfollowedby5digitsfollowedbyanotherdashfollowedby3digitsfollowedbyanotherdashfollowedby1moredigit,or-模式2:1
45、digitfollowedbyadashfollowedby3digitsfollowedbyanotherdashfollowedby5digitsfollowedbyanotherdashfollowedby1moredigit,or-模式3:1digitfollowedbyadashfollowedby2digitsfollowedbyanotherdashfollowedby6digitsfollowedbyanotherdashfollowedby1moredigit.正规表达式正规表达式153专业课件等价的表达式Theverticalbarmeansor154专业课件or?何时用c
46、omplexTypeelement何时用simpleTypeelement?当定义子元素时使用complexTypeelement当基于一个内置类型建立新类型时,使用simpleTypeelement155专业课件内置数据类型PrimitiveDatatypesstringbooleandecimalfloatdoubledurationdateTimetimedategYearMonthgYeargMonthDayAtomic,built-inHello Worldtrue,false, 1, 07.08 12.56E3,12,12560, 0,-0,INF,-INF,NAN12.56E3,
47、12,12560, 0,-0,INF,-INF,NANP1Y2M3DT10H30M12.3Sformat:CCYY-MM-DDThh:mm:ssformat:hh:mm:ss.sssformat:CCYY-MM-DDformat:CCYY-MMformat:CCYYformat:-MM-DDNote:Tisthedate/timeseparatorINF=infinityNAN=not-a-number156专业课件内置数据类型(续)PrimitiveDatatypesgDaygMonthhexBinarybase64BinaryanyURIQNameNOTATIONAtomic,built-
48、informat:-DD (notethe3dashes)format:-MM-ahexstringabase64stringhttp:/anamespacequalifiednameaNOTATIONfromtheXMLspec157专业课件内置数据类型(续)DerivedtypesnormalizedStringtokenlanguageIDREFSENTITIESNMTOKENNMTOKENSNameNCNameIDIDREFENTITYintegernonPositiveIntegerSubtypeofprimitivedatatypeAstringwithouttabs,linefe
49、eds,orcarriagereturnsStringw/otabs,l/f,leading/trailingspaces,consecutivespacesanyvalidxml:langvalue,e.g.,EN,FR,.mustbeusedonlywithattributesmustbeusedonlywithattributesmustbeusedonlywithattributesmustbeusedonlywithattributespart(nonamespacequalifier)mustbeusedonlywithattributesmustbeusedonlywithatt
50、ributesmustbeusedonlywithattributes456negativeinfinityto0158专业课件内置数据类型(续)DerivedtypesnegativeIntegerlongintshortbytenonNegativeIntegerunsignedLongunsignedIntunsignedShortunsignedBytepositiveIntegerSubtypeofprimitivedatatypenegativeinfinityto-1 -9223372036854775808to 9223372036854775807 -2147483648to
51、2147483647 -32768to32767 -127to1280toinfinity 0to18446744073709551615 0to4294967295 0to655350to2551 toinfinityNote:thefollowingtypescanonlybeusedwithattributes(whichwewilldiscusslater):ID,IDREF,IDREFS,NMTOKEN,NMTOKENS,ENTITY,andENTITIES.159专业课件从基类型创建新数据类型facets Example.string有6个facets:lengthminLengt
52、hmaxLengthpatternenumerationwhitespace(legalvalues:preserve,replace,collapse)160专业课件通过指定facets的值创建新类型1.ThiscreatesanewdatatypecalledTelephoneNumber.2.Elementsofthistypecanholdstringvalues,3.Butthestringlengthmustbeexactly8characterslongand4.Thestringmustfollowthepattern:ddd-dddd,wheredrepresentsadig
53、it.(Obviously,inthisexampletheregularexpressionmakesthelengthfacetredundant.)1234161专业课件又例Thiscreatesanewtypecalledshape.Anelementdeclaredtobeofthistypemusthaveeitherthevaluecircle,ortriangle,orsquare.162专业课件integer类型的Facetsinteger数据类型有8facets:totalDigitspatternwhitespaceenumerationmaxInclusivemaxEx
54、clusiveminInclusiveminExclusive163专业课件ExampleThiscreatesanewdatatypecalledEarthSurfaceElevation.Elementsdeclaredtobeofthistypecanholdaninteger.However,theintegerisrestrictedtohaveavaluebetween-1290and29035,inclusive.164专业课件通过指定Facet值建立新类型的一般格式Facets:-length-minlength-maxlength-pattern-enumeration-mi
55、nInclusive-maxInclusive-minExclusive-maxExclusive.Sources:-string-boolean-number-float-double-duration-dateTime-time.165专业课件多个Facets-and还是or?AnelementdeclaredtobeoftypeTelephoneNumbermustbeastringoflength=8 and thestringmustfollowthepattern:3digits,dash,4digits.Anelementdeclaredtobeoftypeshapemustbe
56、astringwithavalueofeithercircle,ortriangle, orsquare.Patterns,enumerations=orthemtogetherAllotherfacets=andthemtogether166专业课件从其它simpleType建立simpleType167专业课件ThissimpleTypeusesEarthSurfaceElevationasitsbasetype.168专业课件固定Facet的值simpleTypeswhichderivefromthissimpleTypemaynotchangethisfacet.169专业课件Erro
57、r!Cannotchangethevalueofafixedfacet!170专业课件包含用户自定义简单类型的元素Example.Createaschemaelementdeclarationforanelevationelement.Declaretheelevationelementtobeanintegerwitharange-1290to290355240Heresonewayofdeclaringtheelevationelement:171专业课件包含用户自定义简单类型的元素Heresanalternativemethodfordeclaringelevation:Thesimpl
58、eTypedefinitionisdefinedinline,itisan anonymoussimpleTypedefinition.ThedisadvantageofthisapproachisthatthissimpleTypemaynotbereusedbyotherelements.172专业课件定义元素小结(3种方式)123173专业课件Codetocheckthestructureandcontent(datatype)ofthedataCodetoactuallydotheworkInatypicalprogram,upto60%ofthecodeisspentchecking
59、thedata!-sourceunknownXMLSchemas节约了$Continued-174专业课件CodetocheckthestructureandcontentofthedataCodetoactuallydotheworkIfyourdataisstructuredasXML,andthereisaschema,thenyoucanhandthedata-checkingtaskofftoaschemavalidator.Thus,yourcodeisreducedbyupto60%!Big$savings!XMLSchemas节约了$175专业课件XMLSchemas的经典使用
60、(贸易伙伴-B2B)SupplierConsumerP.O.SchemaValidatorP.O.SchemaSoftwaretoProcessP.O.P.O.isokayP.O.(Schemaatthird-party,neutralwebsite)176专业课件参考资料ElliotteRustyHarold,XML Bible,SecondEdition,2001RogerL.Costello,XML Schema Tutorial,2001177专业课件XML&CSSTheDiscoursesEpictetusBookFourHeisfreewholivesashewishestoliv
61、e;whoisneithersubjecttocompulsionnortohindrance,nortoforce;whosemovementstoactionarenotimpeded,whosedesiresattaintheirpurpose,andwhodoesnotfallintothatwhichhewouldavoid.178专业课件Stylesheets是stylerule的集合titledisplay:block;font-size:36pt;font-weight:bold;text-align:center;text-decoration:underlinephilos
62、opherdisplay:block;font-size:16pt;text-align:centerbookdisplay:block;font-size:28pt;text-align:center;font-style:italicparagraphdisplay:block;margin-top:10SelectorRuleSpecificationproperty/valuepairs179专业课件XML&CSSTheDiscoursesEpictetusBookFourHeisfreewholivesashewishestolive;whoisneithersubjecttocom
63、pulsionnortohindrance,nortoforce;whosemovementstoactionarenotimpeded,whosedesiresattaintheirpurpose,andwhodoesnotfallintothatwhichhewouldavoid.180专业课件IE中的显示结果181专业课件格式化表格FirstNameLastNameLoanAmountFredTurner$100,000BillSaunders$120,000182专业课件格式化表格documentdisplay:table;border-style:solidheadersdispla
64、y: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:solid1p
65、xamountdisplay:table-cell;border-bottom:solid1px183专业课件Netscape中效果IE中不能正常显示184专业课件XML&XSLTXSLT:XML变换语言XMLHTML纯文本RTFXMLXSLT引擎引擎185专业课件California33871648SacramentoQuailGoldenPoppy155959Massachusetts6349097BostonChickadeeMayflower7840NewYork18976457AlbanyBluebirdRose47214186专业课件AnXSLTStyleSheet187专业课件引
66、擎服务器侧:.NetJSP客户侧:IE工具程序Javaapplicationxalan:AfreeXSLprocessor,implementedinJava,fromApache(http:/www.apache.org/)xt:AfreeXSLprocessor,implementedinJava,fromJamesClark(http:/ Node207专业课件Elements直接使用名字208专业课件Elements209专业课件AttributesCalifornia33871648SacramentoQuailGoldenPoppy155959210专业课件StateDataSta
67、teDataNamePopulationCapitalBirdFlowerArea211专业课件212专业课件HTMLTable213专业课件ID Attributes214专业课件Processing InstructionsMatchedaprocessinginstruction.215专业课件node testelementsthathavechildelements:anyelementthathasaorchildelement:anyelementthathasaunitsattribute:216专业课件练习练习Jeff555-1234555-4321lightgrey给定XM
68、L文件及XSLT文件,请写出IE打开XML文件后的显示结果217专业课件FitnessCenter.xslWelcomeWelcome!Yourphonenumbersare:TypeNumber218专业课件XSL: Formatting ObjectsXSLXSL-FOXSLTXSLTXPathXLink/XPointerXQueryXMLSchemas(high-precisiongraphics,e.g.,PDF)(low-precisiongraphics,e.g.,HTML,text,XML)219专业课件XSL-FO 1.056formattingobjects177proper
69、tiesthatapplytothoseobjectsXMLdocument.xmlXSLTprocessorXSL-FODocument.foXSL-FOprocessorformatteddisplaydocument.pdf220专业课件California33871648SacramentoQuailGoldenPoppy155959Massachusetts6349097BostonChickadeeMayflower7840NewYork18976457AlbanyBluebirdRose47214ch10_01.xml221专业课件ch0_02.xslt222专业课件使用使用XS
70、LT 引擎生成引擎生成FO文档文档%javach09_05ch10_01.xmlch10_02.xslch10_03.fo223专业课件ch10_03.foName:CaliforniaPopulation(people):33871648224专业课件Apache XML Projects FOPThemostpopularXSL-FOprocessorFreedownload:www.apache.org/fop命令:%java-cpbuildfop.jar;libbatik.jar;libxalan-2.3.1.jar;libxercesImpl-2.0.1.jar;libxml-api
71、s.jar;libavalon-framework-cvs-20020315.jar;liblogkit-1.0.jar;libjimi-1.0.jarorg.apache.fop.apps.Fopch10_03.foch10_04.pdf225专业课件226专业课件JavaScript & XMLDOM结点树ElementAttributeTextCDATAsectionEntityreferenceEntityProcessinginstructionCommentDocumentDocumenttypeDocumentfragmentNotation227专业课件例子例子TheRepor
72、tAllclearontheWesternfront./document228专业课件DOM treedocumenttitletextTheReportAllclearontheWesternfront.229专业课件The DOM LevelsLevel0Level1Level2Level3230专业课件唯一完整的DOM实现是IE6.0,支持Level1231专业课件DOM Level 1 objectsDocument文档对象DocumentFragment文档片断引用DocumentType元素引用EntityReference实体引用Element元素Attr属性Processing
73、Instruction处理指令Comment注释Text元素或属性的文本内容CDATASectionCDATA节.Entity实体Notation记号Node结点NodeList结点列表NamedNodeMap名-结点映射232专业课件Microsoft 的的DOM命名命名DOMDocumentXMLDOMNodeXMLDOMNodeList233专业课件DOMDocument对象对象functionreadXMLData()varxmlDocumentObjectxmlDocumentObject=newActiveXObject(MSXML2.DOMDocument.4.0)xmlDocu
74、mentObject.load(ch15_01.xml).234专业课件DOMDocument对象对象DOMDocumentattributesdoctypedocumentElemenfirstChildlastChildappendChild()createComment()createElement()load()235专业课件XMLDOMNode对象对象XMLDOMNodeattributeschildNodesnodeNamefirstChildlastChildappendChild()insertBefore()RemoveChild()ReplaceNode()236专业课件其
75、它对象其它对象XMLDOMElement对象XMLDOMAttribute对象XMLDOMText对象237专业课件例:例:ch15_01.xmlFinance17DonutCosts7/15/2005ThomasSmithFrankMcCoyJayJones使用JavaScript抽取第3个参议员JayJones238专业课件 Extracting XML Data function readXMLData() var xmlDocumentObject, sessionNode, committeeNode, attendeesNode var firstNameNode, lastNam
76、eNode, displayText xmlDocumentObject = new ActiveXObject(Microsoft.XMLDOM) xmlDocumentObject.load(ch15_01.xml) sessionNode = xmlDocumentObject.documentElement committeeNode = sessionNode.firstChild attendeesNode = committeeNode.lastChild senatorNode = attendeesNode.lastChild firstNameNode = senatorN
77、ode.firstChild lastNameNode = firstNameNode.nextSibling displayText = Last senators name: +firstNameNode.firstChild.nodeValue + + lastNameNode.firstChild.nodeValue displayDIV.innerHTML = displayText ch15_02.html239专业课件ch15_02.htmlExtractingXMLData240专业课件IE中读取中读取XML元素元素241专业课件查找元素查找元素 Searching for E
78、lements function readXMLData() var xmlDocumentObject, firstNameNodes, listNodesLastName xmlDocumentObject = new ActiveXObject(Microsoft.XMLDOM) xmlDocumentObject.load(ch15_01.xml) firstNameNodes = xmlDocumentObject.getElementsByTagName( firstName) lastNameNodes = xmlDocumentObject.getElementsByTagNa
79、me( lastName) outputText = Last senators name: + firstNameNodes(2).firstChild.nodeValue + + lastNameNodes(2).firstChild.nodeValue displayDIV.innerHTML=outputText 242专业课件查找元素查找元素(续续)SearchingforElements243专业课件获取属性值获取属性值 Getting attribute values function readXMLData() var xmlDocumentObject, sessionNod
80、e, committeeNode, attendeesNode var firstNameNode, lastNameNode, displayText var attributes, statusSenator xmlDocumentObject = new ActiveXObject(Microsoft.XMLDOM) xmlDocumentObject.load(ch15_01.xml) sessionNode = xmlDocumentObject.documentElement committeeNode = sessionNode.firstChild attendeesNode
81、= committeeNode.lastChild senatorNode = attendeesNode.lastChild firstNameNode = senatorNode.firstChild lastNameNode = firstNameNode.nextSibling attributes = senatorNode. attributes statusSenator = attributes.getNamedItem(status) outputText = firstNameNode.firstChild.nodeValue + + lastNameNode.firstChild.nodeValue + s status is: + statusSenator.value displayDIV.innerHTML=outputText 244专业课件获取属性值获取属性值Gettingattributevalues245专业课件获取属性值获取属性值246专业课件