{"id":75,"date":"2018-07-26T06:53:51","date_gmt":"2018-07-26T06:53:51","guid":{"rendered":"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/?post_type=chapter&#038;p=75"},"modified":"2018-08-02T05:58:13","modified_gmt":"2018-08-02T05:58:13","slug":"xmlschema-part-ii","status":"publish","type":"chapter","link":"https:\/\/ebooks.inflibnet.ac.in\/csp12\/chapter\/xmlschema-part-ii\/","title":{"rendered":"XMLSCHEMA (PART II)"},"content":{"raw":"<div>\r\n\r\n<strong>XML Data Components<\/strong>\r\n\r\n&nbsp;\r\n\r\nAn XML file includes two kinds of data items namely Elements and Attributes.\r\n\r\n&nbsp;\r\n\r\n<strong>Elements:<\/strong>\r\n\r\n&nbsp;\r\n\r\n&lt;article mdate=\"<strong>2002-01-03<\/strong>\" \u2026&gt;\r\n\r\n&lt;e ditor&gt;XXX&lt;\/editor&gt;\r\n\r\n&lt;\/article&gt;\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">The elements are identified to have an hierarchical structure with an open tag and close tag pairs. An element may include nested elements. An element may also include attributes within the element\u2019s open tag. Multiple elements may have same name but the order by which the element appears within the file matters.<\/p>\r\n&nbsp;\r\n\r\n&nbsp;\r\n\r\n<strong>Attributes:<\/strong>\r\n\r\n&nbsp;\r\n\r\nmdate=\"<strong>2002-01-03<\/strong>\"\r\n\r\n<\/div>\r\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0 \u00a0Attributes are named values and are not hierarchical. Only one attribute with a given name can appear within a element and the order of the attributes within the element does not matter.<\/span><\/p>\r\n\r\n<div>\r\n\r\n<strong>\u00a0 \u00a0 \u00a0\u201cSimple\u201d and \u201ccomplex\u201d elements<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">A \u201csimple\u201d element is one that contains text and nothing else. A simple element cannot have attributes and it cannot contain other elements. Further, a simple element cannot be empty.<\/p>\r\n<p style=\"text-align: justify\">However, the text can be of many different types, and may have various restrictions applied to it. If an element isn\u2019t simple, then it is called as a \u201ccomplex\u201d element. A complex element may have attributes. A complex element may be empty, or it may contain text, other elements, or both text and other elements.<\/p>\r\n&nbsp;\r\n\r\n<strong>Simple element<\/strong>\r\n\r\n&nbsp;\r\n\r\nA simple element is defined as\r\n\r\n&lt;xs:element\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 name=\"<strong><em>name<\/em><\/strong>\"\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 type=\"<strong><em>type<\/em><\/strong>\" \/&gt;\r\n\r\nwhere,\r\n<ul>\r\n \t<li><strong><em>name<\/em><\/strong> is the name of the element<\/li>\r\n \t<li>the most common values for <strong><em>type<\/em><\/strong> are<\/li>\r\n<\/ul>\r\nxs:boolean\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 xs:integer\r\n\r\nxs:date\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 xs:string\r\n\r\nxs:decimal\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 xs:time\r\n\r\n&nbsp;\r\n\r\nOther attributes a simple element may have are, \u201cdefault\u201d and \u201cfixed\u201d.\r\n<ul>\r\n \t<li>default= \"<strong><em>default value<\/em><\/strong>\" <em>is used if no other value is specified<\/em><\/li>\r\n \t<li>\u00a0fixed= \"<strong><em>value<\/em><\/strong>\u201c <em>is used if no other value may be specified<\/em><\/li>\r\n<\/ul>\r\n<strong>\u00a0 \u00a0 Defining an attribute<\/strong>\r\n\r\n&nbsp;\r\n\r\nAttributes themselves are always declared as simple types.\r\n\r\nAn attribute is defined as\r\n\r\n&lt;xs:attribute\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 name=\"<strong><em>name<\/em><\/strong>\"\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 type=\"<strong><em>type<\/em><\/strong>\" \/&gt;\r\n\r\nwhere:\r\n<ul>\r\n \t<li><strong><em>name<\/em><\/strong> and <strong><em>type<\/em><\/strong> are the same as for xs:element<\/li>\r\n<\/ul>\r\n<p style=\"text-align: justify\">\u00a0 \u00a0 \u00a0Other attributes a simple attribute may have are \u201cdefault\u201d, \u201cfixed\u201d and \u201cuse\u201d. \"<strong><em>default value<\/em><\/strong>\" <em>is used if no other value is specified<\/em><\/p>\r\n\r\n<\/div>\r\n<ul>\r\n \t<li><span style=\"text-align: initial;font-size: 1em\">\u00a0fixed = \"value\u201c\u00a0 is used if no other value may be specified<\/span><\/li>\r\n \t<li><span style=\"text-align: initial;font-size: 1em\">\u00a0use = \"optional\"<\/span><em style=\"text-align: initial;font-size: 1em\">specifies the attribute is not required (default)<\/em><\/li>\r\n \t<li><span style=\"text-align: initial;font-size: 1em\">\u00a0use = \"required\"<\/span><em style=\"text-align: initial;font-size: 1em\">specifies the attribute must be present<\/em><\/li>\r\n<\/ul>\r\n<div>\r\n\r\n<strong>\u00a0 \u00a0 Restrictions, or \u201cfacets\u201d<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Restrictions are used to define acceptable values for XML elements or attributes. Restrictions on XML elements are called facets. The restriction element defines restrictions on a simpleType, simpleContent, or complexContent definition.<\/p>\r\n&nbsp;\r\n\r\nThe general form for putting a restriction on a text value is by the use of the defined schema element called &lt;xs:restriction&gt; &lt;\/xs:restriction&gt;.\r\n\r\nThe syntax of defining it is given below,\r\n\r\n&nbsp;\r\n\r\n&lt;xs:element\u00a0 name=\"<em>name<\/em>\"&gt;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <em>or <\/em>xs:attribute<em> )<\/em>\r\n\r\n&lt;xs:restriction base=\"<em>type<\/em>\"&gt;\r\n\r\n<em>... the restrictions ...<\/em>\r\n\r\n&lt;\/xs:restriction&gt;\r\n\r\n&lt;\/xs:element&gt;\r\n\r\n&nbsp;\r\n\r\nAn example:\r\n\r\n&nbsp;\r\n\r\n&lt;xs:element\u00a0 name=\"age\"&gt;\r\n\r\n&lt;xs:restriction base=\"xs:integer\"&gt;\r\n\r\n&lt;xs:minInclusive value=\"0\"&gt;\r\n\r\n&lt;xs:maxInclusive value=\"140\"&gt;\r\n\r\n&lt;\/xs:restriction&gt;\r\n\r\n&lt;\/xs:element&gt;\r\n\r\n&nbsp;\r\n\r\n<strong>Restrictions on numbers<\/strong>\r\n\r\n&nbsp;\r\n\r\nThe following are some of the restrictions that can be applied on numbers.\r\n<ul>\r\n \t<li>\u00a0 minInclusive \u2013 is used when the number must be \u2265 the given <strong><em>value<\/em><\/strong><\/li>\r\n \t<li>\u00a0 minExclusive -- is used when the number must be &gt; the given <strong><em>value<\/em><\/strong><\/li>\r\n \t<li>\u00a0 maxInclusive -- is used when the number must be \u2264 the given <strong><em>value<\/em><\/strong><\/li>\r\n \t<li>\u00a0 maxExclusive -- is used when the number must be &lt; the given <strong><em>value<\/em><\/strong><\/li>\r\n \t<li>\u00a0 totalDigits -- is used when the number must have exactly <strong><em>value<\/em><\/strong> digits<\/li>\r\n \t<li>fractionDigits -- is used when the number must have no more than <strong style=\"text-align: initial;font-size: 1em\"><em>value<\/em><\/strong><span style=\"text-align: initial;font-size: 1em\"> digits after the decimal point.<\/span><\/li>\r\n<\/ul>\r\n<\/div>\r\n<div>\r\n\r\n<strong>\u00a0 \u00a0 \u00a0Restrictions on strings<\/strong>\r\n\r\n&nbsp;\r\n\r\nThe following are the restrictions that can be used with strings.\r\n<ul>\r\n \t<li style=\"text-align: justify\">\u00a0 length -- is used when the string must contain exactly <strong><em>value<\/em><\/strong> characters<\/li>\r\n \t<li style=\"text-align: justify\">\u00a0minLength -- is used when the string must contain at least <strong><em>value<\/em><\/strong> characters<\/li>\r\n \t<li style=\"text-align: justify\">\u00a0maxLength -- is used when the string must contain no more than <strong><em>value<\/em><\/strong> characters<\/li>\r\n \t<li style=\"text-align: justify\">\u00a0pattern -- is used when the <strong><em>value<\/em><\/strong> is a regular expression that the string must match<\/li>\r\n \t<li style=\"text-align: justify\">\u00a0whiteSpace \u2013 is not really a \u201crestriction\u201d but it tells what to do with whitespace.<\/li>\r\n \t<li style=\"text-align: justify\">\u00a0The value = \"preserve\" denotes to keep all whitespaces.<\/li>\r\n \t<li style=\"text-align: justify\">\u00a0The value = \"replace\u201d denotes to change all whitespace characters to spaces<\/li>\r\n \t<li style=\"text-align: justify\">\u00a0The value = \"collapse\u201d denotes to remove leading and trailing whitespace, and replace all sequences of whitespace with a single space.<\/li>\r\n<\/ul>\r\n<strong>\u00a0 \u00a0 Enumeration<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">An enumeration constraint restricts the value to be one of a fixed set of values that normally limits the content of an XML element.<\/p>\r\n&nbsp;\r\n\r\n<strong>Example:<\/strong>\r\n\r\n&nbsp;\r\n\r\n&lt;xs:element name=\"season\"&gt;\r\n\r\n&lt;xs:simpleType&gt;\r\n\r\n&lt;xs:restriction\u00a0 base=\"xs:string\"&gt;\r\n\r\n&lt;xs:enumeration value=\"Spring\"\/&gt;\r\n\r\n&lt;xs:enumeration value=\"Summer\"\/&gt;\r\n\r\n&lt;xs:enumeration value=\"Autumn\"\/&gt;\r\n\r\n&lt;xs:enumeration value=\"Fall\"\/&gt;\r\n\r\n&lt;xs:enumeration value=\"Winter\"\/&gt;\r\n\r\n&lt;\/xs:restriction&gt;\r\n\r\n&lt;\/xs:simpleType&gt;\r\n\r\n&lt;\/xs:element&gt;\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">In this example, we restrict the element \u2018season\u2019 to take any of these values as \u2018spring\u2019, \u2018summer\u2019, \u2018Autumn\u2019, \u2018Fall\u2019 and \u2018Winter\u2019.<\/p>\r\n\r\n<\/div>\r\n<strong style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0 Complex elements<\/strong>\r\n<div>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">A complex element is defined with the schema element &lt;complexType&gt; &lt;\/complexType&gt;. The syntax is given below,<\/p>\r\n&nbsp;\r\n\r\n&lt;xs:element\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 name=\"<em>name<\/em>\"&gt;\r\n\r\n&lt;xs:com plexType&gt;\r\n\r\n<em>... information about the complex type...<\/em>\r\n\r\n&lt;\/xs:com plexType&gt;\r\n\r\n&lt;\/xs:element&gt;\r\n\r\n&nbsp;\r\n\r\n<strong>Example:<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">In this example, we have defined a complex element \u2018person\u2019 to have two simple elements called \u2018firstName\u2019 and \u2018lastName\u2019.<\/p>\r\n&nbsp;\r\n\r\n&lt;xs:element\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 name=\"person\"&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=\"firstName\" type=\"xs:string\" \/&gt; &lt;xs:element name=\"lastName\" type=\"xs:string\" \/&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&nbsp;\r\n\r\nThe element &lt;xs:sequence&gt; says that elements must occur in this order.\r\n\r\n<em>Note: Remember that attributes are always simple types.<\/em>\r\n\r\n&nbsp;\r\n\r\n<strong>Global and local definitions<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">The elements that are declared at the \u201ctop level\u201d of a &lt;schema&gt; are available for use throughout the schema. They are considered as global definitions.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\">The elements declared within a &lt;xs:complexType&gt; are local to that type and are considered as local definitions.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\">Thus, in the definition of the element \u2018person\u2019 the elements \u2018firstName\u2019 and \u2018lastName\u2019 are only locally declared.<\/p>\r\n&nbsp;\r\n\r\n&lt;xs:element\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 name=\"person\"&gt;\r\n\r\n&lt;xs:com plexType&gt;\r\n\r\n<span style=\"font-size: 1em;text-align: initial\">&lt;xs:sequence&gt;<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">&lt;xs:element\u00a0 name=\"firstName\"\u00a0 type=\"xs:string\" \/&gt;<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">&lt;xs:element name=\"lastName\" type=\"xs:string\" \/&gt; &lt;\/xs:sequence&gt;<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">&lt;\/xs:com plexType&gt;<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">&lt;\/xs:element&gt;<\/span>\r\n\r\n<\/div>\r\n<div>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">But the order of declarations at the \u201ctop level\u201d of a &lt;schema&gt; does not specify the order in the XML data document.<\/p>\r\n&nbsp;\r\n\r\n<strong>Declaration and Use<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">So far we have been talking about how to <em>declare<\/em> types but not about how to <em>use<\/em> them.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\">To <em>use<\/em> a type we have declared, use it as the value of type=\"...\". Here we should note that the type specifies the user defined type we have already defined and not the predefined types.<\/p>\r\n&nbsp;\r\n\r\nExamples:\r\n\r\n&nbsp;\r\n\r\n&lt;xs:element name=\"student\"\u00a0 type=\"person\"\/&gt;\r\n\r\n&lt;xs:element name=\"professor\" type=\"person\"\/&gt;\r\n\r\n&nbsp;\r\n\r\nThe example says that the element \u2018student\u2019 is defined to be \u2018person\u2019 type which we have already defined.\r\n\r\n<em>Note:<\/em><em> Here the Scope is important: We cannot use a type if it is local to some other type.<\/em>\r\n\r\n&nbsp;\r\n\r\n<strong>Model Groups<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Model Groups are used to define an element that has mixed content of elements and text mixed or element content. Model Groups can be defined with the keywords such as \u2018all\u2019, \u2018choice\u2019 and \u2018sequence\u2019. <em>all <\/em>- is used when the elements specified must all be there, but it can appear in any order.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\"><em>choice <\/em>\u2013 is used when any of the elements specified may or may not be there<\/p>\r\n<p style=\"text-align: justify\"><em>Sequence <\/em>\u2013 is used when all of the elements specified must appear in the specified order<\/p>\r\n&nbsp;\r\n\r\n<strong>xs:sequence<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">We have already seen an example of a complex type whose elements must occur in a specific order.<span style=\"text-align: initial;font-size: 1em\">Here in this example we have used the model group \u2018sequence\u2019 which specifies that within the \u2018person\u2019 element \u2018firstName\u2019 and \u2018lastName\u2019 should appear in the specified order.<\/span><\/p>\r\n&nbsp;\r\n\r\n<\/div>\r\n<div>\r\n\r\n\u00a0 \u00a0&lt;xs:element\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 name=\"person\"&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=\"firstName\" type=\"xs:string\" \/&gt; &lt;xs:element name=\"lastName\" type=\"xs:string\" \/&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&nbsp;\r\n\r\n<strong>xs:all<\/strong>\r\n\r\n&nbsp;\r\n\r\nxs:all allows elements to appear in any order but all elements should appear within the element.\r\n\r\n&lt;xs:element\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 name=\"person\"&gt;\r\n\r\n&lt;xs:com plexType&gt;\r\n\r\n&lt;xs:all&gt;\r\n\r\n&lt;xs:element name=\"firstName\" type=\"xs:string\" \/&gt; &lt;xs:element name=\"lastName\" type=\"xs:string\" \/&gt;\r\n\r\n&lt;\/xs:all&gt;\r\n\r\n&lt;\/xs:com plexType&gt;\r\n\r\n&lt;\/xs:element&gt;\r\n<p style=\"text-align: justify\">Despite the name, the members of an xs:all group can occur once or not at all.<\/p>\r\n<p style=\"text-align: justify\">We can use minOccurs=\"0\" to specify that an element is optional (default value is 1). In this context, maxOccurs is always 1.<\/p>\r\n&nbsp;\r\n\r\n<strong>Referencing<\/strong>\r\n\r\n&nbsp;\r\n\r\nOnce you have defined an element or attribute (with name=\"...\"), we can refer to it with the keyword ref=\"...\"\r\n\r\nBelow is an example to explain this.\r\n\r\n&nbsp;\r\n\r\n&lt;xs:element\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 name=\"person\"&gt;\r\n\r\n&lt;xs:com plexType&gt;\r\n\r\n&lt;xs:all&gt;\r\n\r\n&lt;xs:element name=\"firstName\" type=\"xs:string\" \/&gt; &lt;xs:element name=\"lastName\" type=\"xs:string\" \/&gt;\r\n\r\n<span style=\"font-size: 1em;text-align: initial\">&lt;\/xs:all&gt;<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">&lt;\/xs:com plexType&gt;<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">&lt;\/xs:element&gt;<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">&lt;xs:element\u00a0 name=\"student\"\u00a0 ref=\"person\"&gt;<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">Or just:\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;xs:element\u00a0 ref=\"person\"&gt;<\/span>\r\n\r\n<\/div>\r\n<div>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">In this example, a complex type &lt;person&gt; has been created and it had been referred as the type for the &lt;student&gt; element when it is defined.<\/p>\r\n&nbsp;\r\n\r\n<strong>Text element with attributes<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">If a text element has attributes, it is no longer considered as a simple type but as an element. Here, we make use of the schema element &lt;simpleContent&gt; to define a text element that has attributes.<\/p>\r\n&nbsp;\r\n\r\n&lt;xs:element\u00a0 name=\"population\"&gt;\r\n\r\n&lt;xs:com plexType&gt;\r\n\r\n&lt;xs:simpleContent&gt;\r\n\r\n&lt;xs:extension\u00a0 base=\"xs:integer\"&gt;\r\n\r\n&lt;xs:attribute\u00a0 name=\"year\u201d\r\n\r\ntype=\"xs:integer\"&gt;\r\n\r\n&lt;\/xs:extension&gt;\r\n\r\n&lt;\/xs:simpleContent&gt;\r\n\r\n&lt;\/xs:com plexType&gt;\r\n\r\n&lt;\/xs:element&gt;\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">In the above syntax, the element \u2018population\u2019 has an attribute \u2018name\u2019 which is defined using a schema element called &lt;simpleContent&gt;.<\/p>\r\n&nbsp;\r\n\r\n<strong>Empty elements<\/strong>\r\n\r\n&nbsp;\r\n\r\nEmpty elements are defined as complex elements. An example of defining an empty element is given below.\r\n\r\n&nbsp;\r\n\r\n&lt;xs:com plexType\u00a0 name=\"counter\"&gt;\r\n\r\n&lt;xs:com plexContent&gt;\r\n\r\n&lt;xs:extension\u00a0 base=\"xs:anyType\"\/&gt;\r\n\r\n&lt;xs:attribute\u00a0 name=\"count\"\u00a0 type=\"xs:integer\"\/&gt;\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">&lt;\/xs:com plexContent&gt;<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">&lt;\/xs:com plexType&gt;<\/span>\r\n\r\n<\/div>\r\n<div>\r\n\r\n\u00a0 \u00a0Here, we define the empty element \u2018counter\u2019 with the schema element &lt;complexContent&gt;.\r\n\r\n&nbsp;\r\n\r\n<strong>Mixed elements<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Mixed elements may contain both text and elements. To define a mixed element, we add the attribute mixed=\"true\" to the &lt;xs:complexType&gt; element. The text itself is not mentioned in the element, and may go anywhere and it is basically ignored.<\/p>\r\n&nbsp;\r\n\r\n&lt;xs:com plexType name=\"paragraph\" mixed=\"true\"&gt; &lt;xs:sequence&gt;\r\n\r\n&lt;xs:element\u00a0 name=\"someName\u201d type=\"xs:anyType\"\/&gt;\r\n\r\n&lt;\/xs:sequence&gt;\r\n\r\n&lt;\/xs:com plexType&gt;\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Here, the element \u2018paragraph\u2019 has been defined as a complex type that is composed of another element.<\/p>\r\n&nbsp;\r\n\r\n<strong>Extensions<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">We can base a complex type on another complex type. The complex type is an extension of another complex type with the use of the attribute base = \u201cotherType\u201d.<\/p>\r\n&nbsp;\r\n\r\n&lt;xs:com plexType\u00a0 name=\"newType\"&gt;\r\n\r\n&lt;xs:com plexContent&gt;\r\n\r\n&lt;xs:extension\u00a0 base=\"otherType\"&gt;\r\n\r\n...new stuff...\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\r\n<strong>Type Extensions<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">A third way of creating a complex type is to extend another complex type like inheritance in Object Oriented concepts.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\"><span style=\"font-size: 1em;text-align: initial\">In this example, we define the element \u2018Employee\u2019 as of type \u2018PersonInfoType\u2019. The name of the employee is defined as a complexType which extends from \u2018PersonNameType\u2019.<\/span><\/p>\r\n\r\n<\/div>\r\n<div>\r\n\r\n&nbsp;\r\n\r\n&lt;xs:element name=\"Em ployee\" type=\"PersonInfoType\"\/&gt; &lt;xs:com plexType name=\"PersonNameType\"&gt;\r\n\r\n&lt;xs:sequence&gt;\r\n\r\n&lt;xs:element name=\"FirstName\" type=\"xs:string\"\/&gt; &lt;xs:element name=\"LastName\" type=\"xs:string\"\/&gt;\r\n\r\n&lt;\/xs:sequence&gt;\r\n\r\n&lt;\/xs:com plexType&gt;\r\n\r\n&lt;xs:com plexType name=\"PersonInfoType\"&gt;\r\n\r\n&lt;xs:com plexContent&gt;\r\n\r\n&lt;xs:extension base=\"PersonNameType\"&gt;\r\n\r\n&lt;xs:sequence&gt;\r\n\r\n&lt;xs:element name=\"Address\" type=\"xs:string\"\/&gt;\r\n\r\n&lt;xs:element name=\"City\" type=\"xs:string\"\/&gt;\r\n\r\n&lt;xs:element name=\"Country\" type=\"xs:string\"\/&gt;\r\n\r\n&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\r\n<strong>Type Extensions (use)<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">The below syntax demonstrates the use of a type that is an extension of another. It is used as though it were all defined in a single type.<\/p>\r\n&nbsp;\r\n\r\n&lt;Employee xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema -instance\"\r\n\r\nxsi:noNamespaceSchemaLocation=\"TypeExtension.xsd\"&gt;\r\n\r\n&lt;FirstName&gt;King&lt;\/FirstName&gt;\r\n\r\n&lt;LastName&gt;Arthur&lt;\/LastName&gt;\r\n\r\n&lt;Address&gt;Round Table&lt;\/Address&gt;\r\n\r\n&lt;City&gt;Camelot&lt;\/City&gt;\r\n\r\n&lt;Country&gt;England&lt;\/Country&gt;\r\n\r\n&lt;\/Employee&gt;\r\n\r\n<\/div>\r\n<strong style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0 Simple Content in Complex Type<\/strong>\r\n<div>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">If a type contains only simple content (text and attributes), a &lt;simpleContent&gt; element can be put inside<\/p>\r\nthe &lt;complexType&gt;.\r\n\r\n&nbsp;\r\n\r\nA &lt;simpleContent&gt; must have either a &lt;extension&gt; or a &lt;restriction&gt;.\r\n\r\n&nbsp;\r\n\r\n&lt;xs:element name=\"dialog\"&gt;\r\n\r\n&lt;xs:com plexType&gt;\r\n\r\n&lt;xs:simpleContent&gt;\r\n\r\n&lt;xs:extension base=\"xs:string\"&gt;\r\n\r\n&lt;xs:attribute name=\"speaker\" type=\"xs:string\" use=\"required\"\/&gt; &lt;\/xs:extension&gt;\r\n\r\n&lt;\/xs:simpleContent&gt;\r\n\r\n&lt;\/xs:com plexType&gt;\r\n\r\n&lt;\/xs:element&gt;\r\n\r\n&nbsp;\r\n\r\n<strong>Predefined string types:<\/strong>\r\n\r\n&nbsp;\r\n\r\nRecall that a simple element is defined as:\r\n\r\n&nbsp;\r\n\r\n&lt;xs:element\u00a0 name=\"name\"\u00a0 type=\"type\" \/&gt;\r\n\r\nHere are a few of the possible string types that are given below.\r\n<ul>\r\n \t<li style=\"text-align: justify\">\u00a0 xs:string -- a string<\/li>\r\n \t<li style=\"text-align: justify\">\u00a0xs:normalizedString -- a string that doesn\u2019t contain tabs, newlines, or carriage returns<\/li>\r\n \t<li style=\"text-align: justify\">\u00a0xs:token -- a string that doesn\u2019t contain any whitespace other than single spaces<\/li>\r\n<\/ul>\r\n<p style=\"text-align: justify\">\u00a0 \u00a0Allowable restrictions on strings are, enumeration, length, maxLength, minLength, pattern and whiteSpace.<\/p>\r\n&nbsp;\r\n\r\n<strong>Predefined date and time types:<\/strong>\r\n\r\n&nbsp;\r\n\r\n\u2022\u00a0 xs:date -- A date in the format <strong><em>CCYY-MM-DD<\/em><\/strong>, for example, 2002-11-05\r\n\r\n\u2022\u00a0 xs:time \u2013 A time in the format <strong><em>hh:mm:ss<\/em><\/strong> (hours, minutes, seconds)\r\n\r\n\u2022\u00a0 xs:dateTime -- Format is <strong><em>CCYY-MM-DD<\/em>T<em>hh:mm:ss<\/em><\/strong>\r\n\r\n\u2013\u00a0\u00a0 The T is part of the syntax.\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Allowable restrictions on dates and times are, enumeration, minInclusive, minExclusive, maxInclusive, maxExclusive, pattern and whiteSpace.<\/p>\r\n\r\n<\/div>\r\n<strong style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0Predefined numeric types:<\/strong>\r\n<div>\r\n\r\n\u00a0 \u00a0Some of the predefined numeric types are given below,\r\n<table style=\"border-collapse: collapse;width: 99.9394%;height: 126px\" border=\"1\">\r\n<tbody>\r\n<tr style=\"height: 28px\">\r\n<td style=\"width: 49.9394%;height: 28px\">xs:decimal<\/td>\r\n<td style=\"width: 50%;height: 28px\">xs:positiveInteger<\/td>\r\n<\/tr>\r\n<tr style=\"height: 28px\">\r\n<td style=\"width: 49.9394%;height: 28px\">xs:byte<\/td>\r\n<td style=\"width: 50%;height: 28px\">xs:negativeInteger<\/td>\r\n<\/tr>\r\n<tr style=\"height: 14px\">\r\n<td style=\"width: 49.9394%;height: 14px\">xs:short<\/td>\r\n<td style=\"width: 50%\">xs:nonPositiveInteger<\/td>\r\n<\/tr>\r\n<tr style=\"height: 14px\">\r\n<td style=\"width: 49.9394%;height: 14px\">xs:int<\/td>\r\n<td style=\"width: 50%;height: 14px\">xs:nonNegativeInteger<\/td>\r\n<\/tr>\r\n<tr style=\"height: 28px\">\r\n<td style=\"width: 49.9394%;height: 28px\">xs:long<\/td>\r\n<td style=\"width: 50%;height: 28px\"><\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n&nbsp;\r\n<p style=\"text-align: justify\">Allowable restrictions on numeric types are enumeration, minInclusive, minExclusive, maxInclusive, maxExclusive, fractionDigits, totalDigits, pattern and whiteSpace.<\/p>\r\n&nbsp;\r\n\r\n<strong>Types<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Both elements and attributes have types, which are defined in the Schema. We can reuse types by giving them names.<\/p>\r\n&nbsp;\r\n\r\nFor example, we define a schema Addr.xsd\r\n\r\n&nbsp;\r\n\r\nAddr.xsd:\r\n\r\n&lt;xsd:element name=\"Address\"&gt;\r\n\r\n&lt;xsd:com plexType&gt;\r\n\r\n&lt;xsd:sequence&gt;\r\n\r\n&lt;xsd:element name=\"Street\" type=\"xsd:string\"\/&gt; &lt;xsd:element name=\"Apartment\" type=\"xsd:string\"\/&gt; &lt;xsd:element name=\"Zip\" type=\"xsd:string\"\/&gt;\r\n\r\n&lt;\/xsd:sequence&gt;\r\n\r\n&lt;\/xsd:com plexType&gt;\r\n\r\n&lt;\/xsd:element&gt;\r\n\r\n&nbsp;\r\n\r\n<strong>(or)<\/strong>\r\n\r\n&nbsp;\r\n\r\n&lt;xsd:com plexType name=\"AddrType\"&gt;\r\n\r\n&lt;xsd:sequence&gt;\r\n\r\n&lt;xsd:element name=\"Street\" type=\"xsd:string\"\/&gt; &lt;xsd:element name=\"Apartment\" type=\"xsd:string\"\/&gt; &lt;xsd:element name=\"Zip\" type=\"xsd:string\"\/&gt;\r\n\r\n&lt;\/xsd:sequence&gt;\r\n\r\n&lt;\/xsd:com plexType&gt;\r\n\r\n&lt;xsd:element name=\u201cShipAddress\" type=\"AddrType \"\/&gt; &lt;xsd:element name=\u201cBillAddress\" type=\"AddrType\"\/&gt;\r\n\r\n<\/div>\r\n<strong style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0Complex Type Definition<\/strong>\r\n<div>\r\n\r\n<strong>\u00a0 \u00a0 Composition<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Model Group is composed of Compositor such as <em>sequence<\/em> or <em>choice<\/em> or <em>all<\/em> and Particles, which can be Element Declaration or a Wildcard or a Model Group.<\/p>\r\n<p style=\"text-align: justify\">The model group schema component has the following properties:<\/p>\r\n<em>{compositor}<\/em>\r\n\r\nOne of all, choice or sequence.\r\n\r\n<em>{particles}<\/em>\r\n\r\nA list of particles\r\n\r\n<em>{annotation}<\/em>\r\n\r\nOptional. An annotation.\r\n\r\n&nbsp;\r\n\r\n<strong>Annotations<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Annotations are provided for human-targeted documentations and machine-targeted documentations of schema components. They are actually meta-data.<\/p>\r\n&nbsp;\r\n\r\n<em>The annotation schema component has the following properties:<\/em>\r\n\r\n<em>{application information}<\/em>\r\n\r\n<em>A sequence of element information items.<\/em>\r\n\r\n<em>{user information}<\/em>\r\n\r\n<em>A sequence of element information items.<\/em>\r\n\r\n<em>{attributes}<\/em>\r\n\r\n<em>A sequence of attribute information items.<\/em>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">The XML representation for an annotation schema component is an &lt;annotation&gt; element information item.<\/p>\r\n&nbsp;\r\n\r\n&lt;xs:simpleType fn:note=\"special\"&gt;\r\n\r\n&lt;xs:annotation&gt;\r\n\r\n&lt;xs:documentation&gt;A type for experts only&lt;\/xs:documentation&gt; &lt;xs:appinfo&gt;\r\n\r\n&lt;fn:specialHandling&gt;checkForPrimes&lt;\/fn:specialHandling&gt;\r\n\r\n&lt;\/xs:appinfo&gt;\r\n\r\n&lt;\/xs:annotation&gt;\r\n\r\n<\/div>\r\n<strong style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0 Declarations<\/strong>\r\n<div>\r\n\r\n&nbsp;\r\n\r\nExample\r\n\r\n&nbsp;\r\n\r\n&lt;xs:element name=\"PurchaseOrder\" type=\"PurchaseOrderType\"\/&gt; &lt;xs:element name=\"gift\"&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=\"birthday\" type=\"xs:date\"\/&gt;\r\n\r\n&lt;xs:element ref=\"PurchaseOrder\"\/&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:attribute name=\"age\" type=\"xs:positiveInteger\" use=\"required\"\/&gt; &lt;xs:notation name=\"jpeg\" public=\"image\/jpeg\" system=\"viewer.exe\"&gt;\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">The example shows the declaration of the element 'PurchaseOrder' which is defined as 'PurchaseOrderType' and is composed of complex element 'gift', attribute 'age' and notation 'jpeg'.<\/p>\r\n&nbsp;\r\n\r\n<strong>Example Schema<\/strong>\r\n\r\n&nbsp;\r\n\r\nAn example to illustrate the concepts we have seen so far is given below.\r\n\r\n&nbsp;\r\n\r\n&lt;?xml version=\u201e1.0\u201c ?&gt;\r\n\r\n&lt;xsd:schema xmlns:xsd= http:\/\/w3.org\/2001\/XMLSchema\u201c&gt; &lt;xsd:element name=book\u201c type=BookType\u201c\/&gt;\r\n\r\n&lt;xsd:com plexType name= BookT ype\u201c&gt;\r\n\r\n&lt;xsd:sequence&gt;\r\n\r\n&lt;xsd:element name= title\u201c type= xsd:string\u201c\/&gt; &lt;xsd:element name= author\u201c type= PersonType\u201c\r\n\r\nminOccurs=1\u201c maxOccurs= unbounded\u201c\/&gt;\r\n\r\n&lt;xsd:com plexType name= PersonType\u201c&gt;\r\n\r\n&lt;xsd:sequence&gt; ... &lt;xsd:sequence&gt;\r\n\r\n&lt;\/xsd:com plexType&gt;\r\n\r\n&lt;xsd:element name= publisher\u201c type= xsd:anyType\u201c\/&gt; &lt;\/xsd:sequence&gt;\r\n\r\n&lt;\/xsd:com plexType&gt;\r\n\r\n&lt;\/xsd:schema&gt;\r\n\r\n<\/div>\r\n<strong>\u00a0 \u00a0Summary<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">This module has explained about defining simple elements and complex elements. The module also explains that there exists variety of data \u201cfacets\u201d and \u201cpatterns\u201d to impose domain constraints. The elements can be type defined by applying inheritance. Moreover, the module explains about defining advanced constraints such as \u201cprimary key\u201d and \u201creferential integrity\u201d.<\/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>https:\/\/www.w3.org\/TR\/xmlschema-1\/#components<\/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>people.cs.uchicago.edu\/~asiegel\/courses\/cspp51038...\/<strong>XMLSchema<\/strong>.ppt<\/em><\/li>\r\n<\/ul>","rendered":"<div>\n<p><strong>XML Data Components<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>An XML file includes two kinds of data items namely Elements and Attributes.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Elements:<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>&lt;article mdate=&#8221;<strong>2002-01-03<\/strong>&#8221; \u2026&gt;<\/p>\n<p>&lt;e ditor&gt;XXX&lt;\/editor&gt;<\/p>\n<p>&lt;\/article&gt;<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">The elements are identified to have an hierarchical structure with an open tag and close tag pairs. An element may include nested elements. An element may also include attributes within the element\u2019s open tag. Multiple elements may have same name but the order by which the element appears within the file matters.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Attributes:<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>mdate=&#8221;<strong>2002-01-03<\/strong>&#8221;<\/p>\n<\/div>\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0 \u00a0Attributes are named values and are not hierarchical. Only one attribute with a given name can appear within a element and the order of the attributes within the element does not matter.<\/span><\/p>\n<div>\n<p><strong>\u00a0 \u00a0 \u00a0\u201cSimple\u201d and \u201ccomplex\u201d elements<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">A \u201csimple\u201d element is one that contains text and nothing else. A simple element cannot have attributes and it cannot contain other elements. Further, a simple element cannot be empty.<\/p>\n<p style=\"text-align: justify\">However, the text can be of many different types, and may have various restrictions applied to it. If an element isn\u2019t simple, then it is called as a \u201ccomplex\u201d element. A complex element may have attributes. A complex element may be empty, or it may contain text, other elements, or both text and other elements.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Simple element<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>A simple element is defined as<\/p>\n<p>&lt;xs:element\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 name=&#8221;<strong><em>name<\/em><\/strong>&#8221;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 type=&#8221;<strong><em>type<\/em><\/strong>&#8221; \/&gt;<\/p>\n<p>where,<\/p>\n<ul>\n<li><strong><em>name<\/em><\/strong> is the name of the element<\/li>\n<li>the most common values for <strong><em>type<\/em><\/strong> are<\/li>\n<\/ul>\n<p>xs:boolean\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 xs:integer<\/p>\n<p>xs:date\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 xs:string<\/p>\n<p>xs:decimal\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 xs:time<\/p>\n<p>&nbsp;<\/p>\n<p>Other attributes a simple element may have are, \u201cdefault\u201d and \u201cfixed\u201d.<\/p>\n<ul>\n<li>default= &#8220;<strong><em>default value<\/em><\/strong>&#8221; <em>is used if no other value is specified<\/em><\/li>\n<li>\u00a0fixed= &#8220;<strong><em>value<\/em><\/strong>\u201c <em>is used if no other value may be specified<\/em><\/li>\n<\/ul>\n<p><strong>\u00a0 \u00a0 Defining an attribute<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>Attributes themselves are always declared as simple types.<\/p>\n<p>An attribute is defined as<\/p>\n<p>&lt;xs:attribute\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 name=&#8221;<strong><em>name<\/em><\/strong>&#8221;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 type=&#8221;<strong><em>type<\/em><\/strong>&#8221; \/&gt;<\/p>\n<p>where:<\/p>\n<ul>\n<li><strong><em>name<\/em><\/strong> and <strong><em>type<\/em><\/strong> are the same as for xs:element<\/li>\n<\/ul>\n<p style=\"text-align: justify\">\u00a0 \u00a0 \u00a0Other attributes a simple attribute may have are \u201cdefault\u201d, \u201cfixed\u201d and \u201cuse\u201d. &#8220;<strong><em>default value<\/em><\/strong>&#8221; <em>is used if no other value is specified<\/em><\/p>\n<\/div>\n<ul>\n<li><span style=\"text-align: initial;font-size: 1em\">\u00a0fixed = &#8220;value\u201c\u00a0 is used if no other value may be specified<\/span><\/li>\n<li><span style=\"text-align: initial;font-size: 1em\">\u00a0use = &#8220;optional&#8221;<\/span><em style=\"text-align: initial;font-size: 1em\">specifies the attribute is not required (default)<\/em><\/li>\n<li><span style=\"text-align: initial;font-size: 1em\">\u00a0use = &#8220;required&#8221;<\/span><em style=\"text-align: initial;font-size: 1em\">specifies the attribute must be present<\/em><\/li>\n<\/ul>\n<div>\n<p><strong>\u00a0 \u00a0 Restrictions, or \u201cfacets\u201d<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Restrictions are used to define acceptable values for XML elements or attributes. Restrictions on XML elements are called facets. The restriction element defines restrictions on a simpleType, simpleContent, or complexContent definition.<\/p>\n<p>&nbsp;<\/p>\n<p>The general form for putting a restriction on a text value is by the use of the defined schema element called &lt;xs:restriction&gt; &lt;\/xs:restriction&gt;.<\/p>\n<p>The syntax of defining it is given below,<\/p>\n<p>&nbsp;<\/p>\n<p>&lt;xs:element\u00a0 name=&#8221;<em>name<\/em>&#8220;&gt;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <em>or <\/em>xs:attribute<em> )<\/em><\/p>\n<p>&lt;xs:restriction base=&#8221;<em>type<\/em>&#8220;&gt;<\/p>\n<p><em>&#8230; the restrictions &#8230;<\/em><\/p>\n<p>&lt;\/xs:restriction&gt;<\/p>\n<p>&lt;\/xs:element&gt;<\/p>\n<p>&nbsp;<\/p>\n<p>An example:<\/p>\n<p>&nbsp;<\/p>\n<p>&lt;xs:element\u00a0 name=&#8221;age&#8221;&gt;<\/p>\n<p>&lt;xs:restriction base=&#8221;xs:integer&#8221;&gt;<\/p>\n<p>&lt;xs:minInclusive value=&#8221;0&#8243;&gt;<\/p>\n<p>&lt;xs:maxInclusive value=&#8221;140&#8243;&gt;<\/p>\n<p>&lt;\/xs:restriction&gt;<\/p>\n<p>&lt;\/xs:element&gt;<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Restrictions on numbers<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>The following are some of the restrictions that can be applied on numbers.<\/p>\n<ul>\n<li>\u00a0 minInclusive \u2013 is used when the number must be \u2265 the given <strong><em>value<\/em><\/strong><\/li>\n<li>\u00a0 minExclusive &#8212; is used when the number must be &gt; the given <strong><em>value<\/em><\/strong><\/li>\n<li>\u00a0 maxInclusive &#8212; is used when the number must be \u2264 the given <strong><em>value<\/em><\/strong><\/li>\n<li>\u00a0 maxExclusive &#8212; is used when the number must be &lt; the given <strong><em>value<\/em><\/strong><\/li>\n<li>\u00a0 totalDigits &#8212; is used when the number must have exactly <strong><em>value<\/em><\/strong> digits<\/li>\n<li>fractionDigits &#8212; is used when the number must have no more than <strong style=\"text-align: initial;font-size: 1em\"><em>value<\/em><\/strong><span style=\"text-align: initial;font-size: 1em\"> digits after the decimal point.<\/span><\/li>\n<\/ul>\n<\/div>\n<div>\n<p><strong>\u00a0 \u00a0 \u00a0Restrictions on strings<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>The following are the restrictions that can be used with strings.<\/p>\n<ul>\n<li style=\"text-align: justify\">\u00a0 length &#8212; is used when the string must contain exactly <strong><em>value<\/em><\/strong> characters<\/li>\n<li style=\"text-align: justify\">\u00a0minLength &#8212; is used when the string must contain at least <strong><em>value<\/em><\/strong> characters<\/li>\n<li style=\"text-align: justify\">\u00a0maxLength &#8212; is used when the string must contain no more than <strong><em>value<\/em><\/strong> characters<\/li>\n<li style=\"text-align: justify\">\u00a0pattern &#8212; is used when the <strong><em>value<\/em><\/strong> is a regular expression that the string must match<\/li>\n<li style=\"text-align: justify\">\u00a0whiteSpace \u2013 is not really a \u201crestriction\u201d but it tells what to do with whitespace.<\/li>\n<li style=\"text-align: justify\">\u00a0The value = &#8220;preserve&#8221; denotes to keep all whitespaces.<\/li>\n<li style=\"text-align: justify\">\u00a0The value = &#8220;replace\u201d denotes to change all whitespace characters to spaces<\/li>\n<li style=\"text-align: justify\">\u00a0The value = &#8220;collapse\u201d denotes to remove leading and trailing whitespace, and replace all sequences of whitespace with a single space.<\/li>\n<\/ul>\n<p><strong>\u00a0 \u00a0 Enumeration<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">An enumeration constraint restricts the value to be one of a fixed set of values that normally limits the content of an XML element.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Example:<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>&lt;xs:element name=&#8221;season&#8221;&gt;<\/p>\n<p>&lt;xs:simpleType&gt;<\/p>\n<p>&lt;xs:restriction\u00a0 base=&#8221;xs:string&#8221;&gt;<\/p>\n<p>&lt;xs:enumeration value=&#8221;Spring&#8221;\/&gt;<\/p>\n<p>&lt;xs:enumeration value=&#8221;Summer&#8221;\/&gt;<\/p>\n<p>&lt;xs:enumeration value=&#8221;Autumn&#8221;\/&gt;<\/p>\n<p>&lt;xs:enumeration value=&#8221;Fall&#8221;\/&gt;<\/p>\n<p>&lt;xs:enumeration value=&#8221;Winter&#8221;\/&gt;<\/p>\n<p>&lt;\/xs:restriction&gt;<\/p>\n<p>&lt;\/xs:simpleType&gt;<\/p>\n<p>&lt;\/xs:element&gt;<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">In this example, we restrict the element \u2018season\u2019 to take any of these values as \u2018spring\u2019, \u2018summer\u2019, \u2018Autumn\u2019, \u2018Fall\u2019 and \u2018Winter\u2019.<\/p>\n<\/div>\n<p><strong style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0 Complex elements<\/strong><\/p>\n<div>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">A complex element is defined with the schema element &lt;complexType&gt; &lt;\/complexType&gt;. The syntax is given below,<\/p>\n<p>&nbsp;<\/p>\n<p>&lt;xs:element\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 name=&#8221;<em>name<\/em>&#8220;&gt;<\/p>\n<p>&lt;xs:com plexType&gt;<\/p>\n<p><em>&#8230; information about the complex type&#8230;<\/em><\/p>\n<p>&lt;\/xs:com plexType&gt;<\/p>\n<p>&lt;\/xs:element&gt;<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Example:<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">In this example, we have defined a complex element \u2018person\u2019 to have two simple elements called \u2018firstName\u2019 and \u2018lastName\u2019.<\/p>\n<p>&nbsp;<\/p>\n<p>&lt;xs:element\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 name=&#8221;person&#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;firstName&#8221; type=&#8221;xs:string&#8221; \/&gt; &lt;xs:element name=&#8221;lastName&#8221; type=&#8221;xs:string&#8221; \/&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>&nbsp;<\/p>\n<p>The element &lt;xs:sequence&gt; says that elements must occur in this order.<\/p>\n<p><em>Note: Remember that attributes are always simple types.<\/em><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Global and local definitions<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">The elements that are declared at the \u201ctop level\u201d of a &lt;schema&gt; are available for use throughout the schema. They are considered as global definitions.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">The elements declared within a &lt;xs:complexType&gt; are local to that type and are considered as local definitions.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Thus, in the definition of the element \u2018person\u2019 the elements \u2018firstName\u2019 and \u2018lastName\u2019 are only locally declared.<\/p>\n<p>&nbsp;<\/p>\n<p>&lt;xs:element\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 name=&#8221;person&#8221;&gt;<\/p>\n<p>&lt;xs:com plexType&gt;<\/p>\n<p><span style=\"font-size: 1em;text-align: initial\">&lt;xs:sequence&gt;<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">&lt;xs:element\u00a0 name=&#8221;firstName&#8221;\u00a0 type=&#8221;xs:string&#8221; \/&gt;<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">&lt;xs:element name=&#8221;lastName&#8221; type=&#8221;xs:string&#8221; \/&gt; &lt;\/xs:sequence&gt;<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">&lt;\/xs:com plexType&gt;<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">&lt;\/xs:element&gt;<\/span><\/p>\n<\/div>\n<div>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">But the order of declarations at the \u201ctop level\u201d of a &lt;schema&gt; does not specify the order in the XML data document.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Declaration and Use<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">So far we have been talking about how to <em>declare<\/em> types but not about how to <em>use<\/em> them.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">To <em>use<\/em> a type we have declared, use it as the value of type=&#8221;&#8230;&#8221;. Here we should note that the type specifies the user defined type we have already defined and not the predefined types.<\/p>\n<p>&nbsp;<\/p>\n<p>Examples:<\/p>\n<p>&nbsp;<\/p>\n<p>&lt;xs:element name=&#8221;student&#8221;\u00a0 type=&#8221;person&#8221;\/&gt;<\/p>\n<p>&lt;xs:element name=&#8221;professor&#8221; type=&#8221;person&#8221;\/&gt;<\/p>\n<p>&nbsp;<\/p>\n<p>The example says that the element \u2018student\u2019 is defined to be \u2018person\u2019 type which we have already defined.<\/p>\n<p><em>Note:<\/em><em> Here the Scope is important: We cannot use a type if it is local to some other type.<\/em><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Model Groups<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Model Groups are used to define an element that has mixed content of elements and text mixed or element content. Model Groups can be defined with the keywords such as \u2018all\u2019, \u2018choice\u2019 and \u2018sequence\u2019. <em>all <\/em>&#8211; is used when the elements specified must all be there, but it can appear in any order.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\"><em>choice <\/em>\u2013 is used when any of the elements specified may or may not be there<\/p>\n<p style=\"text-align: justify\"><em>Sequence <\/em>\u2013 is used when all of the elements specified must appear in the specified order<\/p>\n<p>&nbsp;<\/p>\n<p><strong>xs:sequence<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">We have already seen an example of a complex type whose elements must occur in a specific order.<span style=\"text-align: initial;font-size: 1em\">Here in this example we have used the model group \u2018sequence\u2019 which specifies that within the \u2018person\u2019 element \u2018firstName\u2019 and \u2018lastName\u2019 should appear in the specified order.<\/span><\/p>\n<p>&nbsp;<\/p>\n<\/div>\n<div>\n<p>\u00a0 \u00a0&lt;xs:element\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 name=&#8221;person&#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;firstName&#8221; type=&#8221;xs:string&#8221; \/&gt; &lt;xs:element name=&#8221;lastName&#8221; type=&#8221;xs:string&#8221; \/&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>&nbsp;<\/p>\n<p><strong>xs:all<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>xs:all allows elements to appear in any order but all elements should appear within the element.<\/p>\n<p>&lt;xs:element\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 name=&#8221;person&#8221;&gt;<\/p>\n<p>&lt;xs:com plexType&gt;<\/p>\n<p>&lt;xs:all&gt;<\/p>\n<p>&lt;xs:element name=&#8221;firstName&#8221; type=&#8221;xs:string&#8221; \/&gt; &lt;xs:element name=&#8221;lastName&#8221; type=&#8221;xs:string&#8221; \/&gt;<\/p>\n<p>&lt;\/xs:all&gt;<\/p>\n<p>&lt;\/xs:com plexType&gt;<\/p>\n<p>&lt;\/xs:element&gt;<\/p>\n<p style=\"text-align: justify\">Despite the name, the members of an xs:all group can occur once or not at all.<\/p>\n<p style=\"text-align: justify\">We can use minOccurs=&#8221;0&#8243; to specify that an element is optional (default value is 1). In this context, maxOccurs is always 1.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Referencing<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>Once you have defined an element or attribute (with name=&#8221;&#8230;&#8221;), we can refer to it with the keyword ref=&#8221;&#8230;&#8221;<\/p>\n<p>Below is an example to explain this.<\/p>\n<p>&nbsp;<\/p>\n<p>&lt;xs:element\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 name=&#8221;person&#8221;&gt;<\/p>\n<p>&lt;xs:com plexType&gt;<\/p>\n<p>&lt;xs:all&gt;<\/p>\n<p>&lt;xs:element name=&#8221;firstName&#8221; type=&#8221;xs:string&#8221; \/&gt; &lt;xs:element name=&#8221;lastName&#8221; type=&#8221;xs:string&#8221; \/&gt;<\/p>\n<p><span style=\"font-size: 1em;text-align: initial\">&lt;\/xs:all&gt;<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">&lt;\/xs:com plexType&gt;<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">&lt;\/xs:element&gt;<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">&lt;xs:element\u00a0 name=&#8221;student&#8221;\u00a0 ref=&#8221;person&#8221;&gt;<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">Or just:\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;xs:element\u00a0 ref=&#8221;person&#8221;&gt;<\/span><\/p>\n<\/div>\n<div>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">In this example, a complex type &lt;person&gt; has been created and it had been referred as the type for the &lt;student&gt; element when it is defined.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Text element with attributes<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">If a text element has attributes, it is no longer considered as a simple type but as an element. Here, we make use of the schema element &lt;simpleContent&gt; to define a text element that has attributes.<\/p>\n<p>&nbsp;<\/p>\n<p>&lt;xs:element\u00a0 name=&#8221;population&#8221;&gt;<\/p>\n<p>&lt;xs:com plexType&gt;<\/p>\n<p>&lt;xs:simpleContent&gt;<\/p>\n<p>&lt;xs:extension\u00a0 base=&#8221;xs:integer&#8221;&gt;<\/p>\n<p>&lt;xs:attribute\u00a0 name=&#8221;year\u201d<\/p>\n<p>type=&#8221;xs:integer&#8221;&gt;<\/p>\n<p>&lt;\/xs:extension&gt;<\/p>\n<p>&lt;\/xs:simpleContent&gt;<\/p>\n<p>&lt;\/xs:com plexType&gt;<\/p>\n<p>&lt;\/xs:element&gt;<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">In the above syntax, the element \u2018population\u2019 has an attribute \u2018name\u2019 which is defined using a schema element called &lt;simpleContent&gt;.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Empty elements<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>Empty elements are defined as complex elements. An example of defining an empty element is given below.<\/p>\n<p>&nbsp;<\/p>\n<p>&lt;xs:com plexType\u00a0 name=&#8221;counter&#8221;&gt;<\/p>\n<p>&lt;xs:com plexContent&gt;<\/p>\n<p>&lt;xs:extension\u00a0 base=&#8221;xs:anyType&#8221;\/&gt;<\/p>\n<p>&lt;xs:attribute\u00a0 name=&#8221;count&#8221;\u00a0 type=&#8221;xs:integer&#8221;\/&gt;<\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">&lt;\/xs:com plexContent&gt;<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">&lt;\/xs:com plexType&gt;<\/span><\/p>\n<\/div>\n<div>\n<p>\u00a0 \u00a0Here, we define the empty element \u2018counter\u2019 with the schema element &lt;complexContent&gt;.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Mixed elements<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Mixed elements may contain both text and elements. To define a mixed element, we add the attribute mixed=&#8221;true&#8221; to the &lt;xs:complexType&gt; element. The text itself is not mentioned in the element, and may go anywhere and it is basically ignored.<\/p>\n<p>&nbsp;<\/p>\n<p>&lt;xs:com plexType name=&#8221;paragraph&#8221; mixed=&#8221;true&#8221;&gt; &lt;xs:sequence&gt;<\/p>\n<p>&lt;xs:element\u00a0 name=&#8221;someName\u201d type=&#8221;xs:anyType&#8221;\/&gt;<\/p>\n<p>&lt;\/xs:sequence&gt;<\/p>\n<p>&lt;\/xs:com plexType&gt;<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Here, the element \u2018paragraph\u2019 has been defined as a complex type that is composed of another element.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Extensions<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">We can base a complex type on another complex type. The complex type is an extension of another complex type with the use of the attribute base = \u201cotherType\u201d.<\/p>\n<p>&nbsp;<\/p>\n<p>&lt;xs:com plexType\u00a0 name=&#8221;newType&#8221;&gt;<\/p>\n<p>&lt;xs:com plexContent&gt;<\/p>\n<p>&lt;xs:extension\u00a0 base=&#8221;otherType&#8221;&gt;<\/p>\n<p>&#8230;new stuff&#8230;<\/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><strong>Type Extensions<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">A third way of creating a complex type is to extend another complex type like inheritance in Object Oriented concepts.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\"><span style=\"font-size: 1em;text-align: initial\">In this example, we define the element \u2018Employee\u2019 as of type \u2018PersonInfoType\u2019. The name of the employee is defined as a complexType which extends from \u2018PersonNameType\u2019.<\/span><\/p>\n<\/div>\n<div>\n<p>&nbsp;<\/p>\n<p>&lt;xs:element name=&#8221;Em ployee&#8221; type=&#8221;PersonInfoType&#8221;\/&gt; &lt;xs:com plexType name=&#8221;PersonNameType&#8221;&gt;<\/p>\n<p>&lt;xs:sequence&gt;<\/p>\n<p>&lt;xs:element name=&#8221;FirstName&#8221; type=&#8221;xs:string&#8221;\/&gt; &lt;xs:element name=&#8221;LastName&#8221; type=&#8221;xs:string&#8221;\/&gt;<\/p>\n<p>&lt;\/xs:sequence&gt;<\/p>\n<p>&lt;\/xs:com plexType&gt;<\/p>\n<p>&lt;xs:com plexType name=&#8221;PersonInfoType&#8221;&gt;<\/p>\n<p>&lt;xs:com plexContent&gt;<\/p>\n<p>&lt;xs:extension base=&#8221;PersonNameType&#8221;&gt;<\/p>\n<p>&lt;xs:sequence&gt;<\/p>\n<p>&lt;xs:element name=&#8221;Address&#8221; type=&#8221;xs:string&#8221;\/&gt;<\/p>\n<p>&lt;xs:element name=&#8221;City&#8221; type=&#8221;xs:string&#8221;\/&gt;<\/p>\n<p>&lt;xs:element name=&#8221;Country&#8221; type=&#8221;xs:string&#8221;\/&gt;<\/p>\n<p>&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><strong>Type Extensions (use)<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">The below syntax demonstrates the use of a type that is an extension of another. It is used as though it were all defined in a single type.<\/p>\n<p>&nbsp;<\/p>\n<p>&lt;Employee xmlns:xsi=&#8221;http:\/\/www.w3.org\/2001\/XMLSchema -instance&#8221;<\/p>\n<p>xsi:noNamespaceSchemaLocation=&#8221;TypeExtension.xsd&#8221;&gt;<\/p>\n<p>&lt;FirstName&gt;King&lt;\/FirstName&gt;<\/p>\n<p>&lt;LastName&gt;Arthur&lt;\/LastName&gt;<\/p>\n<p>&lt;Address&gt;Round Table&lt;\/Address&gt;<\/p>\n<p>&lt;City&gt;Camelot&lt;\/City&gt;<\/p>\n<p>&lt;Country&gt;England&lt;\/Country&gt;<\/p>\n<p>&lt;\/Employee&gt;<\/p>\n<\/div>\n<p><strong style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0 Simple Content in Complex Type<\/strong><\/p>\n<div>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">If a type contains only simple content (text and attributes), a &lt;simpleContent&gt; element can be put inside<\/p>\n<p>the &lt;complexType&gt;.<\/p>\n<p>&nbsp;<\/p>\n<p>A &lt;simpleContent&gt; must have either a &lt;extension&gt; or a &lt;restriction&gt;.<\/p>\n<p>&nbsp;<\/p>\n<p>&lt;xs:element name=&#8221;dialog&#8221;&gt;<\/p>\n<p>&lt;xs:com plexType&gt;<\/p>\n<p>&lt;xs:simpleContent&gt;<\/p>\n<p>&lt;xs:extension base=&#8221;xs:string&#8221;&gt;<\/p>\n<p>&lt;xs:attribute name=&#8221;speaker&#8221; type=&#8221;xs:string&#8221; use=&#8221;required&#8221;\/&gt; &lt;\/xs:extension&gt;<\/p>\n<p>&lt;\/xs:simpleContent&gt;<\/p>\n<p>&lt;\/xs:com plexType&gt;<\/p>\n<p>&lt;\/xs:element&gt;<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Predefined string types:<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>Recall that a simple element is defined as:<\/p>\n<p>&nbsp;<\/p>\n<p>&lt;xs:element\u00a0 name=&#8221;name&#8221;\u00a0 type=&#8221;type&#8221; \/&gt;<\/p>\n<p>Here are a few of the possible string types that are given below.<\/p>\n<ul>\n<li style=\"text-align: justify\">\u00a0 xs:string &#8212; a string<\/li>\n<li style=\"text-align: justify\">\u00a0xs:normalizedString &#8212; a string that doesn\u2019t contain tabs, newlines, or carriage returns<\/li>\n<li style=\"text-align: justify\">\u00a0xs:token &#8212; a string that doesn\u2019t contain any whitespace other than single spaces<\/li>\n<\/ul>\n<p style=\"text-align: justify\">\u00a0 \u00a0Allowable restrictions on strings are, enumeration, length, maxLength, minLength, pattern and whiteSpace.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Predefined date and time types:<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>\u2022\u00a0 xs:date &#8212; A date in the format <strong><em>CCYY-MM-DD<\/em><\/strong>, for example, 2002-11-05<\/p>\n<p>\u2022\u00a0 xs:time \u2013 A time in the format <strong><em>hh:mm:ss<\/em><\/strong> (hours, minutes, seconds)<\/p>\n<p>\u2022\u00a0 xs:dateTime &#8212; Format is <strong><em>CCYY-MM-DD<\/em>T<em>hh:mm:ss<\/em><\/strong><\/p>\n<p>\u2013\u00a0\u00a0 The T is part of the syntax.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Allowable restrictions on dates and times are, enumeration, minInclusive, minExclusive, maxInclusive, maxExclusive, pattern and whiteSpace.<\/p>\n<\/div>\n<p><strong style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0Predefined numeric types:<\/strong><\/p>\n<div>\n<p>\u00a0 \u00a0Some of the predefined numeric types are given below,<\/p>\n<table style=\"border-collapse: collapse;width: 99.9394%;height: 126px\">\n<tbody>\n<tr style=\"height: 28px\">\n<td style=\"width: 49.9394%;height: 28px\">xs:decimal<\/td>\n<td style=\"width: 50%;height: 28px\">xs:positiveInteger<\/td>\n<\/tr>\n<tr style=\"height: 28px\">\n<td style=\"width: 49.9394%;height: 28px\">xs:byte<\/td>\n<td style=\"width: 50%;height: 28px\">xs:negativeInteger<\/td>\n<\/tr>\n<tr style=\"height: 14px\">\n<td style=\"width: 49.9394%;height: 14px\">xs:short<\/td>\n<td style=\"width: 50%\">xs:nonPositiveInteger<\/td>\n<\/tr>\n<tr style=\"height: 14px\">\n<td style=\"width: 49.9394%;height: 14px\">xs:int<\/td>\n<td style=\"width: 50%;height: 14px\">xs:nonNegativeInteger<\/td>\n<\/tr>\n<tr style=\"height: 28px\">\n<td style=\"width: 49.9394%;height: 28px\">xs:long<\/td>\n<td style=\"width: 50%;height: 28px\"><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Allowable restrictions on numeric types are enumeration, minInclusive, minExclusive, maxInclusive, maxExclusive, fractionDigits, totalDigits, pattern and whiteSpace.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Types<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Both elements and attributes have types, which are defined in the Schema. We can reuse types by giving them names.<\/p>\n<p>&nbsp;<\/p>\n<p>For example, we define a schema Addr.xsd<\/p>\n<p>&nbsp;<\/p>\n<p>Addr.xsd:<\/p>\n<p>&lt;xsd:element name=&#8221;Address&#8221;&gt;<\/p>\n<p>&lt;xsd:com plexType&gt;<\/p>\n<p>&lt;xsd:sequence&gt;<\/p>\n<p>&lt;xsd:element name=&#8221;Street&#8221; type=&#8221;xsd:string&#8221;\/&gt; &lt;xsd:element name=&#8221;Apartment&#8221; type=&#8221;xsd:string&#8221;\/&gt; &lt;xsd:element name=&#8221;Zip&#8221; type=&#8221;xsd:string&#8221;\/&gt;<\/p>\n<p>&lt;\/xsd:sequence&gt;<\/p>\n<p>&lt;\/xsd:com plexType&gt;<\/p>\n<p>&lt;\/xsd:element&gt;<\/p>\n<p>&nbsp;<\/p>\n<p><strong>(or)<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>&lt;xsd:com plexType name=&#8221;AddrType&#8221;&gt;<\/p>\n<p>&lt;xsd:sequence&gt;<\/p>\n<p>&lt;xsd:element name=&#8221;Street&#8221; type=&#8221;xsd:string&#8221;\/&gt; &lt;xsd:element name=&#8221;Apartment&#8221; type=&#8221;xsd:string&#8221;\/&gt; &lt;xsd:element name=&#8221;Zip&#8221; type=&#8221;xsd:string&#8221;\/&gt;<\/p>\n<p>&lt;\/xsd:sequence&gt;<\/p>\n<p>&lt;\/xsd:com plexType&gt;<\/p>\n<p>&lt;xsd:element name=\u201cShipAddress&#8221; type=&#8221;AddrType &#8220;\/&gt; &lt;xsd:element name=\u201cBillAddress&#8221; type=&#8221;AddrType&#8221;\/&gt;<\/p>\n<\/div>\n<p><strong style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0Complex Type Definition<\/strong><\/p>\n<div>\n<p><strong>\u00a0 \u00a0 Composition<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Model Group is composed of Compositor such as <em>sequence<\/em> or <em>choice<\/em> or <em>all<\/em> and Particles, which can be Element Declaration or a Wildcard or a Model Group.<\/p>\n<p style=\"text-align: justify\">The model group schema component has the following properties:<\/p>\n<p><em>{compositor}<\/em><\/p>\n<p>One of all, choice or sequence.<\/p>\n<p><em>{particles}<\/em><\/p>\n<p>A list of particles<\/p>\n<p><em>{annotation}<\/em><\/p>\n<p>Optional. An annotation.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Annotations<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Annotations are provided for human-targeted documentations and machine-targeted documentations of schema components. They are actually meta-data.<\/p>\n<p>&nbsp;<\/p>\n<p><em>The annotation schema component has the following properties:<\/em><\/p>\n<p><em>{application information}<\/em><\/p>\n<p><em>A sequence of element information items.<\/em><\/p>\n<p><em>{user information}<\/em><\/p>\n<p><em>A sequence of element information items.<\/em><\/p>\n<p><em>{attributes}<\/em><\/p>\n<p><em>A sequence of attribute information items.<\/em><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">The XML representation for an annotation schema component is an &lt;annotation&gt; element information item.<\/p>\n<p>&nbsp;<\/p>\n<p>&lt;xs:simpleType fn:note=&#8221;special&#8221;&gt;<\/p>\n<p>&lt;xs:annotation&gt;<\/p>\n<p>&lt;xs:documentation&gt;A type for experts only&lt;\/xs:documentation&gt; &lt;xs:appinfo&gt;<\/p>\n<p>&lt;fn:specialHandling&gt;checkForPrimes&lt;\/fn:specialHandling&gt;<\/p>\n<p>&lt;\/xs:appinfo&gt;<\/p>\n<p>&lt;\/xs:annotation&gt;<\/p>\n<\/div>\n<p><strong style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0 Declarations<\/strong><\/p>\n<div>\n<p>&nbsp;<\/p>\n<p>Example<\/p>\n<p>&nbsp;<\/p>\n<p>&lt;xs:element name=&#8221;PurchaseOrder&#8221; type=&#8221;PurchaseOrderType&#8221;\/&gt; &lt;xs:element name=&#8221;gift&#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;birthday&#8221; type=&#8221;xs:date&#8221;\/&gt;<\/p>\n<p>&lt;xs:element ref=&#8221;PurchaseOrder&#8221;\/&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:attribute name=&#8221;age&#8221; type=&#8221;xs:positiveInteger&#8221; use=&#8221;required&#8221;\/&gt; &lt;xs:notation name=&#8221;jpeg&#8221; public=&#8221;image\/jpeg&#8221; system=&#8221;viewer.exe&#8221;&gt;<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">The example shows the declaration of the element &#8216;PurchaseOrder&#8217; which is defined as &#8216;PurchaseOrderType&#8217; and is composed of complex element &#8216;gift&#8217;, attribute &#8216;age&#8217; and notation &#8216;jpeg&#8217;.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Example Schema<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>An example to illustrate the concepts we have seen so far is given below.<\/p>\n<p>&nbsp;<\/p>\n<p>&lt;?xml version=\u201e1.0\u201c ?&gt;<\/p>\n<p>&lt;xsd:schema xmlns:xsd= http:\/\/w3.org\/2001\/XMLSchema\u201c&gt; &lt;xsd:element name=book\u201c type=BookType\u201c\/&gt;<\/p>\n<p>&lt;xsd:com plexType name= BookT ype\u201c&gt;<\/p>\n<p>&lt;xsd:sequence&gt;<\/p>\n<p>&lt;xsd:element name= title\u201c type= xsd:string\u201c\/&gt; &lt;xsd:element name= author\u201c type= PersonType\u201c<\/p>\n<p>minOccurs=1\u201c maxOccurs= unbounded\u201c\/&gt;<\/p>\n<p>&lt;xsd:com plexType name= PersonType\u201c&gt;<\/p>\n<p>&lt;xsd:sequence&gt; &#8230; &lt;xsd:sequence&gt;<\/p>\n<p>&lt;\/xsd:com plexType&gt;<\/p>\n<p>&lt;xsd:element name= publisher\u201c type= xsd:anyType\u201c\/&gt; &lt;\/xsd:sequence&gt;<\/p>\n<p>&lt;\/xsd:com plexType&gt;<\/p>\n<p>&lt;\/xsd:schema&gt;<\/p>\n<\/div>\n<p><strong>\u00a0 \u00a0Summary<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">This module has explained about defining simple elements and complex elements. The module also explains that there exists variety of data \u201cfacets\u201d and \u201cpatterns\u201d to impose domain constraints. The elements can be type defined by applying inheritance. Moreover, the module explains about defining advanced constraints such as \u201cprimary key\u201d and \u201creferential integrity\u201d.<\/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>https:\/\/www.w3.org\/TR\/xmlschema-1\/#components<\/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>people.cs.uchicago.edu\/~asiegel\/courses\/cspp51038&#8230;\/<strong>XMLSchema<\/strong>.ppt<\/em><\/li>\n<\/ul>\n","protected":false},"author":4,"menu_order":10,"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-75","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\/75","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":11,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-json\/pressbooks\/v2\/chapters\/75\/revisions"}],"predecessor-version":[{"id":507,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-json\/pressbooks\/v2\/chapters\/75\/revisions\/507"}],"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\/75\/metadata\/"}],"wp:attachment":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-json\/wp\/v2\/media?parent=75"}],"wp:term":[{"taxonomy":"chapter-type","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-json\/pressbooks\/v2\/chapter-type?post=75"},{"taxonomy":"contributor","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-json\/wp\/v2\/contributor?post=75"},{"taxonomy":"license","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-json\/wp\/v2\/license?post=75"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}