Title: XML
1XML
What is XML? Extensible Markup Language is a
meta-language that describes the content of a
document. XML is a means to organize data into a
form that permits us to transmit the data in a
standard way. A meta-language is a language
used to describe other languages
2Applications
1. Configuration Files 2. Media for data
exchange an alternative to proprietary
standards 3. Data storage 4. Business to
Business transactions on the web (SOAP)
3An example
lt?xml version"1.0" encoding"ISO-8859-1"?gt
ltnotegt lttogt Jane lt/togt ltfromgt Tarzan
lt/fromgt ltheadinggt Reminder lt/headinggt
ltbodygt Don't forget me this weekend! lt/bodygt
lt/notegt
4An example
lt?xml version"1.0" encoding"ISO-8859-1"?gt
ltnotegt lttogtTovelt/togt ltfromgtJanilt/fromgt
ltheadinggtReminderlt/headinggt ltbodygtDon't
forget me this weekend!lt/bodygt lt/notegt
The first line in the document - the XML
declaration defines the XML version and the
character encoding used in the document. In this
case the document conforms to the 1.0
specification of XML and uses the ISO-8859-1
(Latin-1/West European) character set.
5Elements
ltnotegt This is a single element lt/notegt
This is a an element
6Elements
ltnotegt This is a single element lt/notegt
This is a an element
lt/notegt
ltnotegt
End Tag
Start Tag
7Elements
ltnotegt This is a single element lt/notegt
This is a an element
lt/notegt
ltnotegt
End Tag
Start Tag
Tag names are case-sensitive !
8Elements - attributes
Attributes are used to provide additional
information about elements.
lttag attrName valuegt . lt/taggt
There can be any number of attributes in an
element
ltprotein geneName HK1 genBankId M75126 EC
2.7.1.1gt Hexokinaselt/proteingt
9Elements can be Nested
Elements can be nested, an element can either
contain content or one or more additional elements
ltgenegt ltmRNAgt GCCGAUCGGGUA
lt/mRNAgt ltproteingt Ala-Gly-Ser-..
lt/proteingtlt/genegt
child element
10Content
The data content in elements and attributes can
only be text. If you want to store numeric data,
you have to store it as a text string, eg
3.1415926 White space is preserved, eg ltnamegt
My name is Adam Smith
lt/namegt the spacing between name and is is
preserved
11Comments
Comments can be added to an XML file lt!-- This
is a comment --gt
12Tags
1. Case Sensitive 2. Start with letter or
underscore 3. , . and numbers are allowed after
first letter 4. Cannot contain white
space 3note, _3note, A Note, Simple.Note
13Entity References
Whats wrong with the following element? ltnotegt
ltMy Contentgt lt/notegt
14Entity References
Whats wrong with the following element? ltnotegt
ltMy Contentgt lt/notegt Since lt and gt are
reserved characters we cant use them in this
matter, instead we use an entity
reference. Entities start with and end with
Characters that can cause problems include lt,
gt, , ,
15Entity References
Reserved characters are represented using
entities lt gt amp quot
apos ltnotegt ltMy Contentgt lt/notegt
16CDATA
If you have a large block of data which contains
many reserved characters you can use a CDATA
block to represent the data. lt!CDATA
anything goes here ! gt eg we could use a CDATA
to store a block of HTML
17CDATA
ltscriptgt lt!CDATA function
matchwo(a,b) if (a lt b a lt 0)
return 1 else
return 0 gt
lt/scriptgt
18How do we know if an XML file is valid?
If someone gives you an xml file, how do you know
its correct and conforms to an agreed
format? Someone who specs out an XML format has
the option to generate a so-called XML-schema
file.
19How do we know if an XML is valid?
ltclassgt ltstudent studentId 1234gt
ltnamegt James Smith lt/namegt ltGPAgt 3.8
lt/GPAgt lt/studentgt lt/classgt
20How do we know if an XML is valid?
Schema files are writing in XML and are used to
define the structure of a particular XML file.
Applications can use the schema to check that a
particular XML file is indeed the file it expects.
ltSchema xmlns"urnschemas-microsoft-comxml-data"
xmlnsdt"urnschemas-microsoft-comdatatypes"gt
ltAttributeType name'studentID'
dttype'string' required'yes'/gt ltElementType
name'name' content'textOnly'/gt ltElementType
name'GPA' content'textOnly' dttype'float'/gt
ltElementType name'student' content'mixed'gt
ltattribute type'studentID'/gt ltelement
type'name'/gt ltelement type'GPA'/gt
lt/ElementTypegt ltElementType name'class'
content'eltOnly'gt ltelement type'student'/gt
lt/ElementTypegt lt/Schemagt
21Disadvantages of XML
- The main criticism of XML is that it is verbose,
this leads to a number - of issues, the main ones being
- Files tend to be large
- Large files are slow to transmit
22Examples of XML
SBML Systems Biology markup Language
23Systems Biology Markup Language (SBML)
- Domain biochemical network models
- XML with components that reflect the natural
conceptual constructs used by modelers in the
domain - Reaction networks described by list of
components - Beginning of model definition
- List of unit definitions (optional)
- List of compartments
- List of species
- List of parameters (optional)
- List of rules (optional)
- List of reactions
- End of model definition
24Example
25Example (cont.)
lt?xml version"1.0" encoding"UTF-8"?gt ltsbml
level"1" version"1"gt ltmodel name"simple"gt
ltlistOfCompartmentsgt ltcompartment
name"c1" /gt lt/listOfCompartmentsgt
ltlistOfSpeciesgt ltspecie name"X0"
compartment"c1" boundaryCondition"true
" initialAmount"1"/gt
ltspecie name"S1" compartment"c1"
boundaryCondition"false"
initialAmount"0"/gt ltspecie name"X1"
compartment"c1" boundaryCondition"true"
initialAmount"0"/gt
ltspecie name"X2" compartment"c1"
boundaryCondition"true"
initialAmount"0.23"/gt lt/listOfSpeciesgt
26Example (cont.)
lt?xml version"1.0" encoding"UTF-8"?gt ltsbml
level"1" version"1"gt ltmodel name"simple"gt
ltlistOfCompartmentsgt ltcompartment
name"c1" /gt lt/listOfCompartmentsgt
ltlistOfSpeciesgt ltspecie name"X0"
compartment"c1" boundaryCondition"true"
initialAmount"1"/gt
ltspecie name"S1" compartment"c1"
boundaryCondition"false"
initialAmount"0"/gt ltspecie name"X1"
compartment"c1" boundaryCondition"true"
initialAmount"0"/gt
ltspecie name"X2" compartment"c1"
boundaryCondition"true"
initialAmount"0.23"/gt lt/listOfSpeciesgt
27Example (cont.)
lt?xml version"1.0" encoding"UTF-8"?gt ltsbml
level"1" version"1"gt ltmodel name"simple"gt
ltlistOfCompartmentsgt ltcompartment
name"c1" /gt lt/listOfCompartmentsgt
ltlistOfSpeciesgt ltspecie name"X0"
compartment"c1" boundaryCondition"true"
initialAmount"1"/gt
ltspecie name"S1" compartment"c1"
boundaryCondition"false"
initialAmount"0"/gt ltspecie name"X1"
compartment"c1" boundaryCondition"true"
initialAmount"0"/gt
ltspecie name"X2" compartment"c1"
boundaryCondition"true"
initialAmount"0.23"/gt lt/listOfSpeciesgt
28Example (cont.)
ltlistOfReactionsgt ltreaction name"reaction_1"
reversible"false"gt ltlistOfReactantsgt
ltspecieReference specie"X0
stoichiometry"1"/gt lt/listOfReactantsgt
ltlistOfProductsgt ltspecieReference
specie"X0" stoichiometry"1"/gt
lt/listOfProducsgt ltkineticLaw formula"k1
X0"gt ltlistOfParametersgt
ltparameter name"k1" value"0"/gt
lt/listOfParametersgt lt/kineticLawgt
lt/reactiongt ltreaction name"reaction_2"
reversible"false"gt ltlistOfReactantsgt
ltspecieReference specie"S1"
stoichiometry"1"/gt lt/listOfReactantsgt .
. .
29Other Applications
SOAP - Simple Object Access Protocol SOAP is a
simple XML based protocol to let applications
exchange information over HTTP. HTTP XML SOAP
30SOAP
- SOAP stands for Simple Object Access Protocol
- SOAP is a communication protocol
- SOAP is for communication between applications
- SOAP is a format for sending messages
- SOAP is designed to communicate via Internet
- SOAP is platform independent
- SOAP is language independent
- SOAP is based on XML
- SOAP is simple and extensible
- SOAP allows you to get around firewalls
- SOAP will be developed as a W3C standard
31SOAP
- Provide RPC and User Defined Data Types
- Utilize Existing Simple Standards (HTTP, XML)
- Cross Platform (unlike DCOM)
- Cross Language (unlike Java RMI)
- Localization (English, Chinese, etc.)
- Protocol Agnostic (HTTP, SMTP)
32SOAP
Today's applications communicate using Remote
Procedure Calls (RPC) between objects like DCOM
and CORBA, but HTTP was not designed for this.
RPC represents a compatibility and security
problem firewalls and proxy servers will
normally block this kind of traffic. A better way
to communicate between applications is over HTTP,
because HTTP is supported by all Internet
browsers and servers. SOAP was created to
accomplish this. SOAP provides a way to
communicate between applications running on
different operating systems, with different
technologies and programming languages.
33SOAP
- SOAP is a key element of Microsoft's .NET
architecture for future Internet application
development. - A SOAP message is an ordinary XML document
containing the following elements - A required Envelope element that identifies the
XML document as a SOAP message - An optional Header element that contains header
information - A required Body element that contains call and
response information - An optional Fault element that provides
information about errors that occurred while
processing the message
34SOAP
Call to GetPrice lt?xml version"1.0"?gt
ltsoapEnvelope xmlnssoaphttp//www.w3.org
/2001/12/soap-envelope
soapencodingStyle"http//www.w3.org/2001/12/soap
-encoding"gt ltsoapBodygt ltmGetPrice
xmlnsm"http//www.w3schools.com/prices"gt
ltmItemgtAppleslt/mItemgt lt/mGetPricegt
lt/soapBodygtlt/soapEnvelopegt
35SOAP
Response SOAP to GetPrice lt?xml version"1.0"?gt
ltsoapEnvelope xmlnssoap"http//www.w3.or
g/2001/12/soap-envelope
soapencodingStyle"http//www.w3.org/2001/12/soap
-encoding"gtltsoapBodygt
ltmGetPriceResponse xmlnsm"http//www.w3schools.
com/prices"gt ltmPricegt1.90lt/mPricegt
lt/mGetPriceResponsegtlt/soapBodygtlt/soapE
nvelopegt
36WebServices
The main application of SOAP is in
the implementation of WebServices
37WebServices
Web services, in the general meaning of the term,
are services offered via the Web. In a typical
Web services scenario, a business application
sends a request to a service at a given URL using
the SOAP protocol over HTTP. The service receives
the request, processes it, and returns a
response. An often-cited example of a Web service
is that of a stock quote service, in which the
request asks for the current price of a specified
stock, and the response gives the stock price.
This is one of the simplest forms of a Web
service in that the request is filled almost
immediately, with the request and response being
parts of the same method call.