Section 07
Section 07
XML the eXtensible Markup Language has become the lingua franca of the internet.
It is an HTML like language that allows the exchange of arbitrary data in ASCII format
via a media of your choice. SOAP the Simple Object Access protocol is a document
structure defined in XML with the purpose to transport object interfaces between
distributed applications.
Chapter Contents
XML Extended Markup Language
XML Schemas
1.
XML is known as the lingua franca of the internet. It is a plain text language, like HTML, which
is structured but also human readable at the same time. A structured language is a
precondition for efficient and deterministic automated processing, while the human readability
makes error processing much easier when the automated processing failed for some reason.
XML Farm
This is a simple example of how to define a two dimensional database table in XML.
A table like this
20
Name
Cow
Pig
Weight
420
120
Gender
F
M
A DTD is another XML block that describes the content of the following data.
<?xml version="1.0" encoding="UTF-8"?>
<Schema
xmlns="urn:schemas-microsoft-com:xml-data"
xmlns:dt="urn:schemas-microsoftcom:datatypes">
<ElementType name="Name" content="textOnly" dt:type="string"/>
<ElementType name="Family" content="textOnly" dt:type="string"/>
<ElementType name="Weight" content="textOnly" dt:type="int"/>
<ElementType name="Gender" content="textOnly" dt:type="string"/>
<ElementType name="Animal" content="mixed">
<element type="Name" minOccurs="1" maxOccurs="*"/>
<element type="Family" minOccurs="1" maxOccurs="*"/>
<element type="Weight" minOccurs="1" maxOccurs="*"/>
<element type="Gender" minOccurs="1" maxOccurs="*"/>
</ElementType>
<ElementType name="Farm" content="mixed">
<element type="Animal" minOccurs="1" maxOccurs="*"/>
</ElementType>
</Schema>
XML Schema
An XML Schema for the animal farm may look like this:
2 of 8
XML Schemas
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsd:schema PUBLIC "-//W3C//DTD XMLSCHEMA 19991216//EN" "" [
<!ENTITY % p 'xsd:'>
<!ENTITY % s ':xsd'>
]>
<xsd:schema xmlns:xsd="http://www.w3.org/1999/XMLSchema">
<xsd:complexType name="TyFamily" content="elementOnly">
<xsd:sequence>
<xsd:element name="TyName">
<xsd:simpleType base="xsd:string">
<xsd:enumeration value="Cow"/>
<xsd:enumeration value="Pig"/>
</xsd:simpleType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="TyGender" content="elementOnly">
<xsd:sequence>
<xsd:element name="TyGender">
<xsd:simpleType base="xsd:string">
<xsd:enumeration value="F"/>
<xsd:enumeration value="M"/>
</xsd:simpleType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="AnimalType" content="elementOnly">
<xsd:sequence>
<xsd:element name="Family" type="TyFamily"/>
<xsd:element name="Weight" type="xsd:short"/>
<xsd:element name="Gender" type="TyGender"/>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="Farm">
<xsd:complexType content="elementOnly">
<xsd:sequence>
<xsd:element name="Animal" type="AnimalType"
minOccurs="1" maxOccurs="unbounded"/>
</xsd:sequence>
<xsd:attribute name="xmlns:xsi"
type="xsd:uriReference" use="default"
value="http://www.w3.org/1999/XMLSchema-instance"/>
<xsd:attribute name="xsi:noNamespaceSchemaLocation"
type="xsd:string"/>
<xsd:attribute name="xsi:schemaLocation"
type="xsd:string"/>
</xsd:complexType>
</xsd:element>
</xsd:schema>
30
You may find it helpful to see, that a schema is more or less analogous to the type declaration
section of any modern programming language, like as in the table below. However, the XML
schemas allow a much more complex attribute setting to any type.
ABAP IV
Visual Basic
Types:
TyFamily
C(12)
Public
Enum
TyFamily
Cow = 1
Pig = 2
End Enum
Types:
TyGender
Type
Type
XML Schema
Public
Enum
TyGender
3 of 8
C(1)
male = 1
female = 2
End Enum
Types:
Begin Of Animal
Name(32),
Family
Type
TyFamily,
Weight Type P,
Gender
Type
TyGender,
End Of Animal.
Public
Type
Animal
Name
As
String
Family
As
TyFamily
Weight As
Long
Gender As
TyGender
End Type
<ElementType
content="mixed">
<element type="Name"/>
<element type="Family"/>
<element type="Weight"/>
<element type="Gender"/>
</ElementType>
name="Animal"
40
4 of 8
XML Schemas
XML Schemas
XML is a plain ASCII document format meant to exchange data between correspondents. In
order to create large distributed projects you should sooner or later become familiar
50
with XML. Therefore we introduce some tools to facilitate working with XML.
Schema
The next major step is to create a schema which is a formal way of defining and validating the
content of an XML document. (A well-formed XML document that conforms to its schema is
said to be valid.)
60
The schema is how we assign the data types to each tag and any attributes that are contained
in the XML document. A schema is a structured document which must obey XML syntax rules.
It is composed of a series of predefined tags and attributes that are part of the XML language
and are used to set the data types for the values associated with our custom tags. Simply put,
not only do we get to create custom XML tags, but we can also denote that an XML data value
is, for example, an integer data type. This ability to assign specfic data types to specific XML
data values is one of the reasons why XML has attracted so much attention.
A schema can be part of the XML document or a separate file. For our examples, we will
create a separate schema file to allow you to view the resultant document.
70
Fortunately, if you can write HTML code, you can write a schema document. Here are the XML
tags and attributes that we will use to create a schema:
Schema
The Schema tag serves as a container element that delimits the beginning and end of the
schema. This tag must be closed and please note the exact spelling with regard to case.
80
xmlns
The xmlns attribute is used to declare the schema XML namespace. The value is a URL or
URN address that the browser will access to get information on how to parse and validate the
code.
xmlns:dt
The xmlns:dt attribute is used to declare the data types of the schema XML namespace. The
value is a URL or URN address that the browser will access to get information on the data
types to allow code validation.
If you are using IE 5 to view your XML document, then you must include the xmlns and the
xmlns:dt attributes exactly as displayed below:
90
name
The name attribute provides the name of the attribute.
5 of 8
non-positiveinteger
Boolean
positiveinteger
byte
recurringInst
ant
date
short
decimal
string
double
time
float
timeDuration
int
timeInstant
integer
unsignedbyte
long
unsigned-int
negativeinteger
unsignedlong
non-negativeinteger
attribute
The attribute tag is used to associate a previously data typed attribute to a tag. This tag must
be closed and please note the exact spelling with regard to case.
110
type
The type attribute provides the data type of the custom attribute.
ElementType
The ElementType tag is used to declare the data type for a custom XML tag. This tag must be
closed and please note the exact spelling with regard to case.
120
content
The content attribute describes the intended content of the XML tag. There are four permitted
values:
T
y
p
e
e
lt
O
6 of 8
Description
XML Schemas
n
l
y
e
m
p
t
y
Contains no content
m
i
x
e
d
t
e
x
t
O
n
l
y
name
The name attribute provides the name of the tag (element).
130
dt:type
The dt:type attribute dictates the data type of the tag (element). The twenty three permitted
values are:
binary
non-positiveinteger
Boolean
positiveinteger
byte
recurringInst
ant
date
short
decimal
string
double
time
float
timeDuration
int
timeInstant
integer
unsignedbyte
long
unsigned-int
negativeinteger
unsignedlong
7 of 8
non-negativeinteger
element
The element tag is used to associate a previously data typed tag to an element. This tag must
be closed and please note the exact spelling with regard to case.
type
The type attribute provides the type of the custom XML element.
140
8 of 8