Download presentation
Presentation is loading. Please wait.
1
Sunday, June 28, 2015 Abdelali ZAHI : FALL 2003 : XML Schemas XML Schemas Presented By : Abdelali ZAHI Instructor : Dr H.Haddouti
2
Sunday, June 28, 2015 Abdelali ZAHI : FALL 2003 : XML Schemas Terms and Concepts Schema: In database : refers to the organization or structure for a database In XML community : refers to the structure (or model of a class of documents). This model describes the hierarchy of elements and allowable content in a valid XML document the schema defines constraints for an XML vocabulary. XML Schema is a formal definition for defining a schema for a class of XML documents.
3
Sunday, June 28, 2015 Abdelali ZAHI : FALL 2003 : XML Schemas Purpose Provide a document for validation Extend the functionality of DTDs Define datatypes Define elements and their content Define attributes and their values Define reusable components and their contents Introduce notations
4
Sunday, June 28, 2015 Abdelali ZAHI : FALL 2003 : XML Schemas Design Principles More expressive than XML DTDs Expressed in XML Self-describing Usable in a wide variety of applications that employ XML Straightforwardly usable on the Internet Optimized for interoperability Simple enough to implement with modest design and runtime resources
5
Sunday, June 28, 2015 Abdelali ZAHI : FALL 2003 : XML Schemas Datatype Requirements Provide for primitive datatyping, including byte, date, integer, sequence, and SQL datatypes. Allow creation of user-derived datatypes, such as datatypes that are derived from an existing datatype and that may constrain some of its properties.
6
Sunday, June 28, 2015 Abdelali ZAHI : FALL 2003 : XML Schemas Well-formedness vs validity A document is considered to be well formed if it meets all the well- following constraints: The document contains one or more elements. The document consists of exactly one root element (also known as the document element). The name of an element’s end tag matches the name defined in the start tag. No attribute may appear more than once within an element. Attribute values cannot contain a left-angle bracket (<). Elements delimited with start and end tags must nest properly within each other. an XML document is valid if it adheres to a defined model for a class of XML documents
7
Sunday, June 28, 2015 Abdelali ZAHI : FALL 2003 : XML Schemas Terms and concepts data primitives: basic types to associate with values (integer, real number, character, string…etc) schema components: building blocks that make up the abstract data model of the schema (Element and attribute declarations, complex types, simple types, notations…)
8
Sunday, June 28, 2015 Abdelali ZAHI : FALL 2003 : XML Schemas XML SCHEMA STRUCTURES
9
Sunday, June 28, 2015 Abdelali ZAHI : FALL 2003 : XML Schemas Definitions vs. Declarations A definition describes a complex or simple type that either contains element or attribute declarations or references element or attribute declarations defined elsewhere in the document. Here’s a definition: A declaration defines an element or attribute, specifying the name and datatype for the component. Here’s a declaration:
10
Sunday, June 28, 2015 Abdelali ZAHI : FALL 2003 : XML Schemas Simple Type vs. Complex Type A simple type definition constrains the text that is allowed to appear as content for an attribute value or text-only element without attributes. Here’s a simple type definition: A complex type definition constrains the allowable content of elements. Both types govern possible attribute and child elements. Here’s a complex type definition:
11
Sunday, June 28, 2015 Abdelali ZAHI : FALL 2003 : XML Schemas Global vs. Local Declarations and definitions can be declared globally or locally. A globally defined component is defined as a child of the schema element. A locally defined component (also known as inline) is defined as a child of another schema component.
12
Sunday, June 28, 2015 Abdelali ZAHI : FALL 2003 : XML Schemas Global Component <xsd:schema xmlns:xsd=http://www.w3.org/2001/XMLSchema elementFormDefault=”qualified”http://www.w3.org/2001/XMLSchema targetNamespace=http://www.lanw.com/namespaces/pubhttp://www.lanw.com/namespaces/pub xmlns=” http://www.lanw.com/namespaces/pub ”>http://www.lanw.com/namespaces/pub
13
Sunday, June 28, 2015 Abdelali ZAHI : FALL 2003 : XML Schemas Global component (cont’d)
14
Sunday, June 28, 2015 Abdelali ZAHI : FALL 2003 : XML Schemas Local Component <xsd:schema xmlns:xsd=”http://www.w3.org/2001/XMLSchema” elementFormDefault=”qualified” targetNamespace=”http://www.lanw.com/namespaces/pub” xmlns=”http://www.lanw.com/namespaces/pub”>
15
Sunday, June 28, 2015 Abdelali ZAHI : FALL 2003 : XML Schemas Schema Components: Type definition Declaration Attribute group Indicators
16
Sunday, June 28, 2015 Abdelali ZAHI : FALL 2003 : XML Schemas Type Definitions The are two classes of types : simple types and complex types. There are two types of classes : Named types: defined at the root level and referenced later Anonymous types : defined nested within other schema components
17
Sunday, June 28, 2015 Abdelali ZAHI : FALL 2003 : XML Schemas Simple types Examples: Refsnes 34 1968-03-27 Simple types are used to define all attributes and elements that contain only text and do not have attributes associated with them.
18
Sunday, June 28, 2015 Abdelali ZAHI : FALL 2003 : XML Schemas Default and Fixed Values Simple elements can have a default value OR a fixed value set. A default value is automatically assigned to the element when no other value is specified. In the following example the default value is "red": A fixed value is also automatically assigned to the element. You cannot specify another value. In the following example the fixed value is "red":
19
Sunday, June 28, 2015 Abdelali ZAHI : FALL 2003 : XML Schemas Complex types An element is considered to be a complex type if it contains attribute or child elements. Complex types are used to define complex content models John Smith
20
Sunday, June 28, 2015 Abdelali ZAHI : FALL 2003 : XML Schemas Declarations You can : define elements and attributes as you need them, nesting the declarations within other element declarations (“Inline Declarations”). define declarations at the top level and reference them from within element declarations (“Referencing Declarations”). define named type definitions that are then referenced within element or attribute declarations (“Named Types”).
21
Sunday, June 28, 2015 Abdelali ZAHI : FALL 2003 : XML Schemas Inline Declarations
22
Sunday, June 28, 2015 Abdelali ZAHI : FALL 2003 : XML Schemas Referencing declarations
23
Sunday, June 28, 2015 Abdelali ZAHI : FALL 2003 : XML Schemas Named Types
24
Sunday, June 28, 2015 Abdelali ZAHI : FALL 2003 : XML Schemas How to Define an Attribute The syntax for defining an attribute is: where xxx is the name of the attribute and yyy is the data type of the attribute. Here are an XML element with an attribute:
25
Sunday, June 28, 2015 Abdelali ZAHI : FALL 2003 : XML Schemas Optional and Required Attributes All attributes are optional by default. To explicitly specify that the attribute is optional, use the "use" attribute: To make an attribute required:
26
Sunday, June 28, 2015 Abdelali ZAHI : FALL 2003 : XML Schemas Default and Fixed Values for Attributes Attributes can have a default value OR a fixed value specified. A default value is automatically assigned to the attribute when no other value is specified. In the following example the default value is "EN": A fixed value is also automatically assigned to the attribute. You cannot specify another value. In the following example the fixed value is "EN":
27
Sunday, June 28, 2015 Abdelali ZAHI : FALL 2003 : XML Schemas Attributes and Grouping An attribute group definition is an association between a name and a set of attribute declarations, enabling reuse of the same set in several complex type definitions
28
Sunday, June 28, 2015 Abdelali ZAHI : FALL 2003 : XML Schemas Indicators We have seven types of indicators: Order indicators: All Choice Sequence Occurrence indicators: maxOccurs minOccurs Group indicators: Group name attributeGroup name
29
Sunday, June 28, 2015 Abdelali ZAHI : FALL 2003 : XML Schemas All Indicator The indicator specifies by default that the child elements can appear in any order and that each child element must occur once and only once:
30
Sunday, June 28, 2015 Abdelali ZAHI : FALL 2003 : XML Schemas Choice Indicator The indicator specifies that either one child elements or the other can occur:
31
Sunday, June 28, 2015 Abdelali ZAHI : FALL 2003 : XML Schemas Sequence Indicator The indicator specifies that the child elements must appear in a specific order:
32
Sunday, June 28, 2015 Abdelali ZAHI : FALL 2003 : XML Schemas Occurrence Indicators <xs:element name="child_name" type="xs:string" maxOccurs="10" minOccurs="0"/>
33
Sunday, June 28, 2015 Abdelali ZAHI : FALL 2003 : XML Schemas Datatype properties Every datatype is defined to consist of an ordered set of three properties: value space, lexical space, and facets. Each of these helps constrain the possible content. Value Space The value space defines the allowable set of values for a given datatype. Lexical Space The lexical space defines the set of valid literals for a given datatype Facets Facets provide a set of defining aspects of a given datatype. If you want to define a minimum or maximum constraint, or if you need to restrict the length of a string datatype, you’ll have to use a facet
34
Sunday, June 28, 2015 Abdelali ZAHI : FALL 2003 : XML Schemas Built-in and User-Derived Built-In Built-in datatypes are already defined for you by the Datatypes specification Primitive datatypes are those not defined in terms of other datatypes. Primitive datatypes are the basis for all other datatypes. A derived datatype is one that is derived from a base type. The derived type inherits its value space from its base type and may also constrain the derived value space to be an explicit subset of the base type’s value space
35
Sunday, June 28, 2015 Abdelali ZAHI : FALL 2003 : XML Schemas Built-in and User-Derived (cont’d) Derived Datatypes Restriction Uses facets to restrict the allowable content. List Derived datatype is a list of white-space-separated values of the base datatype. Union There are two or more base datatypes, and the value space– derived datatype is formed from the union of the value spaces of the base types.
36
Sunday, June 28, 2015 Abdelali ZAHI : FALL 2003 : XML Schemas Namespaces
37
Sunday, June 28, 2015 Abdelali ZAHI : FALL 2003 : XML Schemas What are they? Definition: XML namespaces are symbolic references in the form of URLs used to resolve naming conflicts in documents Example: Book List Mastering XHTML Ed Tittel Java Developer’s Guide to E-Commerce with XML and JSP William Brogden Book List The Role of Namespaces 144 Mastering XHTML Ed Tittel Java Developer’s Guide to E-Commerce with XML and JSP William Brogden
38
Sunday, June 28, 2015 Abdelali ZAHI : FALL 2003 : XML Schemas Derivation and Substitution Derivation allows you to derive new types by restricting or extending the type definition. Extension is only allowed for complex types. Restriction Extension
39
Sunday, June 28, 2015 Abdelali ZAHI : FALL 2003 : XML Schemas Substitution XML Schema supports substitution mechanisms that allow one group of elements to be replaced by another group of elements. This is especially helpful when you’re working with a predefined XML Schema document
40
Sunday, June 28, 2015 Abdelali ZAHI : FALL 2003 : XML Schemas References W3C XML Schema Recommendation http://www.w3.org/TR/xmlschema-0/ http://www.w3.org/TR/xmlschema-0/ Tools and resources on XML Schema http://www.w3.org/XML/Schema http://www.w3.org/XML/Schema http://www.w3schools.com
41
Sunday, June 28, 2015 Abdelali ZAHI : FALL 2003 : XML Schemas is an essential tag in XML schemas that means Conclusion and is used when I finish my presentation. YOUR QUESTIONS ARE WELCOME
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.