• Keine Ergebnisse gefunden

A tt ri b ut e s o f X M L E le me nt s

N/A
N/A
Protected

Academic year: 2021

Aktie "A tt ri b ut e s o f X M L E le me nt s"

Copied!
8
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

W er kz eu ge de r In fo rma tik XM L - Ex te ns ib le M ar ku p La ng ua ge

Prof. Dr. Sven Hartmann TU Clausthal Institut für Informatik Lehrstuhl für Datenbanken und Informationssysteme

X M L D a ta

WerkzeugederInformatik:XML,WS2009/101

�Asemi-structureddatatuple(andapossiblevisualisationthroughawebbrowser): Employee NameJerry/Name PositionMouse/Position Emailjerry@turiteaConsulting.co.nz/Email Phones Phone3501111/Phone Phone3541112/Phone Phone2113333/Phone /Phones QualicationMasterofArts/Qualication Skills SkillHiding/Skill SkillRunning/Skill SkillTeasing/Skill /Skills Photogures/jerry.jpg/Photo /Employee

X M L Ele m e n ts

WerkzeugederInformatik:XML,WS2009/102

�XMLstandsforExtensibleMarkupLanguage, describingdatawithXMLissometimescalledXML-ification �Wehavechosenmarkuptagstospecifythelogicalstructureofthedata �thestaffdetailsofanemployeeconsistofaname,aposition,etc. �hencewehavechosenthecorrespondingtagstomarkuptherespectivedata items �Theessentialinformationisthetextbetweenthetags,whilethetagsrepresent meta-informationthathelpstounderstandthetext �AnypieceofXMLcodeiscalledanXMLfragment �however,therearecertainrulesforformingXMLcode �MarkuptagsusuallycomeinpairsandmarkupXMLelements,suchas �Skill�Hiding�/Skill� �herein,�Skill�isthestarttag,and�/Skill�theendtag �thetextinbetweenisthecontentoftheXMLelement

X M L Ele m e n ts

WerkzeugederInformatik:XML,WS2009/103

�ThecontentofanXMLelementmightbe �puretext �amixtureofpuretextandmarkup �furtherXMLelements �nothing �XMLelementsmaybenestedintooneanother,suchas Phones Phone3501111/Phone Phone3541112/Phone Phone2113333/Phone /Phones �AnXMLelementwithoutcontentiscalledanemptyXMLelement �inthiscase,weuseonlyasinglemarkuptag,suchas �Retired/�

(2)

A tt ri b ut e s o f X M L E le me nt s

WerkzeugederInformatik:XML,WS2009/104

�AnXMLelementmayhaveattributestocapturefurtherproperties �theyarestoredasattribute-valuepairsinthestarttag Employee NameJerry/Name PositionSince=2000Mouse/Position Emailjerry@turiteaConsulting.co.nz/Email Phones PhoneKind=work”3501111/Phone PhoneKind=work”3541112/Phone PhoneKind=mobile”2113333/Phone /Phones QualicationMasterofArts/Qualication Skills SkillHiding/Skill SkillRunning/Skill SkillTeasing/Skill /Skills Photogures/jerry.jpg/Photo /Employee

X M L D o c ume n ts

WerkzeugederInformatik:XML,WS2009/105

�XMLcodeisstoredinXMLdocuments �AnXMLdocumentconsistsofthreeparts: �itsXMLdeclaration �itsprocessinginstructions �itsrootelement �AnXMLdocumentmusthavearootelement,whileXMLdeclarationandthe processinginstructionsareoptional �Usually,theXMLdeclarationlooksasfollows: �?xmlversion=“1.0”encoding=”UTF-8”?� �itindicatestheversionofXMLbeingused,here1.0 �anditstatesinwhichencodingthedocumentiswritten �Theprocessinginstructionscouldbedeclarationsofstylesheets,etc. �Fortherootelement,justchooseanameandformitlikeanyotherXMLelement: �DB�...�/DB�

X M L D o c ume n ts

WerkzeugederInformatik:XML,WS2009/106

�AnXMLdocumentmustbewell-formed,thatis, �thereisexactlyonerootelement �startandendtagsmustmatch �startandendtagsmustnestproperly �ThefollowingXMLfragmentsarenotwell-formed: �apple��/pear� �apple��pear��/apple��/pear� �XMLiscase-sensitive(thisisdifferentfromHTML) �ThefollowingXMLfragmentisnotwell-formed: �Apple��/apple� �Infuture,wheneverwetalkaboutanXMLdocument,wemeanawell-formedone

X M L R e p o sit o ries

WerkzeugederInformatik:XML,WS2009/107

?xmlversion=1.0encoding=UTF-8? Employee NameJerry/Name PositionSince=2000Mouse/Position Emailjerry@turiteaConsulting.co.nz/Email Phones PhoneKind=work”3501111/Phone PhoneKind=work”3541112/Phone PhoneKind=mobile”2113333/Phone /Phones QualicationMasterofArts/Qualication Skills SkillHiding/Skill SkillRunning/Skill SkillTeasing/Skill /Skills Photogures/jerry.jpg/Photo /Employee

�StoretheXMLelementEmployeein anXMLdocument(jerry.xml) �Similarly,createanXMLdocument foreachstaffmember

(3)

X M L R e p o sit o ries

WerkzeugederInformatik:XML,WS2009/108

?xmlversion=1.0encoding=UTF-8? Employee NameTom/Name PositionSince=2000Cat/Position Emailtom@turiteaConsulting.co.nz/Email Phones PhoneKind=work”3502222/Phone PhoneKind=home”3542222/Phone /Phones Skills SkillConstructingmousetraps/Skill SkillEating/Skill /Skills Photogures/tom.gif/Photo /Employee �AnXMLrepositoryisacollectionofXMLdocuments(thataresomehowrelated)

De sc ribing Da ta T y p es

WerkzeugederInformatik:XML,WS2009/109

�Weobserve: �therearelotsofemployeeshavingdifferentstaffdetails,butinallcasesthe structureoftheirstaffdetailslookssimilar �classificationabstractionmeanstodescribethecommonstructure �weaimtodescribethecommondatatype(asfaraspossible) �then,thisdatatypecanserveasaschemafortheXMLdatatuples,whichwill beinstancesofthedatatype �AfteranalysingthestructureoftheEmployeeelements,wedeclare: �ELEMENTEmployee(Name,Position,Email,Phones,Qualification,Skills,Photo) �thismayserveasacommondatamodelforallstaff �Weobserve: �thisisacomplexdatatype,sowealsoneedtodeclaredatatypesforNames, Positions,etc. �Qualificationisonlyoptional,soweneedtoindicatethis

X M L Ele m e n t De c la ra tio ns

WerkzeugederInformatik:XML,WS2009/1010

�Anelementdeclarationhasthegeneralform: �ELEMENTelement­namecontent­model �Theelementnameisthenameinsidethestartandendtag �itmustbeavalidXMLname,thatis, �startwithanalphabeticalcharacteroranunderscore �butnotwiththestring“xml” �itmaycontainanyalphanumericalcharacteroror-or. �butnoblanks,noreservedsymbolssuchas�or�or&or” �Thecontentmodelspecifieswhatmayoccurbetweenthestartandendtag: �puretext �anything(anymixtureofpuretextandmarkup) �furtherXMLelements �nothing

X M L Ele men t De c la ra tio n

WerkzeugederInformatik:XML,WS2009/1011

�Weuse�ELEMENTelement­name(#PCDATA)ifthecontentispuretext ��PCD�T�standsforparsed,orbetter,parsablecharacterdata �Weuse�ELEMENTelement­nameANYifthecontentmaybeanything �thisisveryconvenient,butnotveryinformative... �Weuse�ELEMENTelement­nameEMPTYifthereisnocontent �butwait,tillwecanaddattributes... �Weuse�ELEMENTelement­namechild­elementsifthecontentarefurther XMLelements �theseelementsarereferredtoaschildelementsorchildren �asanexample,werecallourdatatypeforthestaffdetails: �ELEMENTEmployee(Name,Position,Email,Phones,Qualification,Skills,Photo)

(4)

De c la ri n g C h il d E le me nts

WerkzeugederInformatik:XML,WS2009/1012

�Recall,thatweneedtoindicatethatQualificationisanoptionalchild �Weuseregularexpressionstodescribethepermittedcombinationsofchildelements �ELEMENTelement­namereg­expression �Regularexpressionscanbebuildasfollows: �startwith�PCD�T�,EMPTYoranyvalidXMLnames �formsequences �formalterations �indicateoptionality �indicateiteration �indicatenon-emptyiteration �addbraces �Inpractise,theregularexpressionsusedforXMLelementsareoftenrathersimple

De c la ri n g C h il d E le me nts

WerkzeugederInformatik:XML,WS2009/1013

�Herearesomeeasy-to-followrulesofthumb: �Todescribeasequenceofelementsoftypeschild,...,child,use �ELEMENTelement-name(child,...,child) �Todescribethealternativeofelementsoftypeschild,...,child,use �ELEMENTelement-name(child···child) �Toindicateanoption,attacha?tooneormorechildelements �suchanelementmayormaynotappear �Toindicateaniteration,attacha�tooneormorechildelements �suchanelementmayoccurafinitenumberoftimes(ornotatall) �Toindicateanon-emptyiteration,attacha+tooneormorechildelements �suchanelementmayoccuranon-zero,finitenumberoftimes

Our E x a mp le

WerkzeugederInformatik:XML,WS2009/1014

�WeindicatethatQualificationisonlyoptional: �ELEMENTEmployee(Name,Position,Email,Phones,Qualification?,Skills,Photo) �WedeclaredatatypesforthechildelementsNames,Positions,etc. �ELEMENTName(#PCDATA) �ELEMENTPosition(#PCDATA) �ELEMENTEmail(#PCDATA) �ELEMENTPhones(Phone) �ELEMENTQualification(#PCDATA) �ELEMENTSkills(Skill ) �ELEMENTPhoto(#PCDATA) �WedeclaredatatypesforthegrandchildelementsPhoneandSkill �ELEMENTPhone(#PCDATA) �ELEMENTSkill(#PCDATA)

Our E x a mp le

WerkzeugederInformatik:XML,WS2009/1015

�Wecheckthesuitabilityofthedatatype: Employee NameTom/Name PositionSince=2000Cat/Position Emailtom@turiteaConsulting.co.nz/Email Phones PhoneKind=work”3502222/Phone PhoneKind=home”3542222/Phone /Phones Skills SkillConstructingmousetraps/Skill SkillEating/Skill /Skills Photogures/tom.gif/Photo /Employee

�ELEMENTEmployee(Name,Position,Email, Phones,Qualication?,Skills,Photo) �ELEMENTName(#PCDT) �ELEMENTPosition(#PCDT) �ELEMENTEmail(#PCDT) �ELEMENTPhones(Phone) �ELEMENTPhone(#PCDT) �ELEMENTQualication(#PCDT) �ELEMENTSkills(Skill) �ELEMENTSkill(#PCDT) �ELEMENTPhoto(#PCDT)

(5)

A tt ri b ut e D e c la ra ti o n

WerkzeugederInformatik:XML,WS2009/1016

�XMLelementscanhaveattributestocaptureparticularpropertiesofthese elements,suchas �ATTLISTPositionSinceCDATA#REQUIRED �Anattributedeclarationhasthegeneralform: �ATTLISTelement­nameattribute­specifications �theelementnamespecifiestheelementwhoseattributeswewanttodeclare �thelistofattributespecificationscontainsexactlyoneforeachattribute, eachattributespecificationhastheform attribute­nameattribute­typeattribute­constraint �theattributenameisthenamechosenforthisattribute �theattributenamemustbeavalidXMLname(asexplainedabove) �naturally,anytwoattributesofthesameelementshouldhavedistinctnames

A tt ri b ut e D e c la ra ti o n

WerkzeugederInformatik:XML,WS2009/1017

�Therearethreekindsofattributevalues:strings,enumerated,andtokens �Strings:theattribute’svalueisacharacterstring �weusethesimpledatatypeCD�T� �blanksareallowed �anytextisallowedexceptforreservedsymbols �Enumerated:theattribute’svaluemustbechosenfromauser-specifiedlist �ELEMENTCarEMPTY �ATTLISTCarMakeCDATA#REQUIRED ColourCDATA#REQUIRED New(yesno)#REQUIRED �Tokens:theattribute’svalueisaspecial-purposecharacterstring �NMTOKENcanbeusedforavalidXMLname �ENTITYcanbeusedforareferencetoanexternalfile �ID,IDREFandIDREFSareexplainedlateron

A tt ri b ut e D e c la ra ti o n

WerkzeugederInformatik:XML,WS2009/1018

�Theattributeconstraintisoneof ��REQUIREDiftheattributemustoccurineveryelement ��IMPLIEDiftheattributeisoptional �adefaultvaluefortheattribute ��FIXEDvalue ��CURRENTiftheattributetakesthevaluemostrecentlyassignedtothisattribute �Forourexample �wecansimplychoose: �ATTLISTPositionSinceCDATA#REQUIRED �ATTLISTPhoneKindCDATA#IMPLIED �thus,Sinceisacompulsoryattribute,andKindisanoptionalattribute �alternativelywecouldalsochoose: �ATTLISTPhoneKind(workhomemobile)#IMPLIED

Our E x a mp le

WerkzeugederInformatik:XML,WS2009/1019

�Wecheckthesuitabilityofthedatatypeagain: Employee NameTom/Name PositionSince=2000Cat/Position Emailtom@turiteaConsulting.co.nz/Email Phones PhoneKind=work”3502222/Phone PhoneKind=home”3542222/Phone /Phones Skills SkillConstructingmousetraps/Skill SkillEating/Skill /Skills Photogures/tom.gif/Photo /Employee

�ELEMENTEmployee(Name,Position,Email, Phones,Qualication?,Skills,Photo) �ELEMENTName(#PCDT) �ELEMENTPosition(#PCDT) �ATTLISTPositionSinceCDT#REQUIRED �ELEMENTEmail(#PCDT) �ELEMENTPhones(Phone) �ELEMENTPhone(#PCDT) �ATTLISTPhoneKindCDT#IMPLIED �ELEMENTQualication(#PCDT) �ELEMENTSkills(Skill) �ELEMENTSkill(#PCDT) �ELEMENTPhoto(#PCDT)

Referenzen