XML - PowerPoint PPT Presentation

1 / 12
About This Presentation
Title:

XML

Description:

CGI Middleware can perform sophisticated processes on several data ... RESPONSE STATUS='WRONG' I guess you are not a Celtics Fan. / RESPONSE /QUESTION ... – PowerPoint PPT presentation

Number of Views:20
Avg rating:3.0/5.0
Slides: 13
Provided by: jian2
Category:
Tags: xml | celtics

less

Transcript and Presenter's Notes

Title: XML


1
XML
  • Introduction to XML
  • Document Type Definition (DTD)
  • XML Parser
  • Example CGI Gateway to XML Middleware

2
1. Introduction to XML
  • CGI Middleware can perform sophisticated
    processes on several data sources that itself
    becomes a data source. XML provides an industry
    standard way of describing data from different
    data sources. CGI programs that speak XML will be
    able to deliver to and retrieve data from any
    XML-compliant Perl script or Java applet.

3
Introduction to XML
  • HTML was deigned for the data presentation
    language (display the content for human to read),
    it lacks of the data description capability
    (cant interpret the data for machine to
    understand.)
  • Example ltBgtWhitelt/Bgt
  • XML was designed to make up many of HTMLs
    limitations. It is a data description language
    that is useful as a mechanism for transporting
    data from program to program on different
    platforms.
  • Example ltLastNamegtWhitelt/LastNamegt

4
XML Features
  • New tags and tag hierarchies can be defined to
    represent data specific to your application. For
    instance, a quiz can contain ltQUESTIONgt and
    ltANSWERgt tags.
  • Document type definitions can be defined for data
    validation. You can require, for instance, that
    every ltQUESTIONgt be associated with exactly one
    ltANSWERgt.
  • Data transport is Unicode-compliant, which is
    important for non-ASCII character sets.
  • Data is provided in a way that makes it easily
    transportable via HTTP.
  • Syntax is simple, allowing parsers to be simple.

5
Example
  • lt?xml version"1.0"?gt
  • lt!DOCTYPE quiz SYSTEM "quiz.dtd"gt
  • ltQUIZgt
  • ltQUESTION TYPE"Multiple"gt
  • ltASKgt All of the following players won the
    regular season MVP and playoff MVP in the same
    year, except for lt/ASKgt
  • ltCHOICE VALUE"A" TEXT"Larry Bird"/gt
  • ltCHOICE VALUE"B" TEXT"Jerry West"/gt
  • ltCHOICE VALUE"C" TEXT"Earvin Magic
    Johnson"/gt ltCHOICE VALUE"D" TEXT"Hakeem
    Olajuwon"/gt
  • ltCHOICE VALUE"E" TEXT"Michael
    Jordan"/gt
  • ltANSWERgtBlt/ANSWERgt
  • ltRESPONSE VALUE"B"gt West was awesome, but
    they did not have a playoff MVP in his day.
    lt/RESPONSEgt
  • ltRESPONSE STATUS"WRONG"gt How could you
    choose Bird, Magic, Michael, or Hakeem?
    lt/RESPONSEgt
  • lt/QUESTIONgt

6
Example (Cont.)
  • ltQUESTION TYPE"Text"gt
  • ltASKgt Who is the only NBA player to get a
    triple-double by halftime? lt/ASKgt
  • ltANSWERgtLarry Birdlt/ANSWERgt
  • ltRESPONSE VALUE"Larry Bird"gt You got it! He
    was quite awesome! lt/RESPONSEgt
  • ltRESPONSE VALUE"Magic Johnson"gt Sorry. Magic
    was just as awesome as Larry, but he never got a
    triple-double by halftime. lt/RESPONSEgt
  • ltRESPONSE STATUS"WRONG"gt I guess you are not a
    Celtics Fan. lt/RESPONSEgt
  • lt/QUESTIONgt
  • lt/QUIZgt

7
XML Document
  • All XML documents must present the data with at
    least one root structure surrounding the whole
    document.
  • XML accept all HTML tags, but it requires closed
    tag for all the tags.
  • XML parser converts the XML document into
    standard HTML. It uses the a dtd file to define
    how the XML document is structured and what the
    tags mean in relation to another
  • Example quiz.dtd (next page)
  • XSL (Extensible Style sheet Language) defines the
    standard stylesheet language for XML. It takes
    the original document tree and creates a new one
    based on the instructions that the developer
    provide.

8
2. Document Type Definition quiz.dtd
  • lt?xml version-"1.0"gt
  • lt!ELEMENT QUIZ (QUESTION)gt
  • lt!ELEMENT QUESTION (ASK,CHOICE,ANSWER,RESPONSE
    )gt
  • lt!ATTLIST QUESTION
  • TYPE CDATA REQUIREDgt
  • lt!ELEMENT ASK (PCDATA)gt
  • lt!ELEMENT CHOICE EMPTYgt
  • lt!ATTLIST CHOICE
  • VALUE CDATA REQUIRED
  • TEXT CDATA REQUIREDgt
  • lt!ELEMENT ANSWER (PCDATA)gt
  • lt!ELEMENT RESPONSE (PCDATA)gt
  • lt!ATTLIST RESPONSE
  • VALUE CDATA
  • STATUS CDATAgt

9
DTD
  • The DTD file is optional. XML document with the
    DTD file is called valid XML document. (without
    DTD is called well-formed document)
  • The lt!ELEMENTgt tags describe the actual tags that
    are valid in the XML document. The parentheses
    after the name of the element show what tags it
    can contain. The symbol is a quantity
    identifier. It follows the same basic rules as
    regular expression matching.
  • After each element is defined, its attributes
    need to be laid out.
  • Example Questions have a type attribute that
    takes a string of character data. Furthermore,
    the REQUIRED keyword indicates that this data is
    required in the XML document.

10
3. XML Parser
  • XML parsers parse data in two different ways.
  • To have the XML parser take the entire document
    and simply return a tree of objects that
    represents the XML document hierarchy. Perl
    supports this concept via the XMLGrove module.
  • (Similar with Java DOM (Document Object Model)
    API)
  • To parse XML documents is using a SAX (Simple API
    for XML) style of parser. This type of parser is
    event-based and is the one that XMLParser is
    based on. CGI Perl XMLParser is an interface to
    a library written in C called expat.
  • (Similar with Java SAX API)

11
4. Example CGI Gateway to XML Middleware
  • CGI gateway script parsing the XML from the
    Netscape Whats Related XML middleware server.

12
Example CGI Gateway to XML Middleware
  • User provides a URL whats_related.html
  • whats_related.cgi
  • get(http//www-rl.netscape.com/wtgn?, url)
    returns the directly related URL in a XML data
    document (without DTD).
  • XMLParser parse XML data document into a HTML
    document.
  • sub get_whats_related_to_whats_related will
    iterate through the directly related urls to get
    next level related urls.
Write a Comment
User Comments (0)
About PowerShow.com