Q5M1 - XML Dudy Fathan Ali S.Kom
XML Schema
Q5M1 - XML
Dudy Fathan Ali, S.Kom (DFA)
2015
CEP - CCIT
Fakultas Teknik Universitas Indonesia
Introducing XML Schema
Q5M1 - XML Dudy Fathan Ali S.Kom
An XML schema defines the list of elements and attributes that
can be used in an XML document.
An XML schema specifies the order in which the elements
appear in the XML document, and their data types.
Microsoft has developed the XML Schema Definition (XSD)
language to define the schema of an XML document.
Advantages of XML Schema Created Using XSDs
Q5M1 - XML Dudy Fathan Ali S.Kom
Some of the advantages of creating an XML schema by using XSD
are:
XSD provides control over the type of data that can be assigned to
elements and attributes.
XSD enables you to create your own data types.
XSD enables you to specify restrictions on data.
The syntax for defining an XSD is the same as the syntax used for
XML documents.
XML schema content models can be used to validate mixed
content.
XML schema is extensible.
XML schema is self documenting.
Support for XML Schemas in Various Parsers
Q5M1 - XML Dudy Fathan Ali S.Kom
Parsers that provide support for XML schemas are:
IBM XML4J: Validates XML documents against several types of XML
schemas.
MSXML 6.0: Enables loading of XML data from anonymous or
untrusted sources in a secured manner.
Data Types in XML Schemas
Q5M1 - XML Dudy Fathan Ali S.Kom
In an XML schema created using XSD, every element must be
associated with a data type.
XSD provides the following list of predefined data types:
Primitive
Derived
Atomic
List
Union
Data Types in XML Schemas
Q5M1 - XML Dudy Fathan Ali S.Kom
In an XML schema created using XSD, every element must be
associated with a data type.
XSD provides the following list of predefined data types:
Primitive
Derived
Atomic
List
Union
Data Types in XML Schemas
Q5M1 - XML Dudy Fathan Ali S.Kom
In an XML schema created using XSD, every element must be
associated with a data type.
XSD provides the following list of predefined data types:
Primitive
Derived
Atomic
List
Union
Data Types in XML Schemas
Q5M1 - XML Dudy Fathan Ali S.Kom
In an XML schema created using XSD, every element must be
associated with a data type.
XSD provides the following list of predefined data types:
Primitive
Derived
Atomic
List
Union
Cannot be broken down into smaller units.
Can be primitive or derived.
Data Types in XML Schemas
Q5M1 - XML Dudy Fathan Ali S.Kom
In an XML schema created using XSD, every element must be
associated with a data type.
XSD provides the following list of predefined data types:
Primitive
Derived
Atomic
List
Union
Are derived data types that contain a set of values of
atomic data types.
Elements referring to a list data type can contain a
value only from that defined set.
Data Types in XML Schemas
Q5M1 - XML Dudy Fathan Ali S.Kom
In an XML schema created using XSD, every element must be
associated with a data type.
XSD provides the following list of predefined data types:
Primitive
Derived
Atomic
List
Union Are derived from the atomic and list data
types.
Elements in XML Schemas
Q5M1 - XML Dudy Fathan Ali S.Kom
There are two types of elements, simple and complex that can be
defined in a schema.
Simple Element
A simple element does not contain any child elements or
attributes.
It contains only values, such as numbers, strings, and dates.
You can specify restrictions on elements by defining a new
simple data type from an existing data type using facet values.
You can also associate an element with a simple data type.
Elements in XML Schemas
Q5M1 - XML Dudy Fathan Ali S.Kom
Simple Element
• prodid
• productname
• description
• price
• quantity
Elements in XML Schemas
Q5M1 - XML Dudy Fathan Ali S.Kom
Complex Element
A complex element contains other elements, attributes, and mixed
content.
To declare a complex element, you need to first define a complex
data type.
After defining the complex data type, you can declare a complex
element by associating this data type with the element.
Elements in XML Schemas
Q5M1 - XML Dudy Fathan Ali S.Kom
Complex Element
• productdata
• product
Syntax for declaring simple element
Elements in XML Schemas
Q5M1 - XML Dudy Fathan Ali S.Kom
<xsd:element
name=“element-name"
type="data type"
min0ccurs="nonNegativeInteger“
max0ccurs="nonNegativeInteger|unbounded“
/>
The name attribute specifies the name of the element declared.
The type attribute specifies the data type of the element declared.
minOccurs specifies the minimum number of times the element can occur.
maxOccurs specifies the maximum number of times the element can appear.
Elements in XML Schemas
Q5M1 - XML Dudy Fathan Ali S.Kom
Simple element declaration code:
Syntax for declaring complex element
Elements in XML Schemas
Q5M1 - XML Dudy Fathan Ali S.Kom
<xsd:complexType name="data type name">
Content model declaration
</xsd:complexType>
The complexType element is used to declare a new complex data type.
The name attribute specifies the name of the new complex data type.
The Content model declaration contains the declaration for the
elements and attributes that make up the content of the complex type.
Elements in XML Schemas
Q5M1 - XML Dudy Fathan Ali S.Kom
Complex element declaration code:
Elements in XML Schemas
Q5M1 - XML Dudy Fathan Ali S.Kom
Full XSD Schema
XML Namespace
Q5M1 - XML Dudy Fathan Ali S.Kom
In XML, a namespace is a virtual space that is assigned or recognized
by a Uniform Resource Identifier (URI).
A namespace is a string that uniquely identifies the elements and
attributes from different schemas.
A namespace is a unique identifier used to resolve conflicts between
elements that have the same names.
The following guidelines ensure the uniqueness of a URI:
Using a URI that is controlled by the developer.
Using a relative URI.
XML Namespace
Q5M1 - XML Dudy Fathan Ali S.Kom
A namespace can be declared in an XSD document by using the xmlns
keyword.
The general form of the xmlns keyword is:
xmlns:prefix="URI“
There are two types of namespace declarations:
Default Declaration: Declares a default namespace for a document
without specifying the prefix for a default namespace.
Explicit Declaration: Enables xmlns keyword to associate a prefix
with a namespace.
xmlns is the name of the attribute.
prefix is an optional namespace.
Q5M1 - XML Dudy Fathan Ali S.Kom
Terima Kasih
Dudy Fathan Ali S.Kom
dudy.fathan@eng.ui.ac.id

XML Schema Part 1

  • 1.
    Q5M1 - XMLDudy Fathan Ali S.Kom XML Schema Q5M1 - XML Dudy Fathan Ali, S.Kom (DFA) 2015 CEP - CCIT Fakultas Teknik Universitas Indonesia
  • 2.
    Introducing XML Schema Q5M1- XML Dudy Fathan Ali S.Kom An XML schema defines the list of elements and attributes that can be used in an XML document. An XML schema specifies the order in which the elements appear in the XML document, and their data types. Microsoft has developed the XML Schema Definition (XSD) language to define the schema of an XML document.
  • 3.
    Advantages of XMLSchema Created Using XSDs Q5M1 - XML Dudy Fathan Ali S.Kom Some of the advantages of creating an XML schema by using XSD are: XSD provides control over the type of data that can be assigned to elements and attributes. XSD enables you to create your own data types. XSD enables you to specify restrictions on data. The syntax for defining an XSD is the same as the syntax used for XML documents. XML schema content models can be used to validate mixed content. XML schema is extensible. XML schema is self documenting.
  • 4.
    Support for XMLSchemas in Various Parsers Q5M1 - XML Dudy Fathan Ali S.Kom Parsers that provide support for XML schemas are: IBM XML4J: Validates XML documents against several types of XML schemas. MSXML 6.0: Enables loading of XML data from anonymous or untrusted sources in a secured manner.
  • 5.
    Data Types inXML Schemas Q5M1 - XML Dudy Fathan Ali S.Kom In an XML schema created using XSD, every element must be associated with a data type. XSD provides the following list of predefined data types: Primitive Derived Atomic List Union
  • 6.
    Data Types inXML Schemas Q5M1 - XML Dudy Fathan Ali S.Kom In an XML schema created using XSD, every element must be associated with a data type. XSD provides the following list of predefined data types: Primitive Derived Atomic List Union
  • 7.
    Data Types inXML Schemas Q5M1 - XML Dudy Fathan Ali S.Kom In an XML schema created using XSD, every element must be associated with a data type. XSD provides the following list of predefined data types: Primitive Derived Atomic List Union
  • 8.
    Data Types inXML Schemas Q5M1 - XML Dudy Fathan Ali S.Kom In an XML schema created using XSD, every element must be associated with a data type. XSD provides the following list of predefined data types: Primitive Derived Atomic List Union Cannot be broken down into smaller units. Can be primitive or derived.
  • 9.
    Data Types inXML Schemas Q5M1 - XML Dudy Fathan Ali S.Kom In an XML schema created using XSD, every element must be associated with a data type. XSD provides the following list of predefined data types: Primitive Derived Atomic List Union Are derived data types that contain a set of values of atomic data types. Elements referring to a list data type can contain a value only from that defined set.
  • 10.
    Data Types inXML Schemas Q5M1 - XML Dudy Fathan Ali S.Kom In an XML schema created using XSD, every element must be associated with a data type. XSD provides the following list of predefined data types: Primitive Derived Atomic List Union Are derived from the atomic and list data types.
  • 11.
    Elements in XMLSchemas Q5M1 - XML Dudy Fathan Ali S.Kom There are two types of elements, simple and complex that can be defined in a schema. Simple Element A simple element does not contain any child elements or attributes. It contains only values, such as numbers, strings, and dates. You can specify restrictions on elements by defining a new simple data type from an existing data type using facet values. You can also associate an element with a simple data type.
  • 12.
    Elements in XMLSchemas Q5M1 - XML Dudy Fathan Ali S.Kom Simple Element • prodid • productname • description • price • quantity
  • 13.
    Elements in XMLSchemas Q5M1 - XML Dudy Fathan Ali S.Kom Complex Element A complex element contains other elements, attributes, and mixed content. To declare a complex element, you need to first define a complex data type. After defining the complex data type, you can declare a complex element by associating this data type with the element.
  • 14.
    Elements in XMLSchemas Q5M1 - XML Dudy Fathan Ali S.Kom Complex Element • productdata • product
  • 15.
    Syntax for declaringsimple element Elements in XML Schemas Q5M1 - XML Dudy Fathan Ali S.Kom <xsd:element name=“element-name" type="data type" min0ccurs="nonNegativeInteger“ max0ccurs="nonNegativeInteger|unbounded“ /> The name attribute specifies the name of the element declared. The type attribute specifies the data type of the element declared. minOccurs specifies the minimum number of times the element can occur. maxOccurs specifies the maximum number of times the element can appear.
  • 16.
    Elements in XMLSchemas Q5M1 - XML Dudy Fathan Ali S.Kom Simple element declaration code:
  • 17.
    Syntax for declaringcomplex element Elements in XML Schemas Q5M1 - XML Dudy Fathan Ali S.Kom <xsd:complexType name="data type name"> Content model declaration </xsd:complexType> The complexType element is used to declare a new complex data type. The name attribute specifies the name of the new complex data type. The Content model declaration contains the declaration for the elements and attributes that make up the content of the complex type.
  • 18.
    Elements in XMLSchemas Q5M1 - XML Dudy Fathan Ali S.Kom Complex element declaration code:
  • 19.
    Elements in XMLSchemas Q5M1 - XML Dudy Fathan Ali S.Kom Full XSD Schema
  • 20.
    XML Namespace Q5M1 -XML Dudy Fathan Ali S.Kom In XML, a namespace is a virtual space that is assigned or recognized by a Uniform Resource Identifier (URI). A namespace is a string that uniquely identifies the elements and attributes from different schemas. A namespace is a unique identifier used to resolve conflicts between elements that have the same names. The following guidelines ensure the uniqueness of a URI: Using a URI that is controlled by the developer. Using a relative URI.
  • 21.
    XML Namespace Q5M1 -XML Dudy Fathan Ali S.Kom A namespace can be declared in an XSD document by using the xmlns keyword. The general form of the xmlns keyword is: xmlns:prefix="URI“ There are two types of namespace declarations: Default Declaration: Declares a default namespace for a document without specifying the prefix for a default namespace. Explicit Declaration: Enables xmlns keyword to associate a prefix with a namespace. xmlns is the name of the attribute. prefix is an optional namespace.
  • 22.
    Q5M1 - XMLDudy Fathan Ali S.Kom Terima Kasih Dudy Fathan Ali S.Kom dudy.fathan@eng.ui.ac.id