440 likes | 718 Views
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 modeling language, based on XML Not based on SGML. Definition of a Schema (cont’d).
E N D
Definition 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
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
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
XSD 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
XSD Constraints (cont’d) • Datatype constraints: • Describe the units of data that the schema considers valid
Schema Components • Prolog • Schema element • Elements • SubElements • Attributes and cardinality • Facets
The 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 • -->
The “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
The “Schema” Element (cont’d) • Includes two attributes: • Namespace attribute • Qualified or unqualified local elements
The 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
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)
Hybrid Names in Namespaces • xsd:annotation • xsd:attribute • xsd:attributeGroup • xsd:complexType • xsd:element
Hybrid Names in Namespaces (cont’d) • xsd:group • xsd:notation • xsd:sequence • xsd:simpleType
xsd: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.
xsd: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.
xsd:attributeGroup • Groups a set of attribute declarations so that they can be incorporated as a group into complex type definitions.
xsd:complexType • Defines a complex type that determines the set of attributes and content of an element.
xsd:element • Used to describe an element in a XML document.
xsd: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.
xsd: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.
xsd:sequence • Requires the elements in the group to appear in the specified sequence within the containing element.
xsd:simpleType • Defines a simple type that determines the information and constraints for the values of attributes or elements with text-only content.
elementFormDefault 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.
Element Types • simpleType • Text only • complexType • Can have sub-elements • Can have attributes
Element Attributes • abstract • block • final • fixed • Id • maxOccurs
Element Attributes (cont’d) • minOccurs • name • nillable • substitutionGroup • type
Attribute Use • <xsd:attribute name=“myname” use=“value”> • Value can be: • required • optional • prohibited
Facets • A means for providing a more precise definition for data contained within a simple type or attribute
Example 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>
Other Schema Facets • length • minLength • maxLength • maxExclusive • minExclusive
Other Schema Facets (cont’d) • duration • totalDigits • fractionDigits • whiteSpace