Introduction to XML - PowerPoint PPT Presentation

1 / 33
About This Presentation
Title:

Introduction to XML

Description:

Simple Mortgage Calculator. Mortgage payment calculator ... Mortgage Calculator General Requirements. Must be. Clean simple interface (easy) ... – PowerPoint PPT presentation

Number of Views:38
Avg rating:3.0/5.0
Slides: 34
Provided by: peopleCs
Category:

less

Transcript and Presenter's Notes

Title: Introduction to XML


1
Introduction to XML
2
Programming models
3
Distributed programming modelsTypical Web-based
  • Easy to deploy but slow, not great user experience

database
html browser
WebServer
http
  • Many programming models
  • JSP
  • Servlets
  • PHP
  • CGI (python, perl, C)
  • Cold Fusion

Dynamically Generated html
html
plus optionally JavaScript to jazz up html
4
Distributed programming modelsTypical Web-based
  • Better user experience. Heavier, less portable,
    requires socket programming to stream to server.

html
database
WebServer
http
applet
socket
Dynamically Generated html
html applet
5
Direct Connections
App1
Application client
Remote Procedures
NDS
App2
App3
Examples Javas rmi, CORBA
6
XML basics
7
XML Basics, cont
  • Most modern languages have method of representing
    structured data.
  • Typical flow of events in application

Read data (file, db, socket)
Marshal objects
Manipulate in program
Unmarshal (file, db, socket)
  • Many language-specific technologies to reduce
    these steps RMI, object
  • serialization in any language, CORBA (actually
    somewhat language neutral),
  • MPI, etc.
  • XML provides a very appealing alternative that
    hits the sweet spot for
  • many applications

8
User-defined types in programming languages
  • XML is a text-based, programming-language-neutral
    way of representing structured information.
    Compare

9
Sample XML Schema
  • In XML, datatype description is called a schema.
  • ema"
  • elementFormDefault"qualified"
    attributeFormDefault"unqualified"
  • type"xsstring"/
  • type"xsstring"/
  • type"xsinteger"/
  • type"xsdecimal"/

Ignore this For now
10
Alternative schema
In this example studentType is defined separately
rather than anonymously


type"xsstring"/ type"xsstring"/ type"xsinteger"/ type"xsdecimal"/

new type defined separately
11
Alternative DTD
Can also use a DTD (Document Type Descriptor),
but this is probably becoming obsolete (notice
the lack of types) Each XML file is stored in a document whose name
is the same as the root node -- ELEMENT Student (name,ssn,age,gpa) Student has four attributes --
is parsed character data -- ssn (PCDATA) (PCDATA)

12
Creating instances of types
In programming languages, we instantiate
objects struct Student s1, s2 s1.name
Andrew s1.ssn123-45-6789 Student s new
Student() s1.name Andrew s1.ssn123-45-6789
. type(Student) s1 s1name Andrew .
C
Java
Fortran
13
Creating XML documents
  • XML is not a programming language!
  • In XML we make a Student object in an xml file
    (Student.xml)
  • Andrew
  • 123-45-6789
  • 36
  • 2.0
  • Think of this as like a serialized object.

14
XML and Schema
  • Note that there are two parts to what we did
  • Defining the structure layout
  • Defining an instance of the structure
  • The first is done with an appropriate Schema or
    DTD.
  • The second is the XML part
  • Both can go in the same file, or an XML file can
    refer to an external Schema or DTD (typical)
  • From this point on we use only Schema

15
XMLSpy
16
XMLSpy
  • Excellent tool for both learning and developing
    XML.
  • Many XML books contain free 90-day license.
    Otherwise, free 30-day license on web page for
    professional and totally free home edition
  • Try to use XMLSpy to create example just covered.

17
Aspects of XML syntax
  • It is illegal to omit closing tags
  • XML tags are case-sensitive
  • XML elements must be properly nested
  • XML elements must have a root element
  • XML preserves whitespaces
  • XML comments

18
How is XML Useful
  • Part I
  • Simple Mortgage Calculator

19
Mortgage payment calculator
  • Design a simple application which does the
    following
  • Accepts user input
  • Loan amount
  • Loan term
  • Interest rate
  • Extras (assessments taxes)
  • Returns per-month table of
  • total payment
  • interest
  • Principal
  • Some other fun stuff

20
Mortgage Calculator General Requirements
  • Must be
  • Clean simple interface (easy)
  • Remotely accessible with security
  • Portable
  • Not require too much installation on the part of
    the user
  • Sufficiently fast not to be embarrassing

21
Some possible architectures
  • Web server
  • Server-side scripting with pure html
  • Server-side scripting with htmljavascript
  • Server-side scripting with htmlapplet
  • Direct connection
  • Raw sockets
  • Distributed objects

22
Initial architecture
  • Front-end pure html form
  • Back end python cgi (similar to java servlet)
  • Python generates web page dynamically after
    making calculations
  • No use of higher-level web generation libraries
    at this point
  • What are advantages/disadvantages of this
    architecture?
  • Run application
  • http//masters.cs.uchicago.edu/asiegel/courses/cs
    pp53025/caseStudies/mortgage

23
Disadvantages
  • Two obvious disadvantages are
  • Formatted web content in print statements
    low-level, ugly error prone
  • Data is not decoupled from formatting. What if we
    want to switch to an application client?
  • Several strategies can help with both of these
    (higher-level htmlgen libraries, server-side
    scripting model, beans, etc.) and XML
  • We will look at how XML fits in

24
XML-based architecture
web browser
hand-rolled XML
WebServer
http
File system
python CGI
hand-rolled XML
XML
25
Observations/questions
  • What does browser do with XML?
  • Can it display
  • Does it even understand XML?
  • If not, what good is this?
  • Do we have to hand roll our programming language
    objects from XML?

26
Some answers
  • Regarding first point, try this with your web
    browser
  • Note that XML is displayed/formatted nicely, but
    not nearly to the same level of utility as the
    html table
  • To add formatting instructions, we must associate
    a separate XSL file with the XML file. We will
    study XSL soon.
  • Regarding XML-language conversion, we will study
    language binding for various high-level ways of
    doing this! For now, we will hand-roll ourselves!

27
XSL
  • We will not cover details of XSL until the third
    week.
  • However, for now we can easily create XSL at a
    high level using XMLSpy
  • See example application

28
Lottery application
29
Lottery overview
  • Given a list of student members of a dormitory,
    perform an ordered randomized sort of the
    students to determine a room draft order.

30
Lottery details
  • Students are defined by
  • Last name
  • First name
  • Seniority
  • Quarters in the House
  • Quarters in the College
  • The sort keys are
  • Quarters in House
  • Quarters in College
  • Random

31
Software requirements
  • Secure login
  • House name
  • Password
  • Remotely accessible
  • Prototypes
  • Standalone excel
  • Web-based

32
Architectural requirements
filesystem
XML Login Info
login
Web Server
Web Client
XML
XML Student Data
XSL
lottery
33
Next Step
  • Implement Lottery as specified
  • You must have the following
  • Student Schema
  • Password Schema
  • Sample student xml
  • Sample password xml
  • Simple XSL for display
Write a Comment
User Comments (0)
About PowerShow.com