Introduction to XML - PowerPoint PPT Presentation

1 / 17
About This Presentation
Title:

Introduction to XML

Description:

html body bgcolor='yellow' h1 References Data Internal Note /h1 xsl:for-each select='note' ... body table border='2' bgcolor='yellow' tr th Title ... – PowerPoint PPT presentation

Number of Views:18
Avg rating:3.0/5.0
Slides: 18
Provided by: eshaamal
Category:

less

Transcript and Presenter's Notes

Title: Introduction to XML


1
Introduction toXML
? Dr. Eshaa M. Alkhalifa
2
Predefined tags vs Your tag names
  • XHTML example
  • ltHTMLgt ltH1 ID"MN"gtStatelt/H1gt ltH2
    ID"12"gtCitylt/H2gt ltDLgt ltDTgtNamelt/DTgt
    ltDDgtJohnsonlt/DDgt ltDTgtPopulationlt/DTgt
    ltDDgt5000lt/DDgt lt/DLgt ltH2 ID"15"gtCitylt/H2gt ltDLgt
    ltDTgtNamelt/DTgt ltDDgtPinevillelt/DDgt
    ltDTgtPopulationlt/DTgt ltDDgt60000lt/DDgt lt/DLgt ltH2
    ID"20"gtCitylt/H2gt ltDLgt ltDTgtNamelt/DTgt ltDDgtLake
    Belllt/DDgt ltDTgtPopulationlt/DTgt ltDDgt20lt/DDgt lt/DLgt
    lt/HTMLgt
  • XML example
  • lt?XML VERSION"1.0" STANDALONE"yes" ?gt ltSTATE
    STATEID"MN"gt ltCITY CITYID"12"gt
    ltNAMEgtJohnsonlt/namegt ltPOPULATIONgt5000lt/POPULATIONgt
    lt/CITYgt ltCITY CITYID"15"gt ltNAMEgtPinevillelt/NAMEgt
    ltPOPULATIONgt60000lt/POPULATIONgt lt/CITYgt ltCITY
    CITYID"20"gt ltNAMEgtLake Belllt/NAMEgt
    ltPOPULATIONgt20lt/POPULATIONgt lt/CITYgt lt/STATEgt

3
eXtensible Markup Language?
  • Last edition is defined here http//www.w3.org/TR/
    2006/REC-xml11-20060816/
  • XML
  • Describes what the data IS
  • Displaying it directly will only show the
    structure of the data
  • HTML
  • Describes how a page looks
  • Can be displayed directly onto a browser

4
Future of the Internet?
  • Yes and No
  • Yes because it makes it easier to maintain large
    sites and pages.
  • No because it will not replace HTML or will it?

5
How is XML really different?
XML Alone XML Using XSL
6
What Does this mean?
  • You write two files
  • XML file to hold your data alone, and you set the
    structure of the file.
  • XSL file to hold the structure of how your data
    is displayed.
  • This means you can alter, add, delete parts of
    the displayed page without having to alter the
    way the page looks.
  • E.g. pages with news

7
XML File
  • An XML file may look like this
  • lt?xml version"1.0" encoding"ISO8859-1" ?gt
  • lt?xml-stylesheet type"text/xsl"
    href"testxsl.xsl"?gt
  • ltnotegt
  • ltTOgtTovelt/TOgt
  • ltfromgtJanilt/fromgt
  • ltheadinggtReminderlt/headinggt
  • ltbodygtDon't forget me this weekend!lt/bodygt
  • lt/notegt

8
XSL File
  • lt?xml version'1.0'?gt
  • ltxslstylesheet xmlnsxsl"http//www.w3.org/TR/WD
    -xsl"gt
  • ltxsltemplate match"/"gt
  • lthtmlgt ltbody bgcolor"yellow"gt
  • lth1gtReferences Data Internal Notelt/h1gt
  • ltxslfor-each select"note"gt
  • ltbgtTo lt/bgtltxslvalue-of select"TO" /gt ltbr
    /gt
  • ltbgtFrom lt/bgtltxslvalue-of select"from" /gt
    lthr /gt
  • ltbgtltxslvalue-of select"heading" /gtlt/bgt
    lthr /gt
  • ltxslvalue-of select"body" /gt
  • lt/xslfor-eachgt
  • lt/bodygt lt/htmlgt
  • lt/xsltemplategtlt/xslstylesheetgt

9
XML Basics
  • XML tags are not predefined, you make your own
    tag names.
  • XML can use a DTD (Document Type Definition) to
    formally describe the data
  • XML can store data in HTML pages as data
    islands
  • XML can be used to exchange data
  • All XML documents must have a root tag (like
    lthtmlgt for html documents)

10
Viewing XML
  • Well formed XML documents a document that
    conforms to XML syntax rules (xhtml)
  • Valid XML documents well formed and conforms
    to the rules of a DTD (Document Type Definition).
  • Error
  • In
  • XML

11
Viewing XML in the Internet Explorer
  • To see an open XML file follow this URL
  • http//www.xmlfiles.com/examples/simple.xml
  • To see an XML that uses XSL
  • http//www.xmlfiles.com/examples/simplexsl.xml

12
XSL eXtensible Stylesheet Language
  • Similar to CSS but this is from XML
  • It can do two basic functions
  • Transform XML into a format that can be
    displayed by the browser.
  • Format the document by selective display of
    items through filtering and sorting of output
    plus more.

13
  • lt?xml version"1.0" encoding"ISO8859-1" ?gt
    lt?xml-stylesheet type"text/xsl"
    href"cd_catalog.xsl"?gt ltCATALOGgt ltCDgt
    ltTITLEgtEmpire Burlesquelt/TITLEgt ltARTISTgtBob
    Dylanlt/ARTISTgt ltCOUNTRYgtUSAlt/COUNTRYgt
    ltCOMPANYgtColumbialt/COMPANYgt ltPRICEgt10.90lt/PRICEgt
    ltYEARgt1985lt/YEARgt lt/CDgt
  • lt?xml version'1.0'?gt ltxslstylesheet
    xmlnsxsl"http//www.w3.org/TR/WD-xsl"gt
  • ltxsltemplate match"/"gt lthtmlgt ltbodygt lttable
    border"2" bgcolor"yellow"gt lttrgt ltthgtTitlelt/thgt
    ltthgtArtistlt/thgt lt/trgt ltxslfor-each
    select"CATALOG/CD"gt lttrgtlttdgt
  • ltxslvalue-of select"TITLE"/gt lt/tdgt
    lttdgtltxslvalue-of select"ARTIST"/gtlt/tdgt lt/trgt
    lt/xslfor-eachgt lt/tablegt lt/bodygt lt/htmlgt
    lt/xsltemplategt lt/xslstylesheetgt

14
You can see how they relate
  • The XSL files name is mentioned in the XML file.
  • The XML repeated element is mentioned in the XSL
    and so are the child elements
  • ltxslvalue-of select"TITLE"/gt
  • Will get a copy of that value for display

15
  • IF
  • ltxslfor-each select"CATALOG/CD"gt ltxslif
    match".ARTIST'Bob Dylan'"gt lt/xslifgt
    lt/xslfor-eachgt
  • CHOOSE
  • ltxslfor-each select"CATALOG/CD"gt lttrgt
    lttdgtltxslvalue-of select"TITLE"/gtlt/tdgt
    ltxslchoosegt ltxslwhen match".ARTIST'Bob
    Dylan'"gt . lt/xslwhengt
  • ltxslotherwisegt lt/xslotherwisegt lt/xslchoosegt
  • lt/trgt lt/xslfor-eachgt

16
  • Sorting
  • ltxslfor-each select"CATALOG/CD" order-by"
    ARTIST"gt
  • Filter
  • ltxslfor-each select"CATALOG/CD ARTIST'Bob
    Dylan'"gt

17
  • Now you are ready to start your Practice sessions
Write a Comment
User Comments (0)
About PowerShow.com