XML Schema: Understanding Simple and Complex Types, Slides of Semantics of Programming Languages

An overview of xml schema, focusing on the classification of components as simple or complex types. It explains how to determine content models, discusses the library book xml example, and covers the definition of elements and attributes using xs:element and xs:complextype. The document also introduces the concepts of minoccurs and maxoccurs attributes, and explains the difference between global and local components.

Typology: Slides

2011/2012

Uploaded on 07/11/2012

dharuna
dharuna 🇮🇳

4.7

(6)

85 documents

1 / 30

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
XML Schema Discussions
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e

Partial preview of the text

Download XML Schema: Understanding Simple and Complex Types and more Slides Semantics of Programming Languages in PDF only on Docsity!

XML Schema Discussions

  • to determine the content model
  • pay attention only to the element and text nodes and ignore any attribute, comment, or processing instruction that could be included
  • For instance, an element with some attributes, a comment, and a couple of processing instructions would have an "empty" content model if it has no text or element children.
  • W3C XML Schema considers the elements that have a simple content model and no attributes "simple types,“
  • while all the other elements (such as simple content with attributes and other content models) are "complex types."
  • In other words, when an element can only have text nodes and doesn't accept any child elements or attributes, it is considered a simple type;
  • in all the other cases, it is a complex type
  • Attributes always have a simple type since they have no children and contain only a text value.
  • Now that we have criteria to classify our components, we can define each of them.
  • To define such an element, we use an xs:element(global definition), included directly under the xs:schema document element:
  • Since this element has an attribute, it has a complex type. Since it has only a text node, it is considered to have a simple content. We will, therefore, write its definition as:
  • The library element, the most straightforward of them, is defined as:

This definition can be read as "the element named library is a complex type composed of a sequence of 1 to many occurrences (note the maxOccurs attribute) of elements defined as having a name book." Docsity.com

  • minOccurs and maxOccurs attributes
  • allow us to define the minimum and maximum number of occurrences.
  • Their default value is 1, which means that when they are both missing, the element must appear exactly one time in the sequence.
  • The special value "unbounded" may be used for maxOccurs when the maximum number of occurrences is unlimited.
  • The attributes need to be defined after the sequence. The remaining elements (book and character) can be defined in the same way, which leads us to the following full schema:
  • Components defined directly under the xs:schema document element are called "global" components.
  • These have a couple of notable properties:
    • they can be referenced anywhere in the schema as well as in the other schema that may include or import this schema
    • and all the global elements can be used as document root elements.
  • second attempt will give it more depth and show how local components may be defined

Advantages…

  • Because the definition of the book element is contained inside the definition of the library element, other definitions of book elements could be done at other locations in the schema without any risk of confusion—except maybe by human readers.
  • We can also reiterate the same operation and perform the definitions of all the elements and all the attributes locally:
  • It is not, strictly speaking, equivalent to the first one: it is less reusable (the document element is the only one that could be reused in another schema) and more strict, since it validates only the documents that have a library document element.