xml schema definition (xsd). definition of a schema it is a model for describing the structure and...

32
XML Schema Definition XML Schema Definition (XSD) (XSD)

Upload: jared-gregory

Post on 21-Jan-2016

239 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: XML Schema Definition (XSD). Definition of a Schema It is a model for describing the structure and content of data The XML Schema was developed as a content

XML Schema Definition XML Schema Definition (XSD)(XSD)

Page 2: XML Schema Definition (XSD). Definition of a Schema It is a model for describing the structure and content of data The XML Schema was developed as a content

Definition of a SchemaDefinition of a Schema• It is a model for describing the

structure and content of data• The XML Schema was developed as a

content modeling language, based on XML

• Not based on SGML

• It is a model for describing the structure and content of data

• The XML Schema was developed as a content modeling language, based on XML

• Not based on SGML

Page 3: XML Schema Definition (XSD). Definition of a Schema It is a model for describing the structure and content of data The XML Schema was developed as a content

Definition of a Schema (cont’d)Definition of a Schema (cont’d)

• The XML Schema (XSD) pertains only to XML and XML-related languages (e.g. WSDL)

• Based upon the specification found at http://www.w3.org/2001/XMLSchema

• The XML Schema (XSD) pertains only to XML and XML-related languages (e.g. WSDL)

• Based upon the specification found at http://www.w3.org/2001/XMLSchema

Page 4: XML Schema Definition (XSD). Definition of a Schema It is a model for describing the structure and content of data The XML Schema was developed as a content

An XSD:An XSD:

• Is a model for a whole class of documents• Describes the possible arrangement of elements,

attributes, and text in a schema-valid document• Models are described in terms of constraints• Provides the ability to validate a document at

machine speed• Instance documents: XML documents that

conform to a specific schema

• Is a model for a whole class of documents• Describes the possible arrangement of elements,

attributes, and text in a schema-valid document• Models are described in terms of constraints• Provides the ability to validate a document at

machine speed• Instance documents: XML documents that

conform to a specific schema

Page 5: XML Schema Definition (XSD). Definition of a Schema It is a model for describing the structure and content of data The XML Schema was developed as a content

XSD ConstraintsXSD Constraints

• A constraint defines what can appear in a given language or document

• Content model constraints: – Define the elements that can appear– Establishes a vocabulary for a class of

documents

• A constraint defines what can appear in a given language or document

• Content model constraints: – Define the elements that can appear– Establishes a vocabulary for a class of

documents

Page 6: XML Schema Definition (XSD). Definition of a Schema It is a model for describing the structure and content of data The XML Schema was developed as a content

XSD Constraints (cont’d)XSD Constraints (cont’d)

• Datatype constraints:– Describe the units of data that the

schema considers valid

• Datatype constraints:– Describe the units of data that the

schema considers valid

Page 7: XML Schema Definition (XSD). Definition of a Schema It is a model for describing the structure and content of data The XML Schema was developed as a content

Schema ComponentsSchema Components

• Prolog• Schema element• Elements• SubElements• Attributes and cardinality• Facets

• Prolog• Schema element• Elements• SubElements• Attributes and cardinality• Facets

Page 8: XML Schema Definition (XSD). Definition of a Schema It is a model for describing the structure and content of data The XML Schema was developed as a content

The Schema PrologThe Schema Prolog

• Consists of the declaration and zero or more comment lines

• Declaration:– <?xml version=“1.0” encoding=“utf-8”?>

• Comment::– <!– edited with Visual Studio .NET by Prof. Hull– -->

• Consists of the declaration and zero or more comment lines

• Declaration:– <?xml version=“1.0” encoding=“utf-8”?>

• Comment::– <!– edited with Visual Studio .NET by Prof. Hull– -->

Page 9: XML Schema Definition (XSD). Definition of a Schema It is a model for describing the structure and content of data The XML Schema was developed as a content

The “Schema” ElementThe “Schema” Element

• Usually represented as <xsd:schema …> • The schema definition ends with </xsd:schema>• Is equivalent to the root element of an XML

document• Therefore, it is the parent element of all other

elements in the schema• These other elements, or sub-elements, are

referred to as child elements in XML documents

• Usually represented as <xsd:schema …> • The schema definition ends with </xsd:schema>• Is equivalent to the root element of an XML

document• Therefore, it is the parent element of all other

elements in the schema• These other elements, or sub-elements, are

referred to as child elements in XML documents

Page 10: XML Schema Definition (XSD). Definition of a Schema It is a model for describing the structure and content of data The XML Schema was developed as a content

The “Schema” Element (cont’d)The “Schema” Element (cont’d)

• Includes two attributes:– Namespace attribute– Qualified or unqualified local elements

• Includes two attributes:– Namespace attribute– Qualified or unqualified local elements

Page 11: XML Schema Definition (XSD). Definition of a Schema It is a model for describing the structure and content of data The XML Schema was developed as a content

The Namespace AttributeThe Namespace Attribute

• <xsd:schema xmlns:http://www.w3.org/2001/XMLSchema elementFormDefault=“qualified”>

• The bolded portion is the namespace declaration• This assignment indicates to the XML processor that

definitions and treatments of elements and other datatypes in the schema are adopted from the W3C’s Namespace Recommendation

• The xmlns attribute specifies the alias to be used throughout the schema to reference the Recommendation

• When the XML processor encounters the alias name “xsd”, it uses the definitions in the Recommendation

• <xsd:schema xmlns:http://www.w3.org/2001/XMLSchema elementFormDefault=“qualified”>

• The bolded portion is the namespace declaration• This assignment indicates to the XML processor that

definitions and treatments of elements and other datatypes in the schema are adopted from the W3C’s Namespace Recommendation

• The xmlns attribute specifies the alias to be used throughout the schema to reference the Recommendation

• When the XML processor encounters the alias name “xsd”, it uses the definitions in the Recommendation

Page 12: XML Schema Definition (XSD). Definition of a Schema It is a model for describing the structure and content of data The XML Schema was developed as a content

The Namespace Attribute (cont’d)The Namespace Attribute (cont’d)

• Each namespace represents a collection of element types and other data types

• It is represented by a unique name• That unique name takes the form of a URL• The URL is used only as a name, not as a

location on the Internet (browsers are not invoked)

• Each namespace represents a collection of element types and other data types

• It is represented by a unique name• That unique name takes the form of a URL• The URL is used only as a name, not as a

location on the Internet (browsers are not invoked)

Page 13: XML Schema Definition (XSD). Definition of a Schema It is a model for describing the structure and content of data The XML Schema was developed as a content

Hybrid Names in NamespacesHybrid Names in Namespaces

• xsd:annotation

• xsd:attribute

• xsd:attributeGroup

• xsd:complexType

• xsd:element

• xsd:annotation

• xsd:attribute

• xsd:attributeGroup

• xsd:complexType

• xsd:element

Page 14: XML Schema Definition (XSD). Definition of a Schema It is a model for describing the structure and content of data The XML Schema was developed as a content

Hybrid Names in Namespaces (cont’d)

Hybrid Names in Namespaces (cont’d)

• xsd:group

• xsd:notation

• xsd:sequence

• xsd:simpleType

• xsd:group

• xsd:notation

• xsd:sequence

• xsd:simpleType

Page 15: XML Schema Definition (XSD). Definition of a Schema It is a model for describing the structure and content of data The XML Schema was developed as a content

xsd:annotationxsd:annotation

• Annotation is used to store extra information about the schema or its elements. These notes are specified for human consumption, xsd:documentation, or by software, xsd:appinfo. Annotation can be the first element of most Schema elements or anywhere under the schema element.

• Annotation is used to store extra information about the schema or its elements. These notes are specified for human consumption, xsd:documentation, or by software, xsd:appinfo. Annotation can be the first element of most Schema elements or anywhere under the schema element.

Page 16: XML Schema Definition (XSD). Definition of a Schema It is a model for describing the structure and content of data The XML Schema was developed as a content

xsd:attributexsd:attribute

• Attributes provide additional information for other document elements. The attribute tag is nested in between the tags of a document’s element for the schema. The XML document displays attributes as named item in the opening tag of an element.

• Attributes provide additional information for other document elements. The attribute tag is nested in between the tags of a document’s element for the schema. The XML document displays attributes as named item in the opening tag of an element.

Page 17: XML Schema Definition (XSD). Definition of a Schema It is a model for describing the structure and content of data The XML Schema was developed as a content

xsd:attributeGroupxsd:attributeGroup

• Groups a set of attribute declarations so that they can be incorporated as a group into complex type definitions.

• Groups a set of attribute declarations so that they can be incorporated as a group into complex type definitions.

Page 18: XML Schema Definition (XSD). Definition of a Schema It is a model for describing the structure and content of data The XML Schema was developed as a content

xsd:complexTypexsd:complexType

• Defines a complex type that determines the set of attributes and content of an element.

• Defines a complex type that determines the set of attributes and content of an element.

Page 19: XML Schema Definition (XSD). Definition of a Schema It is a model for describing the structure and content of data The XML Schema was developed as a content

xsd:elementxsd:element

• Used to describe an element in a XML document.

• Used to describe an element in a XML document.

Page 20: XML Schema Definition (XSD). Definition of a Schema It is a model for describing the structure and content of data The XML Schema was developed as a content

xsd:groupxsd:group

• Defines groups at the schema level that are referenced from the complex types. Groups a set of element declarations so that they can be incorporated as a group into complex type definitions.

• Defines groups at the schema level that are referenced from the complex types. Groups a set of element declarations so that they can be incorporated as a group into complex type definitions.

Page 21: XML Schema Definition (XSD). Definition of a Schema It is a model for describing the structure and content of data The XML Schema was developed as a content

xsd:notationxsd:notation

• An XML Schema definition language (XSD) notation declaration is a reconstruction of XML 1.0 NOTATION declarations. The purpose of notations is to describe the format of non-XML data within an XML document.

• An XML Schema definition language (XSD) notation declaration is a reconstruction of XML 1.0 NOTATION declarations. The purpose of notations is to describe the format of non-XML data within an XML document.

Page 22: XML Schema Definition (XSD). Definition of a Schema It is a model for describing the structure and content of data The XML Schema was developed as a content

xsd:sequencexsd:sequence

• Requires the elements in the group to appear in the specified sequence within the containing element.

• Requires the elements in the group to appear in the specified sequence within the containing element.

Page 23: XML Schema Definition (XSD). Definition of a Schema It is a model for describing the structure and content of data The XML Schema was developed as a content

xsd:simpleTypexsd:simpleType

• Defines a simple type that determines the information and constraints for the values of attributes or elements with text-only content.

• Defines a simple type that determines the information and constraints for the values of attributes or elements with text-only content.

Page 24: XML Schema Definition (XSD). Definition of a Schema It is a model for describing the structure and content of data The XML Schema was developed as a content

elementFormDefault PropertyelementFormDefault Property

• Gets or sets the form for elements declared in the target namespace of the schema.

• Two values for this property:– Qualified Elements from the target namespace

must be qualified with the namespace prefix. Unqualified Elements from the target namespace are not required to be qualified with the namespace prefix.

• Gets or sets the form for elements declared in the target namespace of the schema.

• Two values for this property:– Qualified Elements from the target namespace

must be qualified with the namespace prefix. Unqualified Elements from the target namespace are not required to be qualified with the namespace prefix.

Page 25: XML Schema Definition (XSD). Definition of a Schema It is a model for describing the structure and content of data The XML Schema was developed as a content

Element TypesElement Types

• simpleType– Text only

• complexType– Can have sub-elements– Can have attributes

• simpleType– Text only

• complexType– Can have sub-elements– Can have attributes

Page 26: XML Schema Definition (XSD). Definition of a Schema It is a model for describing the structure and content of data The XML Schema was developed as a content

Element AttributesElement Attributes

• abstract• block• final• fixed• Id• maxOccurs

• abstract• block• final• fixed• Id• maxOccurs

Page 27: XML Schema Definition (XSD). Definition of a Schema It is a model for describing the structure and content of data The XML Schema was developed as a content

Element Attributes (cont’d)Element Attributes (cont’d)

• minOccurs

• name

• nillable

• substitutionGroup

• type

• minOccurs

• name

• nillable

• substitutionGroup

• type

Page 28: XML Schema Definition (XSD). Definition of a Schema It is a model for describing the structure and content of data The XML Schema was developed as a content

Attribute UseAttribute Use

• <xsd:attribute name=“myname” use=“value”>

• Value can be:– required– optional– prohibited

• <xsd:attribute name=“myname” use=“value”>

• Value can be:– required– optional– prohibited

Page 29: XML Schema Definition (XSD). Definition of a Schema It is a model for describing the structure and content of data The XML Schema was developed as a content

FacetsFacets

• A means for providing a more precise definition for data contained within a simple type or attribute

• A means for providing a more precise definition for data contained within a simple type or attribute

Page 30: XML Schema Definition (XSD). Definition of a Schema It is a model for describing the structure and content of data The XML Schema was developed as a content

Example of a FacetExample of a Facet

• <xsd:element name=“myElem”>• <xsd:simpleType>• <xsd:restriction base=“xsd:integer”>• <xsd:minInclusive value=“1” />• <xsd:maxInclusive value = “999” />• </xsd:restriction>• </xsd:simpleType>• </xsd:element>

• <xsd:element name=“myElem”>• <xsd:simpleType>• <xsd:restriction base=“xsd:integer”>• <xsd:minInclusive value=“1” />• <xsd:maxInclusive value = “999” />• </xsd:restriction>• </xsd:simpleType>• </xsd:element>

Page 31: XML Schema Definition (XSD). Definition of a Schema It is a model for describing the structure and content of data The XML Schema was developed as a content

Other Schema FacetsOther Schema Facets

• length

• minLength

• maxLength

• maxExclusive

• minExclusive

• length

• minLength

• maxLength

• maxExclusive

• minExclusive

Page 32: XML Schema Definition (XSD). Definition of a Schema It is a model for describing the structure and content of data The XML Schema was developed as a content

Other Schema Facets (cont’d)Other Schema Facets (cont’d)

• duration

• totalDigits

• fractionDigits

• whiteSpace

• duration

• totalDigits

• fractionDigits

• whiteSpace