170 likes | 320 Views
eXtensible Markup Language (XML). 1. XML. O pen C omputing I nstitute, Inc. What is XML? • eXtensible Markup Language • Subset of SGML (Standardized General Markup Language) – marks up content, not formatting, just like SGML – omits complex features • Formatting is done with
E N D
eXtensibleMarkupLanguage (XML) 1 XML OpenComputingInstitute,Inc.
WhatisXML? •eXtensibleMarkupLanguage •SubsetofSGML(StandardizedGeneralMarkupLanguage) –marksupcontent,notformatting,justlikeSGML –omitscomplexfeatures •Formattingisdonewith –CascadingStyleSheets(CSS) –eXtensibleStyleLanguage(XSL) •RelationshiptoHTML –canexpresstherulesforHTMLinan XMLDocumentTypeDefinition(DTD) –HTMLdocumentscanbeXMLdocuments •haveasinglerootelement(<html>) •closealltags •encloseattributevaluesinquotes 2 XML OpenComputingInstitute,Inc.
SomeBenefitsofUsingXML •XMLdocumentsareself-describing –notjustacollectionofdatavalues •CanusestandardXMLtools(&someSGMLtools) tocreate,modify,processandview –XMLeditors –SAXandDOMprogramminginterfaces –XML-awarebrowsers •CanuseaDTDtoconstrainstructureandallowedvalues •CanuseXSLtoreadexistingXMLdocuments andcreatenewoneswithadifferentstructure –whenneedschange –whenotherapplicationsexpectthedatatobestructureddifferently •Errorsindatadon’tpreventuseofotherdocumentdata aslongasitisstillwell-formed 3 XML OpenComputingInstitute,Inc.
SomeDesignGoalsForXML •CompatiblewithSGML –takeadvantageofexistingexpertiseandsomeexistingtools •Optionalelementskepttoaminimum –comparisonofspec.sizes:SGML~500pages,XML~30pages •Human-readable,likeHTML •Easytocreatedocuments •Tersenessofmarkupisoflittleimportance –elementandattributenamestakeupalotofspace butcompresseswell(~90%) •Supportavarietyofapplications,notjustwebbrowsers •EasytowriteapplicationsthatprocessXMLdocuments –canuseSAXandDOMinterfaces 4 XML OpenComputingInstitute,Inc.
CustomMarkupLanguages •XMLisusedtocreatemarkuplanguages forspecificapplications •Examples –ChemicalMarkupLanguage(CML) •fordisplayingmoleculedescriptionsandtreesandmodeldiagrams – – – – – FDX-forfootwearindustrydata FpMLandFinXML-forsecuritiestradingdata HL7-forhealthcaredata MathML-formathematicalequations OpenFinancialeXchange(OFX) •forpersonalfinancialdatalikethatstoredinQuickenorMoney •alsosupportsconsumerandsmallbusinessbankingandbillpayment –OpenSoftwareDistribution(OSD) •forsoftwaredistributionandupdates 5 XML OpenComputingInstitute,Inc.
CategorizingThePieces • • • • • Basics: Validating: Links: Formatting: Programming: XML DTDandXMLSchema XLinkandXPointer CSSandXSL SAXandDOM 6 XML OpenComputingInstitute,Inc.
XMLElements(ortags) •Mustbesurroundedby<and>characters •Mustbeterminatedinoneoftwoways <city/> <city>contentgoeshere</city> •Canincludeattributes <cityname="St.Louis"state="Missouri"/> •Cancontainchildelements <city> <name>St.Louis</name> <state>Missouri</state> </city> •Childelementsmustbeproperlynested –proper: –improper: <a><b></b></a> <a><b></a></b> 7 XML OpenComputingInstitute,Inc.
ExampleXMLDocument <?xmlversion="1.0"?>XMLdeclaration <!DOCTYPEmusicCollectionSYSTEM"musicCollection.dtd"> rootelement <musicCollection> prolog section documenttype declaration <owner>MarkVolkmann</owner> <artisttype="group"> <name>Cranberries</name> <cdcategory="pop"> <title>EverybodyElseIsDoingIt,SoWhyCan'tWe?</title> <track> <name>IStillDo</name> <time>3:16</time> </track> <track> <name>Dreams</name> <time>4:32</time> </track> </cd> </artist> anXMLcomment <!--placemoreartistshere--> </musicCollection> 8 XML OpenComputingInstitute,Inc.
Well-formed&ValidXMLDocuments •Well-formeddocuments –allelementsareterminated –oneelement,therootelement,containsalltheothers –elementsdonotoverlap •childelementsmustbeclosedbeforetheirparentisclosed –attributevaluesareenclosedinquotes –<isonlyusedtostartelements –alsoafewrulesaboutentities •entitiesareshorthandnamesforreplacementtext •entitiescanalsorefertonon-XMLdata •Validdocuments –well-formed –conformtoaDTD 9 XML OpenComputingInstitute,Inc.
DocumentTypeDefinitions(DTD) •ADTDdefines – – – – – allowedelementsandtheirattributes validelementnestingrelationships sequenceinwhichelementsmustappearwithintheirparentelement numberoftimeselementscanoccurwithintheirparentelement andmore •Onlyneededfor“valid”documents, notformerely“well-formed”documents •DTDsformanyapplicationdomainsalreadyexist •FourDTDtypes –ELEMENT,ATTLIST,ENTITYandNOTATION identifiestheapplicationtobeused forprocessingdatainagivenformat 10 XML OpenComputingInstitute,Inc.
ElementDefinitions •Fourtypesofelementdefinitions ParsedCharacterData –nocontent-EMPTY –onlytextcontent,nochildelements-(#PCDATA) –onlychildelements,notextcontent-requiresacontentmodel –anycontent-ANY •Elementcontentmodels –typicallyasequenceofchildelementsseparatedbycommas –specialcharactersindicatethenumberofoccurrencesallowed •?means0or1,*means0ormore,+means1ormore,defaultis1 –example:(a*,b+,c?,(d|e)) •specifies0ormoreaelements,followedbyoneormorebelements, followedby0or1celements,followedbyonedoreelement 11 XML OpenComputingInstitute,Inc.
Attributes •Tentypesofattributedefinitions –enumerated-listofallowedvalues;example:(red|green|blue) –CDATA-anycharacters –NMTOKEN-onlycharactersallowedin“nametokens” •letters,digits,underscore,hyphen,periodandcolon;beginwithaletter NMTOKENS-awhitespace-separatedlistofNMTOKENvalues ID-uniqueidentifierfortheelementwithintheXMLdocument IDREF-referstoanotherelementwithinthesameXMLdocument IDREFS-awhitespace-separatedlistofIDREFvalues ENTITY-referstoanunparsedexternalentitysuchasanimagefile ENTITIES-awhitespace-separatedlistofENTITYvalues NOTATION-identifiesthedataformatofanunparsedexternalentity – – – – – – – •Attributescanberequired(#REQUIRED), optional(#IMPLIED)orhavedefaultvalues 12 XML OpenComputingInstitute,Inc.
ExampleDTD <!ELEMENT <!ELEMENT <!ELEMENT <!ELEMENT <!ELEMENT <!ELEMENT <!ELEMENT <!ELEMENT musicCollection(owner,artist*)> artist(name,cd*)> cd(title,track*)> track(name,time?)> name(#PCDATA)> owner(#PCDATA)> time(#PCDATA)> title(#PCDATA)> <!ATTLISTartisttype(group|solo)#REQUIRED> <!ATTLISTcd category(classical|country|jazz|pop|rock|other)#REQUIRED import(true|false)"false" yearCDATA#IMPLIED > <!ATTLISTtracksampleFileENTITY#IMPLIED> 13 XML OpenComputingInstitute,Inc.
XMLSchema •W3CproposedschemalanguagealternativetoDTDs –asupersetoftheDTDcapabilities –combinesthebestfeaturesofothersimilarproposals •XML-Data,XDR,DCD,SOX,DDML –usesXMLsyntaxinsteadofauniquesyntaxlikeDTDs •canedit,validate,andtransformusingstandardXMLtools •CreatedbytheW3CXMLSchemaWorkingGroup –seeXMLSchemaPart1:StructuresW3CWorkingDraft6-May-1999 andXMLSchemaPart2:DatatypesW3CWorkingDraft6-May-1999 14 XML OpenComputingInstitute,Inc.
XMLSchema(Cont’d) •SomeXMLSchemaimprovementsoverDTDs –built-indatatypes •string,boolean,number,dateTime,binary(ex.imagedata),uri •integer,decimal,real,date,time,timePeriod –user-generateddatatypes(built-indatatypeswith“constrainingfacets”) •stringsupportslength(forfixed-length),maxlength(forvariable-length), andCOBOL-likepicturesorPerl-likeregularexpressionstoconstrainformat •numbersupports minInclusive,minExclusive,maxInclusiveandmaxExclusive –integer,decimalandrealareallnumbers –limitsonnumberofoccurrencesofchildelements •minOccurcanbesettoanumber(0ormore) •maxOccurcanbesettoanumber(1ormore)or"*"forunlimited 15 XML OpenComputingInstitute,Inc.
XLink •ProvidesgreaterlinkingcapabilitiesthanHTML •Anyelementcanserveasalink –nospecialelement,justspecialattributes •Features –simplelinks •unidirectionallinktoasingleresource(likeHTMLlinks) –extendedlinks •bi-directionallinktooneormoreresources •canbedefinedinaseparatefiletoallowmultiplefilestosharethelink –activatewith“user”(userclick)or“auto”(whenpageisloaded) –showwith“replace”(replacecurrentpage), “new”(displayinanewwindow)or “embed”(embedintocurrentpage) –custombehaviorswhenlinkisactivated(ex.soundsandtransitioneffects) 16 XML OpenComputingInstitute,Inc.
eXtensibleMarkupLanguage (XML) -- END -- 1 XML OpenComputingInstitute,Inc.