Docsity

XML Schemas: Understanding XML Data Types and Structure, Slides of Semantics of Programming Languages

Partial preview of the text

Download XML Schemas: Understanding XML Data Types and Structure and more Slides Semantics of Programming Languages in PDF only on Docsity!

 XML Schema

DTD Problems

 Attribute Value

 It is possible to specify all the values an attribute can

have or allow it to have any value.

 It is not possible to perform type checking on an

attribute’s value so you cannot specify an attributes

value is a integer or float…

 Does not follow xml syntax

DTD Problems

 DTDs are written in their own peculiar

syntax

 In contrast, XML Schemas use regular XML

syntax.

 As a result, any tool that can read or

process an XML document, can read and

process an XML Schema.

 Schemas have a notion of named types,

which are akin to classes; and element

declarations, which are akin to object

instances.

 Schemas also support basic inheritance

concepts, which enable you to derive new

types from existing base types.

 Schemas provide full support for XML

Namespaces.

 This is critically important, as it enables a

single instance document to reference two

or more schemas, each of which is defined

in a separate namespace.

8

XML Schemas

XML Schemas are the Successors of DTDs

 XML Schemas will be used in most Web applications as a replacement for DTDs. Here are some reasons:

 XML Schemas are extensible to future additions  XML Schemas are richer and more powerful than DTDs  XML Schemas are written in XML  XML Schemas support data types  XML Schemas support namespaces

10

XML Schemas

 XML Schemas Support Data Types

 One of their greatest strengths

 With support for data types:

 It is easier to describe allowable document content  It is easier to validate the correctness of data  It is easier to work with data from a database  It is easier to define data facets (restrictions on data)  It is easier to define data patterns (data formats)  It is easier to convert data between different data types

11

XML Schemas

 XML Schemas use XML Syntax

 Schemas are XML documents

 Benefits of Schemas as XML docs

 You don't have to learn a new language  You can use your XML editor to edit your Schema files  You can use your XML parser to parse your Schema files  You can manipulate your Schema with the XML DOM  You can transform your Schema with XSLT

13

XML Schemas

Well-Formed is not Enough

 A well-formed XML document is a document that conforms to the XML syntax rules, like:

  1. it must begin with the XML declaration
  2. it must have one unique root element
  3. start-tags must have matching end-tags
  4. elements are case sensitive
  5. all elements must be closed
  6. all elements must be properly nested
  7. all attribute values must be quoted
  8. entities must be used for special characters

14

XML Schemas

 Even if documents are well-formed they can still

contain errors, and those errors can have serious

consequences.

 The purpose of a schema is to define a class of XML documents

 and so the term "instance document" is often used to describe an XML document that conforms to a particular schema

17

XML Schemas

Simple XML Document "note.xml":

Tove Jani Reminder Don't forget me this weekend!

Start with the standard XML declaration followed by the xs:schema element that defines a schema

**

In the schema above we use the standard namespace (xs), and the URI associated with this namespace is the Schema language definition, which has the standard value of http://www.w3.org/2001/XMLSchema.

The note element is a complex type because it contains other elements. The other elements (to, from,

heading, body) are simple types because they do not contain other elements.

Tove Jani Reminder Don't forget me this weekend!