feb 2001c.watters1 grammars, sgml, & xml agreeing on the rules

Download Feb 2001C.Watters1 Grammars, SGML, & XML Agreeing on the rules

Post on 18-Jan-2016

216 views

Category:

Documents

0 download

Embed Size (px)

TRANSCRIPT

  • Grammars, SGML, & XMLAgreeing on the rules

    C.Watters

  • OverviewWhat is a grammarBNF notationRegular expressionsContext free grammars (remember Chomsky)SGMLHTMLXML (finally) and the DTD

    C.Watters

  • What is a Grammar?A grammar is a set of rules which cangenerate a construct from a list of terminalsdetermine if a construct obeys the rules(i.e. is well formed)

    Example - Englishconstruct is a sentence terminals are words

    C.Watters

  • Simple GrammarSentence::= Subject Verb

    Subject::=(Pnoun | (def noun))Pnoun::=(Joe | Mary)Verb::=(runs | sits)def::=(the | a | an)noun::=(boy | girl)

    C.Watters

  • Syntax not SemanticsLets expand definition of noun terminalsNoun::=(car | hat | TV) no problem with syntax!Hat running a little vague.They are flying planes.No problem with syntax.Semantics not so clear

    C.Watters

  • What is a grammar for anyway?

    1. Parse InputExamines input and determines if it satisfies the rules of a given grammarJoe Mary.If(a

  • BNFBackus Naur (or Normal) FormNotation for describing syntax of a languageJohn Backus and Peter Naur, 1960s for ALGOLMeta-symbols used ::= LHS is defined by RHS | or < > category name (defined somewhere else)Example::= begin end;

    C.Watters

  • Useful extensions to BNFOptional [else ]repetitive items { | }recursion is allowed ::= | brackets for grouping ( | )

    C.Watters

  • Regular ExpressionsSimple way to express languages or stringseg. One a followed by (one n followed by one d) or by one t

    a((n d) | t)

    note: may use + instead of |

    C.Watters

  • Regular Expressions includeConcatenation\sequence A BSelection A|BKleene Closure (0 or more) A*Positive Closure(1 or more) A+Bounded Repetition(1 to i) Aieg. A(n*| t) = {A, An, Ann, , At}

    C.Watters

  • Context-Free GrammarsCFG is a set of recursive productions used to generate patterns of strings satisfying the construct of the language

    SGML and its subsets, HTML and XML are context-free grammars!CFG are more powerful than Regular Expressions

    C.Watters

  • SGMLStandardized General Markup LanguageDeveloped by a committee!Led by Charles Goldfarb, 1978-1986a grammar to define the structure of documents

    rules define the construct or structureterminals are and strings

    C.Watters

  • XMLDTDsHow to use itExamples

    C.Watters

  • DTD - grammar definition for a document typeDefines:element types (structure)attributes (terminals)constraints on combinations of these

    C.Watters

  • Element Type Declaration

    ]>

    todaymyhouseRain or shine

    C.Watters

  • Sub-Elements

    ? Means optional 1 or more 0 or more

    where Graphic etc are also defined as ELEMENTS

    C.Watters

  • AttributesLet you add extra information to elements

    CDATA=> character data

    C.Watters

  • Validating ParserA DTD (document type definition) defines the grammar of a type of documentmemoweb pagebookValidating Parser uses a DTDto check if a given document satisfies the rules of that grammar

    C.Watters

  • HTML & XMLHTML is a subset of SGML with a shared DTDHTMLDOC::=( HEAD BODY )XML is a subset of SGML with many DTDs allowed

    XML is like HTML with the training wheels off -Dan Connolly, leader of XML activity at W3C

    C.Watters

  • XMLUses tags to identify semantics of datalooks like HTML, but isntIntroduction CarolynWatters XML this and that

    is license free, platform-independent and well-supported

    C.Watters

  • HTMLHypertext Markup Language

    Hypertext Markup LanguagePresents documents via WWW browsersDocument layout and hyperlink specificationsPredefined set of tags (ie. Common DTD)

    C.Watters

  • Statistics Canada

    Welcome to Stats CanadaStatistics Canada . . We like numbers..

    What we doCensusSpecial surveysa href=online.html>Online data

    C.Watters

  • HTMLHTML - AdvantagesSimple - fixed set of tagsPortable - used with all browsersLinking - within and to external documents

    HTML - DisadvantagesLimited tag setCant separate the definition from contentCant define structure of contents

    C.Watters

  • XML

    XML allows anyone to define a document structure separate from its display structure

    Explicit Definition - DTD

    C.Watters

  • Some CodeSchemaEntityPassport DetailsSubEntitiesLast NameFirst NameAddress

    EntityAddressSubEntitiesStreetCityTownStateProvince..

    C.Watters

  • DTD

    C.Watters

  • Internal DTD and Instance

    ]>

    SmithJoStephen1 Great StreetGreatCityGreatState1234GreatLandjo@theworldaccordingtojo.com

    C.Watters

  • Shared DTDXML Document specifies the DTD

    SmithJoStephen1 Great StreetGreatCityGreatState1234GreatLandjo@theworldaccordingtojo.com

    C.Watters

  • Importance of XMLCoordinating Heterogenous DatabasesSeparation of Structure / Content / DisplayDocument Validity CheckingPotential Use in Standards

    C.Watters

  • Example

    Boeing

    Boeing places a DTD on its sitepart purchasers use this DTD Boeing can use multiple XSL stylesheets

    C.Watters

  • Boeing (contd)customer creates an order document, they can verify the validity of that document against the DTD.this ensures they are transmitting only type-valid orders.in turn, Boeing can ensure they are receiving only type-valid documents.

    C.Watters

  • 2. Using XML: DOM & SAXDOM: Document Object ModelThe DOM is a standard object application programming interface that gives developers programmatic control of XML document content, structure, formats, and more. DOM defines a programmatic API for accessing XML documents.

    C.Watters

  • 3. Using XML: presenting dataNeed to convert XML tags into appropriate HTML tags for use in a browser!!

    Smith

    Smith Smith

    C.Watters

  • Stylesheets are used to present XML: The Cascading Stylesheet Specification (CSS) The Extensible Style Language (XSL)

    CSSXSLCan be used with HTML?YesNoCan be used with XML? YesYesTransformation language?NoYesSyntaxCSSXML

    C.Watters

  • CSS and XSLCSS - Cascading Style Sheetscan predefined HTML display (font etc)these are shared and reused

    XSL - XML Style languagepredefine display characteristics for XML entitiestransform into CSS for browsers to use

    C.Watters

  • Cascading Style SheetsCSSlast_name{font-family: verdana, arial;font-size: 15pt;font-weight:bold;display: block;margin-bottom: 5pt;}first_name{font-family: verdana, arial;font-size: 15pt;font-weight:bold;display: block;margin-bottom: 5pt;}

    street, city, town, state, province, ZIP, postal_code{font-family: verdana, arial;font-size: 12pt;font-weight:bold;color:green;display:block;margin-bottom: 20pt;margin-top: 40pt;}email{font-family: verdana, arial;font-size: 12pt;font-weight:bold;color:blue;display:block;margin-top: 5pt;}

    C.Watters

  • CSS Most local definition has precidenceMay be referred to (shared)

    C.Watters

  • XSL (Style Language)

    Address

    C.Watters

  • Understanding A TemplateMost templates have the following form:

    The whole element is a templateThe match pattern determines where this template appliesLiteral result elements come from non-XSL namespace(s)XSLT elements come from the XSL namespace

    C.Watters

  • Options for displaying XMLXMLDocumentCSSStylesheetXSLStylesheetXML enabledWeb BroswerXML DisplayEngineXSLTransformationspecHTMLDocumentWeb BroswerXSLTransformation

    C.Watters

  • 2. Using XML:How does browser read XML ?XML parser: A tool for reading XML documentsMicrosoft's Internet Explorer 4.0 was the first Web browser to implement XMLNetscape will support XML metadata in Communicator/Navigator 5.0 as a delivery component code-named Aurora.

    C.Watters

  • DesktopMiddle - TierStorageDisplayMultiple view created from the XML-base dataData Delivery,Manipulation:XML exchanged over HTTP manipulated via the DOMData IntegrationXML emitted or generated from multiple sourceXML delivered to other applications or objects for further processingHTML view #1(eg.Purchasing Agent)HTML view #2(eg.Consumer)Web ServerDB Access, IntegrationBusiness Rules(eg. Purchase order)MainframeDatabaseXML Architecture

    C.Watters

  • 4. Case StudyAn example of XMLTree structureA simply example: Portfolio.xmlPortfolio.xslhttp://msdn.microsoft.com/xml/samples/review/review-xsl.xml

    C.Watters

  • storyaddresslogonamephonedatereviewerpersonsummarypersonbooksoffice suppliesTree Structure of the example

    C.Watters

  • C.Watters

  • Is this for real?In the major Web Browser products.In Microsoft Office 2000.In every major database tool by end of 2000.In every HTML tool by end of 2000.CommerceNet believes that XML may just be the killer application needed to open up the Worldwide Web for Electronic Commerce.

    C.Watters

  • SummaryXML - AdvantagesPlatform and system independentUser-defined tagsDoesnt require explicit DTDDisplay format and content are separateXML - DisadvantagesRequires a processing applicationPickier than HTMLMust be converted to HTML to view in browser

    C.Watters

  • Resources

    W3 Consortium: www.w3.com

    kazillions of XML books in every bookstore!

    C.Watters

  • 6. ReferenceJon Bosak and Tim Bray, Scientific American, May 1999 [http://www.sciam.com