{"id":71,"date":"2018-07-26T06:28:15","date_gmt":"2018-07-26T06:28:15","guid":{"rendered":"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/?post_type=chapter&#038;p=71"},"modified":"2018-08-02T05:51:38","modified_gmt":"2018-08-02T05:51:38","slug":"xmlschemapart-i","status":"publish","type":"chapter","link":"https:\/\/ebooks.inflibnet.ac.in\/csp12\/chapter\/xmlschemapart-i\/","title":{"rendered":"XMLSCHEMA(PART I)"},"content":{"raw":"<div>\r\n\r\n<strong>\u00a0 \u00a0 \u00a0XML Schemas<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">\u201cSchemas\u201d is a general term used in many context and DTD's are a form of XML schemas. According to the dictionary, a schema is \u201ca structured framework or plan\u201d. When we say \u201cXML Schemas,\u201d we usually mean the W3C XML Schema Language. This is also known as \u201cXML Schema Definition\u201d language, or XSD.<span style=\"text-align: initial;font-size: 1em\">An XML Schema consists of components such as type definitions and element declarations that can be used to assess the validity of well-formed element and attribute information items in the file.<\/span><\/p>\r\n\r\n<\/div>\r\n<div>\r\n\r\n<strong>\u00a0 <\/strong>\r\n\r\n<strong>Why we need XML Schemas?<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Some of the reasons why we need XML schemas are listed below,DTDs provide a very weak specification language. We can\u2019t put any restrictions on text content and we have very little control over mixed content (text plus elements). Moreover,we have little control over ordering of elements.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\">DTDs are written in a strange (non-XML) format and so we need separate parsers for DTDs and XML . The XML Schema Definition (XSD) language solves these problems by giving us much more control over structure and content. XSD is written in XML.<\/p>\r\n&nbsp;\r\n\r\n<strong>Why not XML schemas?<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Even though XML schemas supports many features that are not in DTD, DTD's are widely used than Schemas. DTD's have been around longer than XSD and therefore they are more widely used. Also, more tools support them. XSD is very verbose, even by XML standards. More advanced XML Schema instructions can be non-intuitive and confusing. Nevertheless, XSD is not likely to go away quickly for the reasons what has been explained earlier.<\/p>\r\n&nbsp;\r\n\r\n<strong>Referring to a schema<\/strong>\r\n\r\n&nbsp;\r\n\r\nTo refer to a DTD in an XML document, the reference goes before the root element as given below,\r\n\r\n&lt;?xml version=\"1.0\"?&gt;\r\n\r\n&lt;!DOCTYPE rootElement SYSTEM \"url\"&gt;\r\n\r\n&lt;rootElement&gt; ... &lt;\/rootElement&gt;\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">To refer to an XML Schema in an XML document, the reference goes in the root element as shown below,<\/p>\r\n<p style=\"text-align: justify\">&lt;?xml version=\"1.0\"?&gt;<\/p>\r\n<p style=\"text-align: justify\">&lt;rootElement xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance (The XML Schema Instance reference is required) xsi:noNamespaceSchemaLocation=\"url.xsd\"&gt;<\/p>\r\n<p style=\"text-align: justify\">(This is where the XML Schema definition can be found) ...<\/p>\r\n&lt;\/rootElement&gt;\r\n\r\n<\/div>\r\n<strong style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0 \u00a0The XSD document<\/strong>\r\n<div>\r\n\r\n&nbsp;\r\n\r\nThe XSD is written in XML and the file extension is .xsd. The root element is &lt;schema&gt;.\r\n\r\n&nbsp;\r\n\r\nThe XSD starts like this:\r\n\r\n&lt;?xml version=\"1.0\"?&gt;\r\n\r\n&lt;xs:schema xmlns:xs=\"http:\/\/www.w3.rg\/2001\/XMLSchema\"&gt;\r\n\r\n&nbsp;\r\n\r\n<strong>&lt;schema&gt;<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">The root element <strong>&lt;schema&gt;<\/strong> may have attributes, one of which is including the namespace which is necessary to use the predefined schema elements defined in the namespace.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\">xmlns:xs= <a href=\"http:\/\/www.w3.org\/2001\/XMLSchema\">\u201chttp:\/\/www.w3.org\/2001\/XMLSchema<\/a>\"<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\">This statement is necessary to specify where all our XSD tags are defined.<\/p>\r\n<p style=\"text-align: justify\">elementFormDefault=\"qualified\"<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\">This means that all XML elements must be qualified which means it uses a namespace.It is highly desirable to qualify all elements, or problems will arise when another schema is added.<\/p>\r\n&nbsp;\r\n\r\n<strong>Sample Schema header<\/strong>\r\n\r\n&nbsp;\r\n\r\nThe &lt;schema&gt; element may contain some more attributes. A schema declaration often looks something like this:\r\n\r\n&nbsp;\r\n\r\n&lt;?xml version=\"1.0\"?&gt;\r\n\r\n&lt;xs:schema xmlns:xs=\"http:\/\/www.w3.org\/2001\/XMLSchema\"\r\n\r\ntargetNamespace=\"http:\/\/www.w3schools.com\" xmlns=\"http:\/\/www.w3schools.com\"\r\n\r\nelementFormDefault=\"qualified\"&gt;\r\n\r\n... ...\r\n\r\n&lt;\/xs:schema&gt;\r\n\r\n&nbsp;\r\n\r\nThe following fragment,\r\n\r\n\u2013\u00a0\u00a0 <a href=\"http:\/\/www.w3.org\/2001\/XMLSchema\">xmlns:xs=http:\/\/www.w3.org\/2001\/XMLSchema<\/a>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">indicates that the elements and data types used in the schema (i.e., schema, element, complexType, sequence, string, boolean, etc.) come from the \"http:\/\/www.w3.org\/2001\/XMLSchema\" namespace. It also specifies that the elements and data types that come from the \"http:\/\/www.w3.org\/2001\/XMLSchema\" namespace should be prefixed with 'xs:'.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\">The following fragment,\u00a0\u00a0<a href=\"http:\/\/www.w3schools.com\/\">targetNamespace=http:\/\/www.w3schools.com<\/a><\/p>\r\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">indicates that the elements defined by this schema (note, to, from, heading, body.) come from the \"http:\/\/www.w3schools.com\" namespace.<\/span><\/p>\r\n\r\n<\/div>\r\n<div>\r\n\r\n\u00a0 \u00a0The following fragment,\r\n\r\n<span style=\"font-size: 1em\">-\u00a0 xmlns=http:\/\/ <\/span><a style=\"font-size: 1em\" href=\"http:\/\/www.w3schools.com\/\">www.w3sch ools.c om<\/a>\r\n\r\nindicates that the default namespace is \"http:\/\/www.w3schools.com\".\r\n\r\n&nbsp;\r\n\r\n&nbsp;\r\n\r\nThe following fragment,\r\n\r\n\u2013\u00a0\u00a0\u00a0 elementFormDefault=\"qualified\u201c\r\n\r\n&nbsp;\r\n\r\nindicates that any elements used by the XML instance document which were declared in this schema must be namespace qualified.\r\n\r\n&nbsp;\r\n\r\nAn XML Instance Document Example is given below,\r\n\r\n&lt;book isbn=\u201c012345\"&gt;\r\n\r\n&lt;title&gt; XML&lt;\/title&gt;\r\n\r\n&lt;author&gt;CSXX&lt;\/author&gt;\r\n\r\n&lt;qualification&gt; XXXXXX &lt;\/qualification&gt;\r\n\r\n&lt;\/book&gt;\r\n\r\n&nbsp;\r\n\r\nThe Schema for the above XML file could be written as follows,\r\n\r\n&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n\r\n&lt;xs:schema xmlns:xs=\"http:\/\/www.w3.org\/2001\/XMLSchema\"&gt; &lt;xs:element name=\"book\"&gt;\r\n\r\n&lt;xs:com plexType&gt;\r\n\r\n&lt;xs:sequence&gt;\r\n\r\n&lt;xs:element name=\"title\" type=\"xs:string\"\/&gt; &lt;xs:element name=\"author\" type=\"xs:string\"\/&gt; &lt;xs:element name=\u201cqualification\u201c type=\u201cxs:string\u201d\/&gt;\r\n\r\n&lt;\/xs:sequence&gt;\r\n\r\n&lt;\/xs:com plexType&gt;\r\n\r\n&lt;\/xs:element&gt;\r\n\r\n&lt;\/xs:schema&gt;\r\n\r\nLet us learn about how to write XML schemas in the forth coming sections.\r\n\r\n<\/div>\r\n<strong style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0 \u00a0What\u2019s in a Schema?<\/strong>\r\n<div>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">A Schema is an XML document but a DTD is not an XML document. Because a schema is an XML document, it must have a root element and the root element is &lt;schema&gt; for any XSD file. Within the root element, there can be any number and combination of Inclusions, Imports, Re-definitions and Annotations. This is followed by any number and combinations of Simple and complex data type definitions, Element and attribute definitions, Model group definitions and Annotations.<\/p>\r\n&nbsp;\r\n\r\n<strong>Structure of a Schema<\/strong>\r\n\r\n&nbsp;\r\n\r\n<strong>&lt;schema&gt;<\/strong>\r\n\r\n<strong>&lt;!\u2013 any number of the following --&gt;<\/strong>\r\n\r\n&lt;include ...\/&gt;\r\n\r\n&lt;import&gt; ... &lt;\/import&gt;\r\n\r\n&lt;redefine&gt; ... &lt;\/redefine&gt;\r\n\r\n&lt;annotation&gt; ... &lt;\/annotation&gt;\r\n\r\n<strong>&lt;!\u2013 any number of following definitions --&gt;<\/strong>\r\n\r\n&lt;simpleType&gt; ... &lt;\/simpleType&gt;\r\n\r\n&lt;com plexType&gt; ... &lt;\/com plexType&gt;\r\n\r\n&lt;element&gt; ... &lt;\/element&gt;\r\n\r\n&lt;attribute\/&gt;\r\n\r\n&lt;attributeGroup&gt; ... &lt;\/attributeGroup&gt;\r\n\r\n&lt;group&gt; ... &lt;\/group&gt;\r\n\r\n&lt;annotation&gt; ... &lt;\/annotation&gt;\r\n\r\n<strong>&lt;\/schema&gt;<\/strong>\r\n\r\n&nbsp;\r\n\r\n<strong>XML Schema Components<\/strong>\r\n<ul>\r\n \t<li>Abstract Data Model<\/li>\r\n \t<li>Simple and Complex Type Definitions<\/li>\r\n \t<li>Declarations<\/li>\r\n \t<li>Relationship among Schema Components<\/li>\r\n<\/ul>\r\n<p style=\"text-align: justify\">\u00a0 \u00a0 \u00a0 W3C defined an abstract data model to describe XML schemas, and it is composed of schema components. we can write XML schemas using the components as building blocks.<\/p>\r\n\r\n<\/div>\r\n<strong style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0 XML Abstract Data Model<\/strong>\r\n<div>\r\n\r\n&nbsp;\r\n\r\nThe XML Abstract Data Model composes of Schema Components. This abstract model is used to describe XML Schemas.\r\n\r\n&nbsp;\r\n\r\n<strong>Schema Component<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">It is the generic term used for the building blocks that compose the abstract data model of the schema. There are 13(thirteen) kinds of Schema Components defined in the Abstract model. Following is the list of all schema components.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\">They are classified into three groups, primary, secondary, and helper group. We will present how to compose schemas based on the components.<\/p>\r\n&nbsp;\r\n\r\n<strong>Primary Group<\/strong>\r\n\r\n&nbsp;\r\n\r\n1.\u00a0\u00a0\u00a0\u00a0\u00a0 Simple type definitions\r\n\r\n2.\u00a0\u00a0\u00a0\u00a0\u00a0 Complex type definitions\r\n\r\n3.\u00a0\u00a0\u00a0\u00a0\u00a0 Attribute declarations\r\n\r\n4.\u00a0\u00a0\u00a0\u00a0\u00a0 Element declarations\r\n\r\n&nbsp;\r\n\r\n<strong>Secondary Group<\/strong>\r\n\r\n&nbsp;\r\n\r\n5.\u00a0\u00a0\u00a0\u00a0\u00a0 Attribute group definitions\r\n\r\n6.\u00a0\u00a0\u00a0\u00a0\u00a0 Identity-constraint definitions\r\n\r\n7.\u00a0\u00a0\u00a0\u00a0\u00a0 Model group definitions\r\n\r\n8.\u00a0\u00a0\u00a0\u00a0\u00a0 Notation declarations\r\n\r\n&nbsp;\r\n\r\n<strong>Helper Group<\/strong>\r\n\r\n&nbsp;\r\n\r\n9.\u00a0\u00a0\u00a0\u00a0\u00a0 Annotations\r\n\r\n10.\u00a0\u00a0 Model groups\r\n\r\n11.\u00a0\u00a0 Particles\r\n\r\n12.\u00a0\u00a0 Wildcards\r\n\r\n13.\u00a0\u00a0 Attribute Uses\r\n\r\n&nbsp;\r\n\r\n<strong>XML document &amp; XML Schema<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Figure 9.1 describes about the differences between the XML document and an XML schema created for the XML file. An XML document is saved as .xml file and it contains the description of the information\u00a0<span style=\"text-align: initial;font-size: 1em\">items. An XML schema for an XML file is saved as .xsd file and it composes of the desriptions of the declaration and type definitions of the elements and the attributes.<\/span><\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">There are two kinds of activity when writing schemas, declaration and definition.<\/span><span style=\"text-align: initial;font-size: 1em\">All items in XML documents must conform to the declaration in schemas and it must be validated according to the declarations in schemas. The most important declarations are element declarations and attribute declarations. Hence, it is required to declare elements and attributes in schemas. To declare them their types must be defined, just like to define classes in OOP.<\/span><\/p>\r\n\r\n<\/div>\r\n<div>\r\n<p style=\"text-align: center\"><img class=\"size-full wp-image-72 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-25.png\" alt=\"\" width=\"536\" height=\"183\" \/><\/p>\r\n&nbsp;\r\n\r\n<strong>Declaration &amp; Definition<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Declaration Components are associated by (qualified) names to information items being validated. It is like declaring objects in OOP.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\">Definition Components define internal schema components that can be used in other schema components. Type definition is like defining classes in OOP.<\/p>\r\n&nbsp;\r\n\r\n<strong>Declarations<\/strong>\r\n\r\n&nbsp;\r\n\r\n<strong>Declarations are done for the following information items.<\/strong>\r\n\r\n&nbsp;\r\n\r\n\u2022 Element Declaration\r\n\r\n\u2022 Attribute Declaration\r\n\r\n\u2022 Notation Declaration\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">There are three kinds of declaration. Element, attribute and notation. All of them are components in the abstract data model. In attribute declaration, we can use Attribute uses to indicate whether the attribute is required, whether it's value is fixed or it holds default value and soon. Attribute use is an optional component in the abstract data model.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">An example of declaration of elements is given below. In this example the declaration for the element 'book' is shown. Here we use the &lt;element&gt; to declare the book and it is defined as a complex type.<\/span><\/p>\r\n\r\n<\/div>\r\n<div>\r\n\r\n\u00a0 \u00a0 &lt;xs:element <strong>name=\"book\"<\/strong>&gt;\r\n\r\n&lt;xs:com plexType&gt;\r\n\r\n&lt;xs:sequence&gt;\r\n\r\n&lt;xs:element name=\"title\" type=\"xs:string\"\/&gt;\r\n\r\n\u2026 \u2026\r\n\r\n&lt;\/xs:sequence&gt;\r\n\r\n&lt;xs:attribute name=\"isbn\" type=\"xs:string\"\/&gt; &lt;\/xs:com plexType&gt;\r\n\r\n&lt;\/xs:element&gt;\r\n\r\n&nbsp;\r\n\r\n<strong>Type Definitions<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">By type definition, we can do type checking using applications, also we can reuse our type definitions.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\">There two kinds of type definition, simple and complex.<\/p>\r\n&nbsp;\r\n\r\n<strong>Simple Type Definition VS. Complex Type Definition<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">The Simple type definition can be used to declare attributes and elements without element children, while the Complex type definition can only be used to declare elements.Figure 9.2 pictorially represents the use of Simple and Complex type definitions.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: center\"><strong><img class=\"size-full wp-image-73 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-26.png\" alt=\"\" width=\"412\" height=\"201\" \/><\/strong><\/p>\r\n&lt;xs:complexType <strong>name=\"bookType\"<\/strong>&gt;\r\n\r\n&lt;xs:sequence&gt;\r\n\r\n&lt;xs:element name=\"title\" type=\"nameType\"\/&gt;\r\n\r\n\u2026 \u2026\r\n\r\n&lt;\/xs:sequence&gt;\r\n\r\n&lt;xs:attribute name=\"isbn\" type=\"isbnType\" use=\"required\"\/&gt; &lt;\/xs:complexType&gt;\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">In this example, we define a complex data type named \u201cbookType\u201d, and then we can declare an element 'book', somewhere in the file, based on the bookType. Note here we use &lt;complexType&gt; to define the type.<span style=\"font-size: 1em;text-align: initial\">\u00a0 \u00a0 &lt;xs:element name=\"book\" type=\"bookType\"\/&gt;.<\/span><span style=\"text-align: initial;font-size: 1em\">Here we declare an element 'book' based on the bookType.<\/span><\/p>\r\n\r\n<\/div>\r\n<div>\r\n<p style=\"text-align: justify\"><strong>\u00a0<\/strong><\/p>\r\n<p style=\"text-align: justify\"><strong>Simple Types<\/strong><\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\">What is an element with simple type?<\/p>\r\n<p style=\"text-align: justify\">A simple element is an XML element that can contain only text. It cannot contain any other elements or attributes. We can also add restrictions (facets) to a data type in order to limit its content, and we can require the data to match a defined pattern.<\/p>\r\n&nbsp;\r\n\r\n<strong>Simple Type Definition<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Simple Type Definition can be a restriction of some other simple type. It can be a list or union of simple type definition or a built-in primitive datatypes.<\/p>\r\n&nbsp;\r\n\r\nExample\r\n\r\n&lt;xs:simpleType name=\"farenheitWaterTemp\"&gt;\r\n\r\n&lt;xs:restriction base=\"xs:number\"&gt;\r\n\r\n&lt;xs:fractionDigits value=\"2\"\/&gt;\r\n\r\n&lt;xs:minExclusive value=\"0.00\"\/&gt;\r\n\r\n&lt;xs:maxExclusive value=\"100.00\"\/&gt;\r\n\r\n&lt;\/xs:restriction&gt;\r\n\r\n&lt;\/xs:simpleType&gt;\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Here is an example of simple type definition. We define a simple type to describe water temperature. We define it by restricting a base type number, which is a built-in type. To restrict the base type ,we use the restriction element, we can specify the base type and other restrictions, such as minimum and maximum values.<\/p>\r\n&nbsp;\r\n\r\n<strong>Complex Types<\/strong>\r\n\r\n&nbsp;\r\n\r\nComplex types are used for describing complex elements.\r\n\r\n&nbsp;\r\n\r\n<strong>Complex Elements<\/strong>\r\n\r\n&nbsp;\r\n\r\nA complex element is an XML element that contains other elements and\/or attributes.\r\n\r\nThere are four kinds of complex elements:\r\n<ul>\r\n \t<li>\u00a0empty elements<\/li>\r\n \t<li>\u00a0elements that contain only other elements<\/li>\r\n \t<li><span style=\"font-size: 1em;text-align: initial\">\u00a0elements that contain only text<\/span><\/li>\r\n \t<li><span style=\"text-align: initial;font-size: 1em\">\u00a0elements that contain both other elements and text<\/span><\/li>\r\n<\/ul>\r\n<\/div>\r\n<div>\r\n\r\n<em>\u00a0 \u00a0 Note:<\/em><em> Each of these elements may (or must) contain attributes as well.<\/em>\r\n\r\n&nbsp;\r\n\r\n<strong>Examples of Complex XML Elements<\/strong>\r\n\r\n&nbsp;\r\n\r\nSome examples of complex elements are given below.\r\n\r\nA complex XML element, \"product\", which is empty is given below.\r\n\r\n&lt;product pi d=\"1345\"\/&gt;\r\n\r\nA complex XML element, \"employee\", which contains only other elements:\r\n\r\n&nbsp;\r\n\r\n&lt;employee&gt;\r\n\r\n&lt;firstname&gt;John&lt;\/firstname&gt;\r\n\r\n&lt;lastname&gt;Smith&lt;\/lastname&gt;\r\n\r\n&lt;\/employee&gt;\r\n\r\n&nbsp;\r\n\r\nA complex XML element, \"food\", which contains only text:\r\n\r\n&lt;food type=\"dessert\"&gt;Ice cream&lt;\/food&gt;\r\n\r\n&nbsp;\r\n\r\nA complex XML element, \"description\", which contains both elements and text:\r\n\r\n&lt;description&gt; It happened on &lt;date lang=\"norwegian\"&gt;03.03.99&lt;\/date&gt;..&lt;\/description&gt;\r\n\r\n&nbsp;\r\n\r\n<strong>Complex Type Definition<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">According to Object Oriented concepts, there are two kinds of mechanism by which we can define complex type, one by using inheritance property and the other by using composition property. As for inheritance, we can restrict or extend a base type. Composition is achieved by using the group model component in the abstract model.<\/p>\r\n&nbsp;\r\n\r\n<strong>Inheritance:<\/strong>\r\n\r\n&nbsp;\r\n\r\nRestriction: We restrict base types definitions.\r\n\r\nExtension: We add something new.\r\n\r\n&nbsp;\r\n\r\n<strong>Composition:<\/strong>\r\n\r\n&nbsp;\r\n\r\nWe use Group model to deploy composition.\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Each complex type definition is either a restriction of a complex type definition or an extension of a simple or complex type definition or a restriction of the ur-type definition.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">Specifically, we can define a complex type by restricting another complex type, extending a simplex or complex type definition, or restricting a ur-type definition. A ur-type is a special type definition that can be as both simple and complex definition.<\/span><\/p>\r\n\r\n<\/div>\r\n<strong>\u00a0 \u00a0 Example<\/strong>\r\n\r\n&nbsp;\r\n\r\n<strong>&lt;xs:complexType name=\"personName\"&gt;<\/strong>\r\n\r\n&lt;xs:sequence&gt;\r\n\r\n&lt;xs:element name=\"title\" minOccurs=\"0\"\/&gt;\r\n\r\n\u2026 \u2026\r\n\r\n&lt;\/xs:sequence&gt;\r\n\r\n&lt;\/xs:com plexType&gt;\r\n\r\n<strong>&lt;xs:complexType name=\"extendedName\"&gt;<\/strong>\r\n\r\n&lt;xs:com plexContent&gt;\r\n\r\n&lt;xs:extension base=\"personName\"&gt;\r\n\r\n&lt;xs:sequence&gt;\r\n\r\n&lt;xs:element name=\"generation\" minOccurs=\"0\"\/&gt; &lt;\/xs:sequence&gt;\r\n\r\n&lt;\/xs:extension&gt;\r\n\r\n&lt;\/xs:com plexContent&gt;\r\n\r\n&lt;\/xs:com plexType&gt;\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Since we have already seen an example of restriction in simple type definition. In this example we have illustrated the property extension with inheritance. Based on a complex type called personName, we define a new complex type by using extension element. Here we add a new element called generation.<\/p>\r\n&nbsp;\r\n\r\n<strong>Summary<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">This module explains about the fact that XML Schema is a flexible and powerful schema language and the syntax of the schema is XML itself. The module gives an idea about simple and complex elements and about simple and complex type definitions. The module also explores a variety of data types and ability to extend type system.<\/p>\r\n&nbsp;\r\n\r\n<strong>Web Links<\/strong>\r\n<ul>\r\n \t<li><em>www.w3schools.com\/<strong>xml<\/strong><\/em><\/li>\r\n \t<li><em>cs.lamar.edu\/faculty\/osborne\/5369\/sp04\/<strong>XMLschema<\/strong>.<strong>ppt<\/strong><\/em><\/li>\r\n \t<li><em>www.tutorialspoint.com\/<strong>xml<\/strong><\/em><\/li>\r\n \t<li><em>www.cis.upenn.edu\/~matuszek\/cit597-2003\/Lectures\/30-<strong>schemas<\/strong>.<strong>ppt<\/strong><\/em><\/li>\r\n \t<li><em>https:\/\/www.w3.org\/TR\/xmlschema-1\/#components<\/em><\/li>\r\n<\/ul>","rendered":"<div>\n<p><strong>\u00a0 \u00a0 \u00a0XML Schemas<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">\u201cSchemas\u201d is a general term used in many context and DTD&#8217;s are a form of XML schemas. According to the dictionary, a schema is \u201ca structured framework or plan\u201d. When we say \u201cXML Schemas,\u201d we usually mean the W3C XML Schema Language. This is also known as \u201cXML Schema Definition\u201d language, or XSD.<span style=\"text-align: initial;font-size: 1em\">An XML Schema consists of components such as type definitions and element declarations that can be used to assess the validity of well-formed element and attribute information items in the file.<\/span><\/p>\n<\/div>\n<div>\n<p><strong>\u00a0 <\/strong><\/p>\n<p><strong>Why we need XML Schemas?<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Some of the reasons why we need XML schemas are listed below,DTDs provide a very weak specification language. We can\u2019t put any restrictions on text content and we have very little control over mixed content (text plus elements). Moreover,we have little control over ordering of elements.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">DTDs are written in a strange (non-XML) format and so we need separate parsers for DTDs and XML . The XML Schema Definition (XSD) language solves these problems by giving us much more control over structure and content. XSD is written in XML.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Why not XML schemas?<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Even though XML schemas supports many features that are not in DTD, DTD&#8217;s are widely used than Schemas. DTD&#8217;s have been around longer than XSD and therefore they are more widely used. Also, more tools support them. XSD is very verbose, even by XML standards. More advanced XML Schema instructions can be non-intuitive and confusing. Nevertheless, XSD is not likely to go away quickly for the reasons what has been explained earlier.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Referring to a schema<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>To refer to a DTD in an XML document, the reference goes before the root element as given below,<\/p>\n<p>&lt;?xml version=&#8221;1.0&#8243;?&gt;<\/p>\n<p>&lt;!DOCTYPE rootElement SYSTEM &#8220;url&#8221;&gt;<\/p>\n<p>&lt;rootElement&gt; &#8230; &lt;\/rootElement&gt;<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">To refer to an XML Schema in an XML document, the reference goes in the root element as shown below,<\/p>\n<p style=\"text-align: justify\">&lt;?xml version=&#8221;1.0&#8243;?&gt;<\/p>\n<p style=\"text-align: justify\">&lt;rootElement xmlns:xsi=&#8221;http:\/\/www.w3.org\/2001\/XMLSchema-instance (The XML Schema Instance reference is required) xsi:noNamespaceSchemaLocation=&#8221;url.xsd&#8221;&gt;<\/p>\n<p style=\"text-align: justify\">(This is where the XML Schema definition can be found) &#8230;<\/p>\n<p>&lt;\/rootElement&gt;<\/p>\n<\/div>\n<p><strong style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0 \u00a0The XSD document<\/strong><\/p>\n<div>\n<p>&nbsp;<\/p>\n<p>The XSD is written in XML and the file extension is .xsd. The root element is &lt;schema&gt;.<\/p>\n<p>&nbsp;<\/p>\n<p>The XSD starts like this:<\/p>\n<p>&lt;?xml version=&#8221;1.0&#8243;?&gt;<\/p>\n<p>&lt;xs:schema xmlns:xs=&#8221;http:\/\/www.w3.rg\/2001\/XMLSchema&#8221;&gt;<\/p>\n<p>&nbsp;<\/p>\n<p><strong>&lt;schema&gt;<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">The root element <strong>&lt;schema&gt;<\/strong> may have attributes, one of which is including the namespace which is necessary to use the predefined schema elements defined in the namespace.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">xmlns:xs= <a href=\"http:\/\/www.w3.org\/2001\/XMLSchema\">\u201chttp:\/\/www.w3.org\/2001\/XMLSchema<\/a>&#8220;<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">This statement is necessary to specify where all our XSD tags are defined.<\/p>\n<p style=\"text-align: justify\">elementFormDefault=&#8221;qualified&#8221;<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">This means that all XML elements must be qualified which means it uses a namespace.It is highly desirable to qualify all elements, or problems will arise when another schema is added.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Sample Schema header<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>The &lt;schema&gt; element may contain some more attributes. A schema declaration often looks something like this:<\/p>\n<p>&nbsp;<\/p>\n<p>&lt;?xml version=&#8221;1.0&#8243;?&gt;<\/p>\n<p>&lt;xs:schema xmlns:xs=&#8221;http:\/\/www.w3.org\/2001\/XMLSchema&#8221;<\/p>\n<p>targetNamespace=&#8221;http:\/\/www.w3schools.com&#8221; xmlns=&#8221;http:\/\/www.w3schools.com&#8221;<\/p>\n<p>elementFormDefault=&#8221;qualified&#8221;&gt;<\/p>\n<p>&#8230; &#8230;<\/p>\n<p>&lt;\/xs:schema&gt;<\/p>\n<p>&nbsp;<\/p>\n<p>The following fragment,<\/p>\n<p>\u2013\u00a0\u00a0 <a href=\"http:\/\/www.w3.org\/2001\/XMLSchema\">xmlns:xs=http:\/\/www.w3.org\/2001\/XMLSchema<\/a><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">indicates that the elements and data types used in the schema (i.e., schema, element, complexType, sequence, string, boolean, etc.) come from the &#8220;http:\/\/www.w3.org\/2001\/XMLSchema&#8221; namespace. It also specifies that the elements and data types that come from the &#8220;http:\/\/www.w3.org\/2001\/XMLSchema&#8221; namespace should be prefixed with &#8216;xs:&#8217;.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">The following fragment,\u00a0\u00a0<a href=\"http:\/\/www.w3schools.com\/\">targetNamespace=http:\/\/www.w3schools.com<\/a><\/p>\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">indicates that the elements defined by this schema (note, to, from, heading, body.) come from the &#8220;http:\/\/www.w3schools.com&#8221; namespace.<\/span><\/p>\n<\/div>\n<div>\n<p>\u00a0 \u00a0The following fragment,<\/p>\n<p><span style=\"font-size: 1em\">&#8211;\u00a0 xmlns=http:\/\/ <\/span><a style=\"font-size: 1em\" href=\"http:\/\/www.w3schools.com\/\">www.w3sch ools.c om<\/a><\/p>\n<p>indicates that the default namespace is &#8220;http:\/\/www.w3schools.com&#8221;.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>The following fragment,<\/p>\n<p>\u2013\u00a0\u00a0\u00a0 elementFormDefault=&#8221;qualified\u201c<\/p>\n<p>&nbsp;<\/p>\n<p>indicates that any elements used by the XML instance document which were declared in this schema must be namespace qualified.<\/p>\n<p>&nbsp;<\/p>\n<p>An XML Instance Document Example is given below,<\/p>\n<p>&lt;book isbn=\u201c012345&#8243;&gt;<\/p>\n<p>&lt;title&gt; XML&lt;\/title&gt;<\/p>\n<p>&lt;author&gt;CSXX&lt;\/author&gt;<\/p>\n<p>&lt;qualification&gt; XXXXXX &lt;\/qualification&gt;<\/p>\n<p>&lt;\/book&gt;<\/p>\n<p>&nbsp;<\/p>\n<p>The Schema for the above XML file could be written as follows,<\/p>\n<p>&lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;utf-8&#8243;?&gt;<\/p>\n<p>&lt;xs:schema xmlns:xs=&#8221;http:\/\/www.w3.org\/2001\/XMLSchema&#8221;&gt; &lt;xs:element name=&#8221;book&#8221;&gt;<\/p>\n<p>&lt;xs:com plexType&gt;<\/p>\n<p>&lt;xs:sequence&gt;<\/p>\n<p>&lt;xs:element name=&#8221;title&#8221; type=&#8221;xs:string&#8221;\/&gt; &lt;xs:element name=&#8221;author&#8221; type=&#8221;xs:string&#8221;\/&gt; &lt;xs:element name=\u201cqualification\u201c type=\u201cxs:string\u201d\/&gt;<\/p>\n<p>&lt;\/xs:sequence&gt;<\/p>\n<p>&lt;\/xs:com plexType&gt;<\/p>\n<p>&lt;\/xs:element&gt;<\/p>\n<p>&lt;\/xs:schema&gt;<\/p>\n<p>Let us learn about how to write XML schemas in the forth coming sections.<\/p>\n<\/div>\n<p><strong style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0 \u00a0What\u2019s in a Schema?<\/strong><\/p>\n<div>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">A Schema is an XML document but a DTD is not an XML document. Because a schema is an XML document, it must have a root element and the root element is &lt;schema&gt; for any XSD file. Within the root element, there can be any number and combination of Inclusions, Imports, Re-definitions and Annotations. This is followed by any number and combinations of Simple and complex data type definitions, Element and attribute definitions, Model group definitions and Annotations.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Structure of a Schema<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><strong>&lt;schema&gt;<\/strong><\/p>\n<p><strong>&lt;!\u2013 any number of the following &#8211;&gt;<\/strong><\/p>\n<p>&lt;include &#8230;\/&gt;<\/p>\n<p>&lt;import&gt; &#8230; &lt;\/import&gt;<\/p>\n<p>&lt;redefine&gt; &#8230; &lt;\/redefine&gt;<\/p>\n<p>&lt;annotation&gt; &#8230; &lt;\/annotation&gt;<\/p>\n<p><strong>&lt;!\u2013 any number of following definitions &#8211;&gt;<\/strong><\/p>\n<p>&lt;simpleType&gt; &#8230; &lt;\/simpleType&gt;<\/p>\n<p>&lt;com plexType&gt; &#8230; &lt;\/com plexType&gt;<\/p>\n<p>&lt;element&gt; &#8230; &lt;\/element&gt;<\/p>\n<p>&lt;attribute\/&gt;<\/p>\n<p>&lt;attributeGroup&gt; &#8230; &lt;\/attributeGroup&gt;<\/p>\n<p>&lt;group&gt; &#8230; &lt;\/group&gt;<\/p>\n<p>&lt;annotation&gt; &#8230; &lt;\/annotation&gt;<\/p>\n<p><strong>&lt;\/schema&gt;<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><strong>XML Schema Components<\/strong><\/p>\n<ul>\n<li>Abstract Data Model<\/li>\n<li>Simple and Complex Type Definitions<\/li>\n<li>Declarations<\/li>\n<li>Relationship among Schema Components<\/li>\n<\/ul>\n<p style=\"text-align: justify\">\u00a0 \u00a0 \u00a0 W3C defined an abstract data model to describe XML schemas, and it is composed of schema components. we can write XML schemas using the components as building blocks.<\/p>\n<\/div>\n<p><strong style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0 XML Abstract Data Model<\/strong><\/p>\n<div>\n<p>&nbsp;<\/p>\n<p>The XML Abstract Data Model composes of Schema Components. This abstract model is used to describe XML Schemas.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Schema Component<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">It is the generic term used for the building blocks that compose the abstract data model of the schema. There are 13(thirteen) kinds of Schema Components defined in the Abstract model. Following is the list of all schema components.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">They are classified into three groups, primary, secondary, and helper group. We will present how to compose schemas based on the components.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Primary Group<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>1.\u00a0\u00a0\u00a0\u00a0\u00a0 Simple type definitions<\/p>\n<p>2.\u00a0\u00a0\u00a0\u00a0\u00a0 Complex type definitions<\/p>\n<p>3.\u00a0\u00a0\u00a0\u00a0\u00a0 Attribute declarations<\/p>\n<p>4.\u00a0\u00a0\u00a0\u00a0\u00a0 Element declarations<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Secondary Group<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>5.\u00a0\u00a0\u00a0\u00a0\u00a0 Attribute group definitions<\/p>\n<p>6.\u00a0\u00a0\u00a0\u00a0\u00a0 Identity-constraint definitions<\/p>\n<p>7.\u00a0\u00a0\u00a0\u00a0\u00a0 Model group definitions<\/p>\n<p>8.\u00a0\u00a0\u00a0\u00a0\u00a0 Notation declarations<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Helper Group<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>9.\u00a0\u00a0\u00a0\u00a0\u00a0 Annotations<\/p>\n<p>10.\u00a0\u00a0 Model groups<\/p>\n<p>11.\u00a0\u00a0 Particles<\/p>\n<p>12.\u00a0\u00a0 Wildcards<\/p>\n<p>13.\u00a0\u00a0 Attribute Uses<\/p>\n<p>&nbsp;<\/p>\n<p><strong>XML document &amp; XML Schema<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Figure 9.1 describes about the differences between the XML document and an XML schema created for the XML file. An XML document is saved as .xml file and it contains the description of the information\u00a0<span style=\"text-align: initial;font-size: 1em\">items. An XML schema for an XML file is saved as .xsd file and it composes of the desriptions of the declaration and type definitions of the elements and the attributes.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">There are two kinds of activity when writing schemas, declaration and definition.<\/span><span style=\"text-align: initial;font-size: 1em\">All items in XML documents must conform to the declaration in schemas and it must be validated according to the declarations in schemas. The most important declarations are element declarations and attribute declarations. Hence, it is required to declare elements and attributes in schemas. To declare them their types must be defined, just like to define classes in OOP.<\/span><\/p>\n<\/div>\n<div>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-72 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-25.png\" alt=\"\" width=\"536\" height=\"183\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-25.png 536w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-25-300x102.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-25-65x22.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-25-225x77.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-25-350x119.png 350w\" sizes=\"auto, (max-width: 536px) 100vw, 536px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Declaration &amp; Definition<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Declaration Components are associated by (qualified) names to information items being validated. It is like declaring objects in OOP.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Definition Components define internal schema components that can be used in other schema components. Type definition is like defining classes in OOP.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Declarations<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Declarations are done for the following information items.<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>\u2022 Element Declaration<\/p>\n<p>\u2022 Attribute Declaration<\/p>\n<p>\u2022 Notation Declaration<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">There are three kinds of declaration. Element, attribute and notation. All of them are components in the abstract data model. In attribute declaration, we can use Attribute uses to indicate whether the attribute is required, whether it&#8217;s value is fixed or it holds default value and soon. Attribute use is an optional component in the abstract data model.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">An example of declaration of elements is given below. In this example the declaration for the element &#8216;book&#8217; is shown. Here we use the &lt;element&gt; to declare the book and it is defined as a complex type.<\/span><\/p>\n<\/div>\n<div>\n<p>\u00a0 \u00a0 &lt;xs:element <strong>name=&#8221;book&#8221;<\/strong>&gt;<\/p>\n<p>&lt;xs:com plexType&gt;<\/p>\n<p>&lt;xs:sequence&gt;<\/p>\n<p>&lt;xs:element name=&#8221;title&#8221; type=&#8221;xs:string&#8221;\/&gt;<\/p>\n<p>\u2026 \u2026<\/p>\n<p>&lt;\/xs:sequence&gt;<\/p>\n<p>&lt;xs:attribute name=&#8221;isbn&#8221; type=&#8221;xs:string&#8221;\/&gt; &lt;\/xs:com plexType&gt;<\/p>\n<p>&lt;\/xs:element&gt;<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Type Definitions<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">By type definition, we can do type checking using applications, also we can reuse our type definitions.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">There two kinds of type definition, simple and complex.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Simple Type Definition VS. Complex Type Definition<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">The Simple type definition can be used to declare attributes and elements without element children, while the Complex type definition can only be used to declare elements.Figure 9.2 pictorially represents the use of Simple and Complex type definitions.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center\"><strong><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-73 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-26.png\" alt=\"\" width=\"412\" height=\"201\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-26.png 412w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-26-300x146.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-26-65x32.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-26-225x110.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-26-350x171.png 350w\" sizes=\"auto, (max-width: 412px) 100vw, 412px\" \/><\/strong><\/p>\n<p>&lt;xs:complexType <strong>name=&#8221;bookType&#8221;<\/strong>&gt;<\/p>\n<p>&lt;xs:sequence&gt;<\/p>\n<p>&lt;xs:element name=&#8221;title&#8221; type=&#8221;nameType&#8221;\/&gt;<\/p>\n<p>\u2026 \u2026<\/p>\n<p>&lt;\/xs:sequence&gt;<\/p>\n<p>&lt;xs:attribute name=&#8221;isbn&#8221; type=&#8221;isbnType&#8221; use=&#8221;required&#8221;\/&gt; &lt;\/xs:complexType&gt;<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">In this example, we define a complex data type named \u201cbookType\u201d, and then we can declare an element &#8216;book&#8217;, somewhere in the file, based on the bookType. Note here we use &lt;complexType&gt; to define the type.<span style=\"font-size: 1em;text-align: initial\">\u00a0 \u00a0 &lt;xs:element name=&#8221;book&#8221; type=&#8221;bookType&#8221;\/&gt;.<\/span><span style=\"text-align: initial;font-size: 1em\">Here we declare an element &#8216;book&#8217; based on the bookType.<\/span><\/p>\n<\/div>\n<div>\n<p style=\"text-align: justify\"><strong>\u00a0<\/strong><\/p>\n<p style=\"text-align: justify\"><strong>Simple Types<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">What is an element with simple type?<\/p>\n<p style=\"text-align: justify\">A simple element is an XML element that can contain only text. It cannot contain any other elements or attributes. We can also add restrictions (facets) to a data type in order to limit its content, and we can require the data to match a defined pattern.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Simple Type Definition<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Simple Type Definition can be a restriction of some other simple type. It can be a list or union of simple type definition or a built-in primitive datatypes.<\/p>\n<p>&nbsp;<\/p>\n<p>Example<\/p>\n<p>&lt;xs:simpleType name=&#8221;farenheitWaterTemp&#8221;&gt;<\/p>\n<p>&lt;xs:restriction base=&#8221;xs:number&#8221;&gt;<\/p>\n<p>&lt;xs:fractionDigits value=&#8221;2&#8243;\/&gt;<\/p>\n<p>&lt;xs:minExclusive value=&#8221;0.00&#8243;\/&gt;<\/p>\n<p>&lt;xs:maxExclusive value=&#8221;100.00&#8243;\/&gt;<\/p>\n<p>&lt;\/xs:restriction&gt;<\/p>\n<p>&lt;\/xs:simpleType&gt;<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Here is an example of simple type definition. We define a simple type to describe water temperature. We define it by restricting a base type number, which is a built-in type. To restrict the base type ,we use the restriction element, we can specify the base type and other restrictions, such as minimum and maximum values.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Complex Types<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>Complex types are used for describing complex elements.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Complex Elements<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>A complex element is an XML element that contains other elements and\/or attributes.<\/p>\n<p>There are four kinds of complex elements:<\/p>\n<ul>\n<li>\u00a0empty elements<\/li>\n<li>\u00a0elements that contain only other elements<\/li>\n<li><span style=\"font-size: 1em;text-align: initial\">\u00a0elements that contain only text<\/span><\/li>\n<li><span style=\"text-align: initial;font-size: 1em\">\u00a0elements that contain both other elements and text<\/span><\/li>\n<\/ul>\n<\/div>\n<div>\n<p><em>\u00a0 \u00a0 Note:<\/em><em> Each of these elements may (or must) contain attributes as well.<\/em><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Examples of Complex XML Elements<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>Some examples of complex elements are given below.<\/p>\n<p>A complex XML element, &#8220;product&#8221;, which is empty is given below.<\/p>\n<p>&lt;product pi d=&#8221;1345&#8243;\/&gt;<\/p>\n<p>A complex XML element, &#8220;employee&#8221;, which contains only other elements:<\/p>\n<p>&nbsp;<\/p>\n<p>&lt;employee&gt;<\/p>\n<p>&lt;firstname&gt;John&lt;\/firstname&gt;<\/p>\n<p>&lt;lastname&gt;Smith&lt;\/lastname&gt;<\/p>\n<p>&lt;\/employee&gt;<\/p>\n<p>&nbsp;<\/p>\n<p>A complex XML element, &#8220;food&#8221;, which contains only text:<\/p>\n<p>&lt;food type=&#8221;dessert&#8221;&gt;Ice cream&lt;\/food&gt;<\/p>\n<p>&nbsp;<\/p>\n<p>A complex XML element, &#8220;description&#8221;, which contains both elements and text:<\/p>\n<p>&lt;description&gt; It happened on &lt;date lang=&#8221;norwegian&#8221;&gt;03.03.99&lt;\/date&gt;..&lt;\/description&gt;<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Complex Type Definition<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">According to Object Oriented concepts, there are two kinds of mechanism by which we can define complex type, one by using inheritance property and the other by using composition property. As for inheritance, we can restrict or extend a base type. Composition is achieved by using the group model component in the abstract model.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Inheritance:<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>Restriction: We restrict base types definitions.<\/p>\n<p>Extension: We add something new.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Composition:<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>We use Group model to deploy composition.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Each complex type definition is either a restriction of a complex type definition or an extension of a simple or complex type definition or a restriction of the ur-type definition.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">Specifically, we can define a complex type by restricting another complex type, extending a simplex or complex type definition, or restricting a ur-type definition. A ur-type is a special type definition that can be as both simple and complex definition.<\/span><\/p>\n<\/div>\n<p><strong>\u00a0 \u00a0 Example<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><strong>&lt;xs:complexType name=&#8221;personName&#8221;&gt;<\/strong><\/p>\n<p>&lt;xs:sequence&gt;<\/p>\n<p>&lt;xs:element name=&#8221;title&#8221; minOccurs=&#8221;0&#8243;\/&gt;<\/p>\n<p>\u2026 \u2026<\/p>\n<p>&lt;\/xs:sequence&gt;<\/p>\n<p>&lt;\/xs:com plexType&gt;<\/p>\n<p><strong>&lt;xs:complexType name=&#8221;extendedName&#8221;&gt;<\/strong><\/p>\n<p>&lt;xs:com plexContent&gt;<\/p>\n<p>&lt;xs:extension base=&#8221;personName&#8221;&gt;<\/p>\n<p>&lt;xs:sequence&gt;<\/p>\n<p>&lt;xs:element name=&#8221;generation&#8221; minOccurs=&#8221;0&#8243;\/&gt; &lt;\/xs:sequence&gt;<\/p>\n<p>&lt;\/xs:extension&gt;<\/p>\n<p>&lt;\/xs:com plexContent&gt;<\/p>\n<p>&lt;\/xs:com plexType&gt;<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Since we have already seen an example of restriction in simple type definition. In this example we have illustrated the property extension with inheritance. Based on a complex type called personName, we define a new complex type by using extension element. Here we add a new element called generation.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Summary<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">This module explains about the fact that XML Schema is a flexible and powerful schema language and the syntax of the schema is XML itself. The module gives an idea about simple and complex elements and about simple and complex type definitions. The module also explores a variety of data types and ability to extend type system.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Web Links<\/strong><\/p>\n<ul>\n<li><em>www.w3schools.com\/<strong>xml<\/strong><\/em><\/li>\n<li><em>cs.lamar.edu\/faculty\/osborne\/5369\/sp04\/<strong>XMLschema<\/strong>.<strong>ppt<\/strong><\/em><\/li>\n<li><em>www.tutorialspoint.com\/<strong>xml<\/strong><\/em><\/li>\n<li><em>www.cis.upenn.edu\/~matuszek\/cit597-2003\/Lectures\/30-<strong>schemas<\/strong>.<strong>ppt<\/strong><\/em><\/li>\n<li><em>https:\/\/www.w3.org\/TR\/xmlschema-1\/#components<\/em><\/li>\n<\/ul>\n","protected":false},"author":4,"menu_order":9,"template":"","meta":{"pb_show_title":"on","pb_short_title":"","pb_subtitle":"","pb_authors":["dr-m-vijayalakshmi"],"pb_section_license":""},"chapter-type":[],"contributor":[58],"license":[],"class_list":["post-71","chapter","type-chapter","status-publish","hentry","contributor-dr-m-vijayalakshmi"],"part":3,"_links":{"self":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-json\/pressbooks\/v2\/chapters\/71","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-json\/pressbooks\/v2\/chapters"}],"about":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-json\/wp\/v2\/types\/chapter"}],"author":[{"embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-json\/wp\/v2\/users\/4"}],"version-history":[{"count":17,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-json\/pressbooks\/v2\/chapters\/71\/revisions"}],"predecessor-version":[{"id":498,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-json\/pressbooks\/v2\/chapters\/71\/revisions\/498"}],"part":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-json\/pressbooks\/v2\/parts\/3"}],"metadata":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-json\/pressbooks\/v2\/chapters\/71\/metadata\/"}],"wp:attachment":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-json\/wp\/v2\/media?parent=71"}],"wp:term":[{"taxonomy":"chapter-type","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-json\/pressbooks\/v2\/chapter-type?post=71"},{"taxonomy":"contributor","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-json\/wp\/v2\/contributor?post=71"},{"taxonomy":"license","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-json\/wp\/v2\/license?post=71"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}