数据库教学课件:Viper-XML-Concepts_第1页
数据库教学课件:Viper-XML-Concepts_第2页
数据库教学课件:Viper-XML-Concepts_第3页
数据库教学课件:Viper-XML-Concepts_第4页
数据库教学课件:Viper-XML-Concepts_第5页
已阅读5页,还剩34页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

DB2ViperTechnology

XMLConceptsWorldwideInformationManagementTechnicalPresalesDisclaimer/TrademarksInformationconcerningnon-IBMproductswasobtainedfromthesuppliersofthoseproducts,theirpublishedannouncements,orotherpubliclyavailablesources.IBMhasnottestedthoseproductsandcannotconfirmtheaccuracyofperformance,compatibility,oranyotherclaimsrelatedtonon-IBMproducts.Questionsonthecapabilitiesofnon-IBMproductsshouldbeaddressedtothesuppliersofthoseproducts.AllstatementsregardingIBM'sfuturedirectionorintentaresubjecttochangeorwithdrawalwithoutnotice,andrepresentgoalsandobjectivesonly.Thisinformationmaycontainexamplesofdataandreportsusedindailybusinessoperations.Toillustratethemascompletelyaspossible,theexamplesincludethenamesofindividuals,companies,brands,andproducts.Allofthesenamesarefictitious,andanysimilaritytothenamesandaddressesusedbyanactualbusinessenterpriseisentirelycoincidental.TrademarksThefollowingtermsaretrademarksorregisteredtrademarksofothercompaniesandhavebeenusedinatleastoneofthepagesofthepresentation:ThefollowingtermsaretrademarksofInternationalBusinessMachinesCorporationintheUnitedStates,othercountries,orboth:AIX,AS/400,DataJoiner,DataPropagator,DB2,DB2Connect,DB2Extenders,DB2OLAPServer,DB2UniversalDatabase,DistributedRelationalDatabaseArchitecture,DRDA,eServer,IBM,IMS,iSeries,MVS,Net.Data,OS/390,OS/400,PowerPC,pSeries,RS/6000,SQL/400,SQL/DS,Tivoli,VisualAge,VM/ESA,VSE/ESA,WebSphere,z/OS,zSeriesMicrosoft,Windows,WindowsNT,andtheWindowslogoaretrademarksofMicrosoftCorporationintheUnitedStates,othercountries,orboth.

IntelandPentiumaretrademarksofIntelCorporationintheUnitedStates,othercountries,orboth.

UNIXisaregisteredtrademarkofTheOpenGroupintheUnitedStatesandothercountries.

JavaandallJava-basedtrademarksaretrademarksofSunMicrosystems,IheUnitedStates,othercountries,orboth.

Othercompany,product,orservicenamesmaybetrademarksorservicemarksofothers.XMLFeaturesinDB2ViperCanstore,indexandquery……well-formedXMLdocumentsonly…...handlesvalidandnon-validdocuments……withorwithoutnamespaces……supportsXPath2.0……butalsoXQuery&SQL/XML……supportsXMLSchemabutnoDTDvalidation……usesSAXinsteadofDOMparsing……andstillincludestheXSLTfunctionsfromV8.?Readyto“talkXML”?WhatisXML:eXtensible

MarkupLanguage<book><authors><authorid=“47”>JohnDoe</author><authorid=“58”>PeterPan</author></authors><title>Databasesystems</title><price>29</price><keywords><keyword>SQL</keyword><keyword>relational</keyword></keywords></book>XML:DescribesdataHTML:DescribesdisplayXMLis"self-describingdata"WhatisXML:eXtensibleMarkupLanguage<book><authors><authorid=“47”>JohnDoe</author><authorid=“58”>PeterPan</author></authors><title>Databasesystems</title><price>29</price><keywords><keyword>SQL</keyword><keyword>relational</keyword></keywords></book>StartTagDataEndTagElementAttributeXML:DescribesdataHTML:DescribesdisplayEndTagStartTagTheXMLDocumentTree<book><authors><authorid=“47”>JohnDoe</author><authorid=“58”>PeterPan</author></authors><title>Databasesystems</title><price>29</price><keywords><keyword>SQL</keyword><keyword>relational</keyword></keywords></book>XMLParsing

booktitlepriceauthorauthorsauthorkeywordskeywordkeywordid=47id=58SQLrelationalDatabase

Systems29JohnDoePeterPanSerializationAnswer1:eXtensible

MarkupLanguageAnswer2:Ahierarchicaldatamodel!Adatamodel,consistingofnodesofseveraltypeslinkedthroughorderedparent/childrelationshipstoformahierarchy.Onlyonerepresentationofthatdatamodelistextual,thereareothersthatarenottextWhatisXML?<book><authors><authorid=“47”>JohnDoe</author><authorid=“58”>PeterPan</author></authors><title>Databasesystems</title><price>29</price><keywords><keyword>SQL</keyword><keyword>relational</keyword></keywords></book>Text Tree TwodifferentrepresentationsofthesamehierarchicalXMLdata:Otherrepresentations:Eventstreams,BinaryXML,etc.booktitlepriceauthorauthorsauthorkeywordskeywordkeywordid=47id=58SQLrelationalDatabase

Systems29JohnDoePeterPan1XMLDocument-2Representations<a><b>bla</b></a><a><b>bla</a>Eachopeningtagismatchedbyaclosingtag<a>3<5</a><a>3<5</a>Doesnotusedisallowedcharactersintagsorvalues<aid=“15”></a><aid=15></a>Attributevaluesmustbequoted<a><b>bla</b></a><a><b>bla</a></b>Allelementsareproperlynested<a><b>bla</b><c>blub</c></a><b>bla</b><c>blub</c>HasexactlyonerootelementWell-formednotwell-formedWell-formedXMLDocumentsAnXMLdocumentiswell-formed,if:Note:xmlheader<?xmlversion=“1.0”?>isNOTrequiredforwellformedness.See/TR/REC-xmlforfulldefinition.“Well-formed”or“valid”?AnXMLdocumentiswell-formed,if……itcomplieswiththerulesonthepreviouspagei.e.itcanbeparsedbyanXMLparserwithouterrorAnXMLdocumentisvalid,if……itiswell-formedAND…itcomplieswithaspecificDTDorXMLSchemaXMLParserscanoptionallyperform“validation”DTDs(DocumentTypeDefinitions)andXMLSchemadefineaspecificXMLdocumentstructureXMLElementNodesvs.TextNodes<customerinfo>

<name>Matt

Foreman</name><phone>905-555-4789</phone></customerinfo>customerinfophonename905-555-4789MattForemanTextNodesElement

NodesNote:Onlyelementshavetextnodes.Attributesdon’t.Don’tputdataintagnames!Feweruniqueelementnamesisbetter.EasiertodefineDTDorXMLSchema.<customer_by_zipcode><95123><customerid=“1289”><name>Bob</name>(...)</customer>:<customerid=“2317”>(...)</customer></95123><95141><customerid=“4903”>(...)</customer>:</95141>(...)</customer_by_zipcode><customer_by_zipcode><zipcodevalue=“95123”><customerid=“1289”><name>Bob</name>(...)</customer>:<customerid=“2317”>(...)</customer></zipcode><zipcodevalue=“95141”><customerid=“4903”>(...)</customer>:</zipcode>(...)</customer_by_zipcode>Well-formed,butbadstyle!Problem:NameCollisionThreedifferentXMLelements:

<title>DatabaseAdministrator</title>

<title>Mr</title>

<title>Gonewiththewind</title>Sameelementname,butdifferentmeaning!Canresultinprocessing/applicationerrors.Needtodistinguishbetweendifferentdomains.Solution:NamespacesAprefixidentifiesthedomain(“namespace”),anddistinguishesbetweenduplicateelementnames <job:title>DatabaseAdministrator</job:title> <person:title>Mr</person:title> <movies:title>Gonewiththewind</movies:title>Namespacesneedtobeuniquelyidentified….->URIsURI=UniversalResourceIdentifierURIExamples:

/db2xml http://abcdefghijklmn.xyzURIsuniquelyidentifyanamespaceURIstypicallylooklikeaURLURIsarejustanidentifier,theymaytopointtoawebpage,butdon’thaveto!FormoredetailsonURIssee/rfc/rfc2396.txtNamespaceDeclarationandURIsExample:elementname:person

namespaceURI:http://

namespaceprefix:foo

<foo:person

xmlns:foo="http://"><foo:name>JohnDoe</foo:name><foo:person>Thenamespaceappliestothecurrentelementandallsub-elementsandattributesthatitcontains.Thereservedattribute“xmlns”definesnamespaces,and(optionally)assignsthemtoanamespaceprefixMultipleNamespaces<cust:person

xmlns:cust=“/customer”><cust:name>JohnDoe</cust:name><prod:productxmlns:prod=“/product”> <prod:name>ThinkpadT40</prod:name> <prod:orderdate>2004-11-18</prod:orderdate></prod:product></cust:person>Thenamespaceappliestothecurrentelementandallsub-elementsandattributesthatitcontains–unlessit’soverridden!Scopeofthenamespace“prod”DefaultNamespaces<personxmlns=“http://”><age>45</age><name> <first>John</first> <last>Doe</last></name></person>Anamespacedeclarationwithoutprefixdefinesadefaultnamespace.Thenamespaceisimplicitforallelements/attributesinscope,withoutusingaprefix.Thedefaultnamespaceappliestothecurrentelementandallsub-elementsandattributesthatitcontains.PathExpressionsProvidenavigationinXMLDocumentsthroughthefollowingAxes:Child /employee/nameDescendants //firstnameParent /employee/name/../ageAttribute /@idSelf /employee/.andothers…Optionalpredicate/employee[@id="1234"]<customerinfo><name>

JohnSmith

</name><addrcountry="Canada">

<street> Fourth

</street><city>

Calgary</city><prov-state>

Alberta</prov-state><pcode-zip>

M1T2A9</pcode-zip></addr><phonetype="Work">

963-289-4136</phone></customerinfo>BeginElement(customerinfo)BeginElement(name)ElementValue(JohnSmith)

EndElement(name)BeginElement(addr)Attribute(country,Canada)BeginElement(street)ElementValue(Fourth)EndElement(street)BeginElement(city)ElementValue(Calgary)EndElement(city)BeginElement(prov-state)ElementValue(Alberta)EndElement(prov-state)BeginElement(pcode-zip)ElementValue(M1T2A9)EndElement(pcode-zip)EndElement(addr)BeginElement(phone)Attribute(type,work)ElementValue(963-289-4136)EndElement(phone)EndElement(customerinfo)Text Tree EventsThreedifferentrepresentationsofthesamehierarchicalXMLdata:customerinfoaddrphonenamecountry=Canada963-289-4136JohnSmithType=Workstreetcityprov-statepcode-zipValueCalgaryAlbertaValueOneXMLDocument-3Representations

XPath:SimpleXPathExpressionsUsefullyqualifiedpathstospecifyelements/attributes“@”isusedtospecifyanattributeuse“text()”tospecifythetextnodeunderanelementXPathResult/dept/@bldg101/dept/employee/@id901902/dept/employee/name<name>JohnDoe</name><name>PeterPan</name>/dept/employee/name/text()JohnDoePeterPan<deptbldg=“101”><employeeid=“901”><name>JohnDoe</name><phone>4085551212</phone><office>344</office></employee><employeeid=“902”><name>PeterPan</name><phone>4085559918</phone><office>216</office></employee></dept>XPATH<customerinfo> <name> JohnSmith</name><addrcountry="Canada"> <street> Fourth</street><city> Calgary</city><prov-state> Alberta</prov-state><pcode-zip> M1T2A9</pcode-zip></addr><phonetype="Work"> 963-289-4136</phone><name>FredDoe</name><addrcountry="USA"><prov-state> Iowa</prov-state><pcode-zip> 98765</pcode-zip></addr><phonetype="Mobile"> 244-775-3151</phone></customerinfo>/customerinfo<customerinfo> <name> JohnSmith</name><addrcountry="Canada"> <street> Fourth</street><city> Calgary</city><prov-state> Alberta</prov-state><pcode-zip> M1T2A9</pcode-zip></addr><phonetype="Work"> 963-289-4136</phone><name>FredDoe</name><addrcountry="USA"><prov-state> Iowa</prov-state><pcode-zip> 98765</pcode-zip></addr><phonetype="Mobile"> 244-775-3151</phone></customerinfo>XPATH<customerinfo> <name> JohnSmith</name><addrcountry="Canada"> <street> Fourth</street><city> Calgary</city><prov-state> Alberta</prov-state><pcode-zip> M1T2A9</pcode-zip></addr><phonetype="Work"> 963-289-4136</phone><name>FredDoe</name><addrcountry="USA"><prov-state> Iowa</prov-state><pcode-zip> 98765</pcode-zip></addr><phonetype="Mobile"> 244-775-3151</phone></customerinfo>/customerinfo/name<customerinfo> <name> JohnSmith</name><addrcountry="Canada"> <street> Fourth</street><city> Calgary</city><prov-state> Alberta</prov-state><pcode-zip> M1T2A9</pcode-zip></addr><phonetype="Work"> 963-289-4136</phone>

<name>FredDoe</name><addrcountry="USA"><prov-state> Iowa</prov-state><pcode-zip> 98765</pcode-zip></addr><phonetype="Mobile"> 244-775-3151</phone></customerinfo><name> JohnSmith</name><name>FredDoe</name>XPATH<customerinfo> <name> JohnSmith</name><addrcountry="Canada"> <street> Fourth</street><city> Calgary</city><prov-state> Alberta</prov-state><pcode-zip> M1T2A9</pcode-zip></addr><phonetype="Work"> 963-289-4136</phone><name>FredDoe</name><addrcountry="USA"><prov-state> Iowa</prov-state><pcode-zip> 98765</pcode-zip></addr><phonetype="Mobile"> 244-775-3151</phone></customerinfo>/customerinfo/addr<customerinfo> <name> JohnSmith</name>

<addrcountry="Canada"> <street> Fourth</street><city> Calgary</city><prov-state> Alberta</prov-state><pcode-zip> M1T2A9</pcode-zip></addr><phonetype="Work"> 963-289-4136</phone><name>FredDoe</name>

<addrcountry="USA"><prov-state> Iowa</prov-state><pcode-zip> 98765</pcode-zip></addr><phonetype="Mobile"> 244-775-3151</phone></customerinfo><addrcountry="Canada"> <street>Fourth</street><city>Calgary</city><prov-state>Alberta</prov-state><pcode-zip>M1T2A9</pcode-zip></addr><addrcountry="USA"><prov-state>Iowa</prov-state><pcode-zip>987653</pcode-zip></addr>XPATH<customerinfo> <name> JohnSmith</name><addrcountry="Canada"> <street> Fourth</street><city> Calgary</city><prov-state> Alberta</prov-state><pcode-zip> M1T2A9</pcode-zip></addr><phonetype="Work"> 963-289-4136</phone><name>FredDoe</name><addrcountry="USA"><prov-state> Iowa</prov-state><pcode-zip> 98765</pcode-zip></addr><phonetype="Mobile"> 244-775-3151</phone></customerinfo>/customerinfo/addr/prov-state<customerinfo> <name> JohnSmith</name><addrcountry="Canada"> <street> Fourth</street><city> Calgary</city>

<prov-state> Alberta</prov-state><pcode-zip> M1T2A9</pcode-zip></addr><phonetype="Work"> 963-289-4136</phone><name>FredDoe</name><addrcountry="USA">

<prov-state> Iowa</prov-state><pcode-zip> 98765</pcode-zip></addr><phonetype="Mobile"> 244-775-3151</phone></customerinfo><prov-state> Alberta</prov-state><prov-state> Iowa</prov-state>XPath:Wildcards*matchesanytagname//isthe“descendent-or-self”wildcardXPathResult/dept/employee/*/text()JohnDoe4085551212344PeterPan4085559918216/dept/*/@id901902//name/text()JohnDoePeterPan/dept//phone<phone>4085551212</phone><phone>4085559918</phone><deptbldg=“101”><employeeid=“901”><name>JohnDoe</name><phone>4085551212</phone><office>344</office></employee><employeeid=“902”><name>PeterPan</name><phone>4085559918</phone><office>216</office></employee></dept>XPath:PredicatesPredicatesareenclosedinsquarebrackets[…]CanhavemultiplepredicatesinoneXpathPositionalpredicates:[n]selectsthen-thchildXPathResult/dept/employee[@id="902"]/name<name>PeterPan</name>/dept[@bldg="101"]/employee[office>"300"]/name<name>JohnDoe</name>//employee[office="344"ORoffice="216"]/@id901902/dept/employee[2]/@id902<deptbldg=“101”><employeeid=“901”><name>JohnDoe</name><phone>4085551212</phone><office>344</office></employee><employeeid=“902”><name>PeterPan</name><phone>4085559918</phone><office>216</office></employee></dept>XPATH<customerinfo> <name> JohnSmith</name><addrcountry="Canada"> <street> Fourth</street><city> Calgary</city><prov-state> Alberta</prov-state><pcode-zip> M1T2A9</pcode-zip></addr><phonetype="Work"> 963-289-4136</phone><name>FredDoe</name><addrcountry="USA"><prov-state> Iowa</prov-state><pcode-zip> 98765</pcode-zip></addr><phonetype="Mobile"> 244-775-3151</phone></customerinfo>/customerinfo/addr[@country="Canada"]/prov-state<customerinfo> <name> JohnSmith</name><addrcountry="Canada"> <street> Fourth</street><city> Calgary</city>

<prov-state> Alberta</prov-state>

<pcode-zip> M1T2A9</pcode-zip></addr><phonetype="Work"> 963-289-4136</phone><name>FredDoe</name><addrcountry="USA"><prov-state> Iowa</prov-state><pcode-zip> 98765</pcode-zip></addr><phonetype="Mobile"> 244-775-3151</phone></customerinfo><prov-state> Alberta</prov-state>XPath:TheParentAxisCurrentcontext:"."Parentcontext:".."XPathResult/dept/employee/name[../@id="902"]<name>PeterPan</name>/dept/employee/office[.>"300"]<office>344</office>/dept/employee[office>"300"]/office<office>344</office>/dept/employee[name="JohnDoe"]/../@bldg101/dept/employee/name[.="JohnDoe"]/../../@bldg101<deptbldg=“101”><employeeid=“901”><name>JohnDoe</name><phone>4085551212</phone><office>344</office></employee><employeeid=“902”><name>PeterPan</name><phone>4085559918</phone><office>216</office></employee></dept>XPATH<customerinfo> <name> JohnSmith</name><addrcountry="Canada"> <street> Fourth</street><city> Calgary</city><prov-state> Alberta</prov-state><pcode-zip> M1T2A9</pcode-zip></addr><phonetype="Work"> 963-289-4136</phone><name>FredDoe</name><addrcountry="USA"><prov-state> Iowa</prov-state><pcode-zip> 98765</pcode-zip></addr><phonetype="Mobile"> 244-775-3151</phone></customerinfo>/customerinfo/addr/city[.="Calgary"]/../@country<customerinfo> <name> JohnSmith</name><addrcountry="Canada"> <street> Fourth</street><city> Calgary</city><prov-state> Alberta</prov-state>

<pcode-zip> M1T2A9</pcode-zip></addr><phonetype="Work"> 963-289-4136</phone><name>FredDoe</name><addrcountry="USA"><prov-state> Iowa</prov-state><pcode-zip> 98765</pcode-zip></addr><phonetype="Mobile"> 244-775-3151</phone></customerinfo>CanadaXPATH<customerinfo> <name> JohnSmith</name><addrcountry="Canada"> <street> Fourth</street><city> Calgary</city><prov-state> Alberta</prov-state><pcode-zip> M1T2A9</pcode-zip></addr><phonetype="Work"> 963-289-4136</phone><name>FredDoe</name><addrcountry="USA"><prov-state> Iowa</prov-state><pcode-zip> 98765</pcode-zip></addr><phonetype="Mobile"> 244-775-3151</phone></customerinfo>/customerinfo/addr[prov-state="Iowa"]/@country<customerinfo> <name> JohnSmith</name><addrcountry="Canada"> <street> Fourth</street><city> Calgary</city><prov-state> Alberta</prov-state>

<pcode-zip> M1T2A9</pcode-zip></addr><phonetype="Work"> 963-289-4136</phone><name>FredDoe</name><addrcountry="USA"><prov-state> Iowa</prov-state><pcode-zip> 98765</pcode-zip></addr><phonetype="Mobile"> 244-775-3151</phone></customerinfo>USAXPATH<customerinfo> <name> JohnSmith</name><addrcountry="Canada"> <street> Fourth</street><city> Calgary</city><prov-state> Alberta</prov-state><pcode-zip> M1T2A9</pcode-zip></addr><phonetype="Work"> 963-289-4136</phone><name>FredDoe</name><addrcountry="USA"><prov-state> Iowa</prov-state><pcode-zip> 98765</pcode-zip></addr><phonetype="Mobile"> 244-775-3151</phone></customerinfo>/customerinfo//text()<customerinfo> <name>

JohnSmith</name><addrcountry="Canada"> <street>

Fourth</street><city>

Calgary</city><prov-state>

Alberta</prov-state><pcode-zip>

M1T2A9</pcode-zip></addr><phonetype="Work">

963-289-4136</phone><name>

FredDoe</name><addrcountry="USA"><prov-state>

Iowa</prov-state><pcode-zip>

98765</pcode-zip></addr><phonetype="Mobile">

244-775-3151</phone></customerinfo>JohnSmithFourthCalgaryAlbertaM1T2A9963-289-4136FredDoeIowa98765244-775-3151WhatisanXMLSchema?Definesstructure,content,datatypesforXMLdocumentsConsistsof1ormoreschemadocumentsAschemadocumentcandefineanamespace(optionally)Example:1XMLSchema,3SchemaDocuments,2Namespaces

order.xsd

Order

Lineitemlineitem.xsd

parts.xsd

import

include

Namespace:Namespace:Orderschema/TR/xmlschema-0/AdvantagesofXMLSchemaoverDTDsCandefinedatatypesforelements/attributesBasictypes:i

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论