xml schema part 1

22
Q5M1 - XML Dudy Fathan Ali S.Kom XML Schema Q5M1 - XML Dudy Fathan Ali, S.Kom (DFA) 2015 CEP - CCIT Fakultas Teknik Universitas Indonesia

Upload: dudy-ali

Post on 11-Apr-2017

43 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: XML Schema Part 1

Q5M1 - XML Dudy Fathan Ali S.Kom

XML SchemaQ5M1 - XML

Dudy Fathan Ali, S.Kom (DFA)2015

CEP - CCITFakultas Teknik Universitas Indonesia

Page 2: XML Schema Part 1

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.

Page 3: XML Schema Part 1

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.

Page 4: XML Schema Part 1

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.

Page 5: XML Schema Part 1

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:

PrimitiveDerivedAtomicListUnion

Page 6: XML Schema Part 1

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:

PrimitiveDerivedAtomicListUnion

Page 7: XML Schema Part 1

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:

PrimitiveDerivedAtomicListUnion

Page 8: XML Schema Part 1

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:

PrimitiveDerivedAtomicListUnion

Cannot be broken down into smaller units.

Can be primitive or derived.

Page 9: XML Schema Part 1

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:

PrimitiveDerivedAtomicListUnion

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.

Page 10: XML Schema Part 1

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:

PrimitiveDerivedAtomicListUnion Are derived from the atomic and list data

types.

Page 11: XML Schema Part 1

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.

Page 12: XML Schema Part 1

Elements in XML Schemas

Q5M1 - XML Dudy Fathan Ali S.Kom

Simple Element• prodid• productname• description• price• quantity

Page 13: XML Schema Part 1

Elements in XML Schemas

Q5M1 - XML Dudy Fathan Ali S.Kom

Complex ElementA 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.

Page 14: XML Schema Part 1

Elements in XML Schemas

Q5M1 - XML Dudy Fathan Ali S.Kom

Complex Element• productdata• product

Page 15: XML Schema Part 1

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.

Page 16: XML Schema Part 1

Elements in XML Schemas

Q5M1 - XML Dudy Fathan Ali S.Kom

Simple element declaration code:

Page 17: XML Schema Part 1

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.

Page 18: XML Schema Part 1

Elements in XML Schemas

Q5M1 - XML Dudy Fathan Ali S.Kom

Complex element declaration code:

Page 19: XML Schema Part 1

Elements in XML Schemas

Q5M1 - XML Dudy Fathan Ali S.Kom

Full XSD Schema

Page 20: XML Schema Part 1

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.

Page 21: XML Schema Part 1

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.

Page 22: XML Schema Part 1

Q5M1 - XML Dudy Fathan Ali S.Kom

Terima KasihDudy Fathan Ali S.Kom

[email protected]