Professional Documents
Culture Documents
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 1
Objective…
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 2
Agenda… Day 1
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 3
Agenda… Day 2
XML Assignments
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 4
XML
XML is a markup language for documents
containing structured information
<?xml version="1.0"?>
<student id="101">
<name>kumar</name>
<age>21</age>
</student>
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 5
XML Declaration
<?xml version="version_number"
encoding="encoding_declaration"
standalone="standalone_status" ?>
Example:
<?xml version=“1.0” encoding=“UTF-8”
standalone=“yes” ?>
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 6
XML Declaration Rules
If the XML declaration is included, it must be
situated at the first position of the first line in the
XML document
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 7
XML Declaration
Possible Attribute values:
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 8
XML Vs HTML
XML HTML
User definable tags Defined set of tags designed for
web display
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 9
Namespace
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 10
Namespaces disambiguate elements
• Namespaces disambiguate elements with the
same name from each other by attaching
different prefixes to names from different
XML applications.
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 12
Namespace Syntax
• Elements and attributes that are in namespaces have
names that contain exactly one colon. They look like
this:
rdf:description
xlink:type
xsl:template
• Everything before the colon is called the prefix
• Everything after the colon is called the local part.
• The complete name including the colon is called the
qualified name.
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 13
Namespace URIs
• Each prefix is associated with a URI (technically a URI
reference) called a namespace name.
• For example, all elements in XSLT 1.0 style sheets are
associated with the http://www.w3.org/1999/XSL/Transform
URI.
• The customary prefix xsl is a shorthand for the longer URI
http://www.w3.org/1999/XSL/Transform.
• You can't use the URI in the element name directly.
{http://www.w3.org/1999/XSL/Transform}template
http://www.w3.org/1999/XSL/Transform#templa
te
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 14
Binding Prefixes to Namespace URIs
• Prefixes are bound to namespace URIs by attaching an
xmlns:prefix attribute to the prefixed element or one of its
ancestors.
<svg:svg xmlns:svg="http://www.w3.org/2000/svg"
width="12cm" height="10cm">
<svg:ellipse rx="110" ry="130" />
<svg:rect x="4cm" y="1cm" width="3cm" height="6cm" />
</svg:svg>
• Bindings have scope within the element where they're
declared.
• An SVG processor recognizes all three of these elements as
SVG elements because they all have prefixes bound to the
particular URI defined by the SVG specification.
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 15
Namespaces and Attributes
• An attribute can be placed in a namespace by
prefixing its name.
• Normally only used for global atributes that can
appear on any element such as XLink attributes
rather than attributes that are tied to a specific
element.
• Unprefixed attributes are never in any namespace.
• Being an attribute of an element in the
http://www.w3.org/1999/xhtml namespace is not
sufficient to put the attribute in the
http://www.w3.org/1999/xhtml namespace.
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 16
URIs matter, not prefixes
• Many XML applications have recommended
prefixes. For example, SVG elements often use the
prefix svg and Resource Description Framework
(RDF) elements often have the prefix rdf. However,
these prefixes are simply conventions, and can be
changed based on necessity, convenience or whim.
• Before a prefix can be used, it must be bound to a
URI.
• These URIs are standardized, not the prefixes.
• The prefix can change as long as the URI stays the
same.
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 17
The Default Namespace
• Indicates that an unprefixed element and all its unprefixed
descendant elements belong to a particular namespace by
attaching an xmlns attribute with no prefix:
<DATASCHEMA xmlns="http://www.w3.org/2000/P3Pv1">
<DATA name="vehicle.make" type="text" short="Make"
category="preference" size="31"/>
<DATA name="vehicle.model" type="text" short="Model"
category="preference" size="31"/>
<DATA name="vehicle.year" type="number" short="Year"
category="preference" size="4"/>
<DATA name="vehicle.license.state." type="postal." short="State"
category="preference" size="2"/>
<DATA name="vehicle.license.number" type="text" short="License
Plate Number" category="preference" size="12"/>
</DATASCHEMA>
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 18
The Default Namespace
• Both the DATASCHEMA and DATA
elements are in the
http://www.w3.org/2000/P3Pv1 namespace.
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 19
Multiple default namespaces
• You can change the default namespace within a particular element by adding an xmlns
attribute to the element.
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:xlink="http://www.w3.org/1999/xlink">
<head><title>Three Namespaces</title></head>
<body> <h1 align="center">An Ellipse and a Rectangle</h1>
<svg xmlns="http://www.w3.org/2000/svg" width="12cm" height="10cm">
<ellipse rx="110" ry="130" />
<rect x="4cm" y="1cm" width="3cm" height="6cm" />
</svg>
<p xlink:type="simple" xlink:href="ellipses.html"> More about ellipses </p>
<p xlink:type="simple" xlink:href="rectangles.html"> More about rectangles
</p> <hr/> <p>Last Modified February 13, 2000</p>
</body>
</html>
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 20
Parsers compare namespace URIs character
by character
– http://www.w3.org/1999/XSL/Transform
– http://www.w3.org/1999/XSL/Transform/
– http://www.w3.org/1999/XSL/Transform/index.ht
ml
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 21
Namespaces and Schemas
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 22
A Song with a Namespace
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<SONG xmlns="http://ibiblio.org/xml/namespace/song"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation = "http://www.cafeconleche.org/namespace/song
namespace_song.xsd" >
<TITLE>Hot Cop</TITLE>
<PHOTO ALT="Victor Willis in Cop Outfit" WIDTH="100" HEIGHT="200"/>
<COMPOSER>Jacques Morali</COMPOSER>
<COMPOSER>Henri Belolo</COMPOSER>
<COMPOSER>Victor Willis</COMPOSER>
<PRODUCER>Jacques Morali</PRODUCER>
<PUBLISHER>PolyGram Records</PUBLISHER>
<YEAR>1978</YEAR>
<ARTIST>Village People</ARTIST>
</SONG>
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 23
A Schema for a Document that Uses the Default
Namespace
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://ibiblio.org/xml/namespace/song"
targetNamespace="http://ibiblio.org/xml/namespace/song"
elementFormDefault="qualified" attributeFormDefault="unqualified" >
<xsd:element name="SONG" type="SongType"/>
<xsd:complexType name="SongType">
<xsd:sequence>
<xsd:element name="TITLE" type="xsd:string"/>
<xsd:element name="PHOTO" type="PhotoType" minOccurs="0"/> <xsd:element
name="COMPOSER" type="xsd:string" maxOccurs="unbounded"/>
<xsd:element name="PRODUCER" type="xsd:string" minOccurs="0"
maxOccurs="unbounded"/>
<xsd:element name="PUBLISHER" type="xsd:string" minOccurs="0"/>
<xsd:element name="YEAR" type="xsd:gYear"/>
<xsd:element name="ARTIST" type="xsd:string" minOccurs="0"
maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType> </xsd:schema>
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 24
Multiple Namespaces, Multiple Schemas
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<SONG xmlns="http://www.cafeconleche.org/namespace/song"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation = "http://www.cafeconleche.org/namespace/song
xlink_song.xsd http://www.w3.org/1999/xlink xlink.xsd" >
<TITLE>Hot Cop</TITLE>
<PHOTO xlink:type="simple" xlink:href="hotcop.jpg" xlink:actuate="onLoad"
xlink:show="embed" ALT="Victor Willis in Cop Outfit" WIDTH="100"
HEIGHT="200"/>
<COMPOSER>Jacques Morali</COMPOSER>
<COMPOSER>Henri Belolo</COMPOSER>
<COMPOSER>Victor Willis</COMPOSER>
<PRODUCER>Jacques Morali</PRODUCER>
<PUBLISHER>PolyGram Records</PUBLISHER>
<YEAR>1978</YEAR>
<ARTIST>Village People</ARTIST>
</SONG>
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 25
XML Schemas
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 26
XML Schemas
“Schemas” is a general term--DTDs are a form of
XML schemas
According to the dictionary, a schema is “a structured
framework or plan”
When we say “XML Schemas,” we usually mean
the W3C XML Schema Language
This is also known as “XML Schema Definition”
language, or XSD
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 27
Why XML Schemas?
DTDs provide a very weak specification language
You can’t put any restrictions on text content
You have very little control over mixed content (text
plus elements)
You have little control over ordering of elements
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 28
Why not XML schemas?
DTDs have been around longer than XSD
Therefore they are more widely used
Also, more tools support them
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 30
The XSD document
Since the XSD is written in XML, it can get
confusing which we are talking about
Except for the additions to the root element of
our XML data document, the rest of this lecture
is about the XSD schema document
The file extension is .xsd
The root element is <schema>
The XSD starts like this:
<?xml version="1.0"?>
<xs:schema
xmlns:xs="http://www.w3.rg/2001/XMLSchema">
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 31
<schema>
The <schema> element may have
attributes:
xmlns:xs="http://www.w3.org/2001/XM
LSchema"
This is necessary to specify where all our
XSD tags are defined
elementFormDefault="qualified"
This means that all XML elements must be
qualified
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 32
“Simple” and “complex” elements
A “simple” element is one that contains text and
nothing else
A simple element cannot have attributes
A simple element cannot contain other elements
A simple element cannot be empty
However, the text can be of many different types, and
may have various restrictions applied to it
If an element isn’t simple, it’s “complex”
A complex element may have attributes
A complex element may be empty, or it may contain
text, other elements, or both text and other elements
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 33
Defining a simple element
A simple element is defined as
<xs:element name="name" type="type" />
where:
name is the name of the element
the most common values for type are
xs:boolean xs:integer
xs:date xs:string
xs:decimal xs:time
Other attributes a simple element may have:
default="default value" if no other value is specified
fixed="value" no other value may be specified
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 34
Defining an attribute
Attributes themselves are always declared as
simple types
An attribute is defined as
<xs:attribute name="name" type="type" />
where:
name and type are the same as for xs:element
Other attributes a simple element may have:
default="default value" if no other value is specified
fixed="value" no other value may be specified
use="optional" the attribute is not required
(default)
use="required" the attribute must be present
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 35
Restrictions, or “facets”
The general form for putting a restriction on a
text value is:
<xs:element name="name"> (or xs:attribute)
<xs:restriction base="type">
... the restrictions ...
</xs:restriction>
</xs:element>
For example:
<xs:element name="age">
<xs:restriction base="xs:integer">
<xs:minInclusive value="0">
<xs:maxInclusive value="140">
</xs:restriction>
</xs:element>
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 36
Restrictions on numbers
minInclusive -- number must be ≥ the given value
minExclusive -- number must be > the given value
maxInclusive -- number must be ≤ the given value
maxExclusive -- number must be < the given
value
totalDigits -- number must have exactly value
digits
fractionDigits -- number must have no more than
value digits after the decimal point
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 37
Restrictions on strings
length -- the string must contain exactly value characters
minLength -- the string must contain at least value characters
maxLength -- the string must contain no more than value characters
pattern -- the value is a regular expression that the string must match
whiteSpace -- not really a “restriction”--tells what to do with
whitespace
value="preserve" Keep all whitespace
value="replace" Change all whitespace characters to spaces
value="collapse" Remove leading and trailing whitespace, and replace
all sequences of whitespace with a single space
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 38
Enumeration
An enumeration restricts the value to be one of
a fixed set of values
Example:
<xs:element name="season">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="Spring"/>
<xs:enumeration value="Summer"/>
<xs:enumeration value="Autumn"/>
<xs:enumeration value="Fall"/>
<xs:enumeration value="Winter"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 39
Complex elements
A complex element is defined as
<xs:element name="name">
<xs:complexType>
... information about the complex type...
</xs:complexType>
</xs:element>
Example:
<xs:element name="person">
<xs:complexType>
<xs:sequence>
<xs:element name="firstName" type="xs:string" />
<xs:element name="lastName" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:sequence> says that elements must occur
in this order
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 40
Global and local definitions
Elements declared at the “top level” of a <schema> are available
for use throughout the schema
Elements declared within a xs:complexType are local to that type
Thus, in
<xs:element name="person">
<xs:complexType>
<xs:sequence>
<xs:element name="firstName" type="xs:string" />
<xs:element name="lastName" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
the elements firstName and lastName are only locally declared
The order of declarations at the “top level” of a <schema> do not
specify the order in the XML data document
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 41
Declaration and use
So far we’ve been talking about how to
declare types, not how to use them
To use a type we have declared, use it as
the value of type="..."
Examples:
<xs:element name="student" type="person"/>
<xs:element name="professor" type="person"/>
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 43
xs:all
xs:all allows elements to appear in any order
<xs:element name="person">
<xs:complexType>
<xs:all>
<xs:element name="firstName" type="xs:string" />
<xs:element name="lastName" type="xs:string" />
</xs:all>
</xs:complexType>
</xs:element>
Despite the name, the members of an xs:all
group can occur once or not at all
You can use minOccurs="n" and maxOccurs="n" to specify
how many times an element may occur (default
value is 1)
In this context, n may only be 0 or 1
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 44
Referencing
Once you have defined an element or
attribute (with name="..."), you can refer to
it with ref="..."
Example:
<xs:element name="person">
<xs:complexType>
<xs:all>
<xs:element name="firstName" type="xs:string" />
<xs:element name="lastName" type="xs:string" />
</xs:all>
</xs:complexType>
</xs:element>
<xs:element name="student" ref="person">
Or just: <xs:element ref="person">
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 45
Text element with attributes
If a text element has attributes, it is no
longer a simple type
<xs:element name="population">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:integer">
<xs:attribute name="year"
type="xs:integer">
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 46
Empty elements
Empty elements are (ridiculously) complex
<xs:complexType name="counter">
<xs:complexContent>
<xs:extension base="xs:anyType"/>
<xs:attribute name="count" type="xs:integer"/>
</xs:complexContent>
</xs:complexType>
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 47
Mixed elements
Mixed elements may contain both text and
elements
We add mixed="true" to the xs:complexType
element
The text itself is not mentioned in the element,
and may go anywhere (it is basically ignored)
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 48
List:
<xsd:simpleType name='sizes'>
<xsd:list itemType=‘xsd:decimal'/>
</xsd:simpleType>
Union:
- it is a derived data type.
- it is not built-in data type.
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 49
Predefined string types
Recall that a simple element is defined as:
<xs:element name="name" type="type" />
Here are a few of the possible string types:
xs:string-- a string
xs:normalizedString -- a string that doesn’t contain
tabs, newlines, or carriage returns
xs:token -- a string that doesn’t contain any
whitespace other than single spaces
Allowable restrictions on strings:
enumeration, length, maxLength, minLength,
pattern, whiteSpace
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 50
Predefined date and time types
xs:date -- A date in the format CCYY-MM-
DD, for example, 2002-11-05
xs:time -- A date in the format hh:mm:ss
(hours, minutes, seconds)
xs:dateTime -- Format is CCYY-MM-
DDThh:mm:ss
Allowable restrictions on dates and times:
enumeration, minInclusive, maxExclusive,
maxInclusive, maxExclusive, pattern,
whiteSpace
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 51
Predefined numeric types
• Here are some of the predefined numeric
types:
xs:decimal xs:positiveInteger
xs:byte xs:negativeInteger
xs:short xs:nonPositiveInteger
xs:int xs:nonNegativeInteger
xs:long
• Allowable restrictions on numeric types:
– enumeration, minInclusive, maxExclusive,
maxInclusive, maxExclusive, fractionDigits,
totalDigits, pattern, whiteSpace
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 52
XSL
XSL is a family of recommendations for defining XML
document transformation and presentation. It consists of
three parts:
XSL Transformations (XSLT)
a language for transforming XML
the XML Path Language (XPath)
an expression language used by XSLT to access or refer to parts
of an XML document. (XPath is also used by the XML Linking
specification)
XSL Formatting Objects (XSL-FO)
an XML vocabulary for specifying formatting semantics
An XSLT stylesheet specifies the presentation of a class
of XML documents by describing how an instance of the
class is transformed into an XML document that uses a
formatting vocabulary, such as (X)HTML or XSL-FO. For a
more detailed explanation of how XSL works, see the
What Is XSL page.
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 53
XSLT
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 54
In Summary…
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 55
The End
Teknoturf Info Services Pvt. Ltd. | © Copyright 2008 (Do not redistribute or reuse) Slide# 56