Displaying the XML document - PowerPoint PPT Presentation

1 / 33
About This Presentation
Title:

Displaying the XML document

Description:

The e-commerce issues with the display of XML. ... the XML document, XML can be used as a lingua franca' between different systems. ... – PowerPoint PPT presentation

Number of Views:26
Avg rating:3.0/5.0
Slides: 34
Provided by: jonathan76
Category:

less

Transcript and Presenter's Notes

Title: Displaying the XML document


1
Displaying the XML document
  • indicates covered in lecture/other slides to
    studied in your own time
  • The e-commerce issues with the display of XML
  • .xml files - how do we display the data they
    contain?
  • Introduction to techniques
  • XML Spy - How To
  • Summary

2
Our lifecycle the next stage
  • XML documents built from XML Schema.
  • XML document gets parsed into a node structure.
  • Node structure is transformed into HTML using the
    stylesheet.

Parser stylesheet .xsl
Schema .xsd
Result HTML .html
XML doc .xml
3
E-Commerce issues
  • Web accessibility create alternative web sites
    for special needs e.g. disabilities, WAP phones,
    PDAs.
  • Makes application data available to other
    applications supporting different schemas.
  • Data transformation crucial! separation of
    transformation effort from application data
    effort good software engineering.
  • Via transformation of the XML document, XML can
    be used as a lingua franca between different
    systems.
  • This is akin to a Babelfish, i.e. an
    intermediate language that can be used to convert
    English to Chinese or (for our purposes) one
    companys data (and its structure/schema) to
    another companys.

4
The presentation of XML
  • XML (schemas and .xml files) may be understood by
    developers but what about the poor old user?
  • XML information needs presenting in some other
    non-technical form typically via a browser
  • On a PC
  • On a mobile
  • On a PDA
  • On a TV
  • Hence this week and next we are looking at the
    presentation aspects regarding XML.

5
XSL and XSLT
  • eXtensible Stylesheet Language (XSL).
  • An XML based language.
  • XSL Transformation (XSLT) - one subset of XSL but
    there are others.
  • XSL and XSLT specify how an XML document should
    be converted (transformed) into other XML
    documents or text files, such a HTML, XHTML, or
    WML pages.
  • XSL/XSLT also includes the ability to manipulate
    both tags and data content.

6
A new file extension to consider
  • .xsl files.
  • XML Stylesheet files.
  • Can be programmed actually quite complex
    there are now books devoted to just this aspect.
  • Essential purpose to display the contents of an
    .xml file(s).
  • It follows that an .xml file can have a
    stylesheet allocated to it .
  • Just to mention that XML can use cascading
    stylesheets but for this module we will not.

7
Other initial comments
  • Stylesheet aspect of XML can be quite time
    consuming.
  • Even using XML Spy this is no exception
    essentially as you will see you need to code
    it.
  • XML Spy does assist in the selection of XSL
    items.
  • Why is transformation necessary?
  • Generally at the moment the main browsers are
    still HTML browsers and so typically the
    stylesheet converts the XML to display in an HTML
    format.
  • In the future the overhead of the transformation
    will be reduced. A stylesheet will probably
    always be necessary however.

8
More details about the terms
  • Extensible Style Language (XSL) was the original
    specification.
  • W3C divided XSL into two pieces
  • XSLT for transformation.
  • XSL-FO for formatting objects.
  • Transforming an XML file (document) means in
    lay terms to analyse its contents and take action
    depending on the elements found i.e. display
    according to certain requirements programmed in
    the stylesheet.

9
How to do it
  • There are a number of methods for displaying XML.
  • The following slides introduce the techniques.
  • Transform using an XSL file and a parser
  • SAX
  • DOM
  • Use data islands see last weeks notes

10
The presentation of XML
  • There are a range of options/alternatives but
    this is the main (current, general) technique
  • Transform the XML by applying an XSL style sheet.
  • The style sheet specifies how the XML should be
    parsed.
  • Once the style sheet has been designed and
    created you need only to apply it to the xml file
    to get presentation output see XML Spy example
    later.
  • To achieve the above a XSLT processor is needed -
    a .xml file and .xsl file are input and the
    output is transformed text.
  • We need to use a parser and the choices include
    SAX or DOM more about this next week

11
Parsers
  • Parsing the XML using SAX (the Simple API for
    XML) server side.
  • Originally developed for Java but Microsofts
    MSXML 4.0 also implements SAX.
  • SAX reads XML like a spool of film running
    through a projector - as it finds elements it
    fires events that the developer can handle to
    derive the output desired.
  • SAX yet works well with large XML files and hence
    is a server side solution.

12
Parsers
  • Parse the XML using DOM (Document Object Model)
    server side.
  • DOM parser reads an XML file into memory and then
    traverse its nodes to extract the content.
  • a node is one individual piece of information -
    an element - a node tree is hierarchical
    representation of the entire XML document.
  • DOM is a rival to SAX and has an advantage over
    SAX
  • DOM gives random access to the content rather
    than sequential.
  • However, DOM can consume more memory that SAX and
    this may be a problem commercially.

13
The presentation of XML
  • Which one does XML Spy use by default?
  • .xsl and the DOM parser and thats what we will
    use for this module.
  • The following slides/screenshots explain.

14
(No Transcript)
15
The steps involved
  • 1. Create an XSL file a .xsl file.
  • 2. Assign it to the XML file a .xml file.
  • 3. Run the XSLT transformation processor.
  • 4. View the results either in XML Spy or a
    browser.
  • For home users you should find not difference
    to the labs but it you do let use know. You may
    need to download MSXML 3.0 if you are using IE
    older than 6.0 at home (i.e 5.0 or 5.5) this is
    explained on the next two screen grabs from XML
    Spy. May be time to upgrade your browser?
  • The labs use the latest version (v7) and so it
    will not be necessary to download anything as the
    MSXML (the Microsoft DOM parser) 3.0 or 4.0 is
    built into the browser product.

16
Create an XSL file a .xsl file
17
Supporting notes
  • When an .xsl file is created in XML Spy a default
    skeleton is created HOWEVER the body of the
    .xsl (the stylesheet) is NOT created
    automatically that is up to the developer to
    create/code.
  • The stylesheet language (a specification) is used
    to populate the body part essentially the
    developer writes the stylesheet script
    indicating how the data will be displayed.

18
Explanation of default skeleton
  • lt?xml version"1.0" encoding"UTF-8"?gt
  • ltxslstylesheet version"1.0" xmlnsxsl"http//ww
    w.w3.org/1999/XSL/Transform" xmlnsfo"http//www.
    w3.org/1999/XSL/Format"gt
  • create stylesheet code in here
  • lt/xslstylesheetgt

This has to be written by the developer
19
Explanation in more detail
  • lt?xml version"1.0" encoding"UTF-8"?gt
  • Every XSL style sheet is an XML document in
    itself and therefore should begin with a standard
    XML declaration.
  • ltxslstylesheet version"1.0" xmlnsxsl"http//ww
    w.w3.org/1999/XSL/Transform" xmlnsfo"http//www.
    w3.org/1999/XSL/Format"gt
  • Specifies a namespace for the style sheet.
  • lt/xslstylesheetgt
  • completes the style sheet.

20
Supporting notes
  • To start with dont worry about writing a
    stylesheet script.
  • Let us move on to assigning an (empty) .xsl file
    to a .xml document.
  • What we can then do is ask it to display the data
    in the .xml document what we will get is an
    .html file with nothing on it which is correct!
    As we have not specified how to display the data.
  • However we must edit the stylesheet file so that
    it has the following line ltxsltemplate match"/"
    /gt - this will make it look for the root of the
    xml document we assign it to as depicted on the
    next screen grab.

21
(No Transcript)
22
Assigning the .xsl to an .xml file
  • Firstly within XML Spy open up (select) the .xml
    document you are going to use.
  • Then click on the Assign XSL drop down menu
    option.
  • Select Assign XSL XML Spy will ask you for the
    location of the .xsl file.
  • The .xml file will be edited to include a line
    indicating the stylesheet it is to use.
  • The following screen grabs illustrate.

23
XSL
The XSL drop down menu
The .xml file we intend to use
24
This shows in text view the xml file has now had
the .xsl file assigned to it
25
Transformation stage
  • Select the XSL Transformation option from the XSL
    drop down menu.
  • Essentially this will parse the XML file with the
    .xsl stylesheet and create an .html file using
    the transformation engine.
  • The display should show nothing! this proves
    you have everything in place (the environment is
    okay) the next stage will be to start to write
    a meaningful stylesheet!

26
.html file created
27
Views
  • Can either view the result within XML Spy or by
    selecting the file in a browser such as IE.
  • The following screen grab indicates this.

28
(No Transcript)
29
XSLT
  • More about the transformation engine can be found
    in XML Spy help.
  • The next screen grab indicates this.

30
(No Transcript)
31
Summary
  • We have followed the next step of our lifecycle
    by creating a skeleton stylesheet (.xsl).
  • We have then assigned it to an xml document.
  • We have now entered the world of web browsers
    it most cases the user will wish to see the
    content of the xml document in a web browser -
    most browsers are HTML based but support XML.
  • The browsers on the market all support XML to
    some extent
  • Can you name 4 other browsers on the market?

32
Summary
  • In the future browsers will probably be XML
    browsers and some of the transformation process
    will be obsolete.
  • The stylesheet can contain static data you may
    care to look at PODstyle2.xsl example on trentdev
    in the \studentinfo\Software\xml_for_deca_module
    \examplestylesheetsfolder to see what we mean
    by this notice how the stylesheet includes
    information normally found on a letterhead.

33
Other related thoughts good topic for projects
  • XML browsers versus HTML browsers
  • Metrics regarding SAX V DOM
  • B2B ecommerce impact of XSL/XSLT
  • B2C ecommerce impact of XSL/XSLT
  • Customised web-publishing with XSLT (particularly
    wrt legal changes in accessibility)
Write a Comment
User Comments (0)
About PowerShow.com