 I will walk through some of the elements of XML schema because we are now transitioning away from DTDs. DTDs were very inflexible they did not give us some of the flexibility that was required that is being provided by schema descriptions right. So that is the first bullet so the flexibility provided is better than DTDs right. The XML document syntax right how I describe what the XML document is going to look like is also in XML in this particular case right. So all your XML authoring tools that you have XML spy this and that can be used easily to author schema descriptions right. Non-textual data types which are very important to B2B and e-commerce so for example numbers in XML you could only describe strings of characters right eventually that has to be translated by a parser from a string to an integer done something here there is a type system that is actually embedded there is a data model that is provided for the XML scheme right and much more complex syntax. So XML schema is not part of 1.0 it is come after that so just valid does not valid only means that it is validated with respect to a DTD so schema valid means that it is validated with respect to a schema description because the rest of it is similar so it is very similar to classes and objects in OOD right. So class is a template in object oriented design schema is a template and then every XML document is a schema instance of similar to an object definition so there are two things that we end up doing within XML scheme we create new types right and we use these types in declarations so creating new types of the definition and we use these types and that forms a declaration here is a very quick example of this creation of a type called zip union and the zip union is actually a union type we will see what a union type is is just a simple example right so that has a either a bunch of state zip codes or it has a bunch of integers some random integers right so it is a union so one of the two will be picked so here the declaration is shown down here right so which actually uses the zip union and I will declare an element of type zips this is also part of the schema definition. Now you have a notion of simple data types as well as the more complex data type which are formed out of aggregating multiple simple data types as the name suggests right a simple type does not have any sub elements associated with it they are more fundamental in nature right either attributes or element no sub elements at all right either so they come where do they come from why do we want simple types it is like a type def in a programming language right so a predefined type would derive from this and you can put certain restrictions on a type def also it is that notion and complex types are basically aggregating these simple types or different elements under you have the basic simple types that exist you do not have to go through this list so predefined simple types is I want to call something a title for a book let us say it is a string the title is nothing but a string a string is already a built-in type for me what I will type this to type def this to be a title say a similar heading topic price whatever right so there are multiple examples that I have here so one is an attribute the rest of them are elements you all played with XML before right I hope you have because this is a precursor to this otherwise it is going to be a problem I am assuming that you are familiar with XML and you have used DTDs before this is where we are discussing schemas only right so you restrict simple types to get derived simple types right one was a type def that we did but now we can do restrictions based on some base type that we have that already exists and the restrictions come in the form of facets right so these are certain rules of restriction let's take a look at example I think examples of the best way to understand this I am going to call something my integer the base type is an integer right for my integer is restricted to be within 10,000 and 99,999 so value between these two numbers let I restrict so I call that my integer so this is actually a simple type but say derived simple type where I have put certain facets or restrictions there are two facets here mean inclusive max inclusive mean inclusive is 10,000 included is a minimum and 99,000 include is max inclusive you know many different types of restrictions here is another restriction I say SKU basically a sales code for some product that I am selling it says string but it has some pattern the string has to have this kind of a pattern so it is three digits followed by hyphen right followed by two uppercase letters aske letters right so any SKU is any string that is conforming to this part right so this is an enumeration so it is called a 2D shape the 2D shape is also a string but it has to be one of these set of strings that I am give specifically a list of things that I am going to put down here right square circle triangle whatever you can have any number of these okay complex types contain different element declaration references attributes etc it is a contained right so here is a complex type we call it an Indian address although we can never capture an Indian address in XML that is my typical Indian address would be in front of the tree next to two buffalos which are normally standing there which is so anyway so this is our address that only the Indian postal system can deliver to nobody else can find that address right so we have to catch all of the postman so this has a name street city state zip it will be a nice way of being able to define addresses now here I have given I also as an attribute which is country because an Indian address I am going to fix it to a particular token which is IN which is standing for Indian right so I do not have to explicitly specify this attribute every time I use address already seen this so this contains only declarations involving other simple types right we saw that these are all strings and decimals then what else so this is a purchase order now this contains other complex types because it contains Indian address within it is a ship to address and as a bill address bill to address both are Indian addresses right so and it can also contain comments right it doesn't have to contain comments so minimum occurrences of a comment or zero doesn't have to contain a comment is what it means right then it has an attribute which is the order date which is of type date there is no default value for that same thing so elements such as attributes you have already seen right there is no need for me to go through this this is part of the standard XML so references also you have heard of reference notion in XML you are familiar with I am presuming right so okay so occurrences these are different facets basically right so I have min occurs max occurs that you already know what it means we use minimum number of occurrences maximum number of occurrences of certain elements then it is fixed that means that it is fixed to a particular value right so it cannot change if the element appears it doesn't have to appear but if it appears the value must be something so if it is a string in this case it has to be Anna whatever right otherwise the value is set to this by the parser right the notion of the difference between default and fixed is that in the case of fixed the value must be this in the case of default if it appears right then the value is set to whatever is specified as the default point right so it doesn't have to be fixed so this is in this case it doesn't have to be fixed it can be anything but if it is there and it doesn't have value it is assigned to default right so filler so these are examples of these types so is so min occurs one max occurs one that means it has to occur one time this test is a string it has to occur one time right how so there is also the specific value got unbounded which can be any number of so there is a notion of use aspect and value aspect for occurrences of attributes right so I think the example is better the use is required so attribute name is test type is string the value the use is required and the value has to be 37 right or it can be optional and fixed so there are different combinations that can be created out of this right the use is required optional fixed or default right so one of the four things this is just an example that is dumping everything into the same it shouldn't be like this because there are some contradictions here it is just illustrating the fact that you can use this different values of the facet of use that's all so here's a good example of a fixed value which is India for the name country which is an attribute of the address you don't have to specify address yeah I mean you don't have to specify country it will take India to be the value which is fixed for anyway for these addresses right so you can have enumerations or unions those are the other two types that can be assigned to different attributes and what the name implies enumeration is one of these different types of values that I'm going to give you a union is with respect to the base type itself right here's a complete example of book contents it has a complex type of I'm calling contents type and since it's a complex type it involves other types within it other complex types as well within it has a heading it has a topic all the restrictions specified you can go through this this is all part of your handout and we can also have lists basically sequences of the simple types that you can build up similar the notion of a programming language built-in type of list you can have three types of lists ID refs you know what ID refs are right they were appearing in GGDs as well right and different entities that can exist and different facets list or what is the length of the list min length max length enumeration with so again here's an example I'm going to create a list of my int type remember my int type was the my integer right my integer was a type that I had created earlier in one of the examples and I'm going to use that to create a list of that type so if I in the instance so this is actually the schema in the instance it will be list of my int right which is a type that I've created and some set of examples with each one of these numbers is between 10,000 and 99,999 right here's a list type with a facet the facet is the number of items that can appear in the list is six colors is the name of the type that I'm creating right it has a length of six is what we're saying right and it's a color list so base type is colorless I'm understanding it's assuming that there is some base type called color list and that base type has been defined here is a list of colors right so a list of colors is also a list type now I'm restricting that further to say that it can only have six colors right in this particular type define a list of exactly six words so six colors would be the tag that I'll use here because that is what I'm going to use as a restricted time okay so you can already see that there is a lot more flexibility with respect to DTD so schema gives you a much more full type system that you can play with right so unions are again it takes either this type of value or that type of value but not both at the same time right at a given time we can only take on one type of value that's a union right facets are what is the pattern and what is the enumeration so here is an example of a color union but the color union actually either has color or it has something random list of my intake right in this case it is random so it can either be color or it can be list of my intake it can't be both so you can't have an XML tag which which contains both list of my integers as well as color it turns out that this example is not fully right because list of my in type should have numbers between 10,999 99,999 anyway so explicit typing is very actually described the type right and then included somewhere else or you reference it somewhere in an attribute implicit type is as you're doing a definition you will not be creating a separate type you will just create do a type specification okay a name is given to a type is explicit type right list of my integer types a color union these are all explicit types that I had created right implicit type is it is kind of inlining the notion of an inlining right I haven't created a separate function for it but I am using it separately it's nameless right so here the explicit is pretty easy we understand this the implicit is here right so this book example is this a book example is not the book example but anyway so this is an implicit type that I have created right but I have not named this to be of some type that's the notion right in other words I haven't created this outside and then used it in this particular items complex type that I am creating now in this items complex type there is some other complex type that I have created in here right it's a well this is actually a direct simple type it's not a complex right so direct simple type in which I have taken a positive integer is based the restriction is a positive integer right on this and the max exclusive value is 100 right that means it can only be between 0 and 99 that's what it means but I have not named this to be of anything that I can reuse somewhere else right that is part of this schema itself and it's only appearing once but I can't reuse this that's the problem if I do it implicitly I cannot reuse it I want to reuse it I have to create is it an explicitly named type and then reuse it also so complex types from simple types can be created in this way so I have a price right usage in some document instances price and then the type is this much of the XML schema I gave this and this is the actual instance right now I want to create something called international price where currency is in euro this is an attribute currency is in euro right how do you do this describe this in the XML schema right this isn't come to confirm to this remember right I have described this is an instance this specific instance appearing in an XML document what would be the corresponding definition and XML schema a simple type can't have attributes so we can't do this so we have to create a complex type here it was just a simple type prices decimal that's it but here because the currency is euro I have an attribute and simple type can't have attributes I need to define a complex type called international price in this particular case right so it has some simple content and it has an attribute associated with it and the attribute is a string will describe the currency in which this decimal is to be interpreted right you can also mix things here the letter body which mixes sub elements and just plain old character data right so dear mister and then there is some sub element associated with it which is name happens to be a Mardu Bay whatever again this is an example of mixed content in which the two previous types that we went through where mixed with each other there is no content that is actually associated with it the content model of the complex type is actually being extended in here so I create default restrictions of the any type is a base type within XML schemas which can stand for anything it's what is the equivalent it's like object in Java right so object can be specialized to anything everything will eventually be routed as that object everything is XML would be routed at any time right everything would be eventually derived from this it's actually a dangerous thing to use this any type because you won't be able to type it to a specific kind of entity very easily so you normally not want to use this so the advice is to use more constraint types this can stand for anything basically it can be a string it can be an integer value it can be a date it doesn't matter but you're not getting specific enough information from this as to what it is so in general you don't want to use this but if you don't have a good idea of what the value is expected to be then you will stick an any type in there annotation is so there can be documentation annotation right so you can say that this document consists of stuff relating to whatever right and then there can be application so for example XSLT I want to do transformations with this CSS kind of annotations and so on for style sheets so here is an example of an documentation annotation it is this is an element that is declared with an anonymous type is what I'm saying this is to be interpreted by human the parser will just give this back as documentation and you do whatever you want with that it is mainly meant for humans to read eventually and do something another documentation annotation also so grouping I don't think we want to go through this given the time restrictions but it's unlikely that you will use grouping but here is an example that I can group two different addresses it's called a ship and bill address I create a sequence group both of them are of type address and then now you are given the choice between either a ship and bill address which is a group or a single address which is of type address so you can pass any one of these at this point time so it's an either or in here it's a choice between one of these two right so in other words if the actual XML document contained a group of such addresses I'll take it if it just contained a single address I'll probably use it as both a shipping address and a billing address that's my interpretation of this right I'll still consider it to be a valid XML document with respect to this scheme that's the notion of a choice so I can also do collective restrictions collective restrictions instead of specifying restrictions for each item separately I will say that I'm going to group all of this into one entities so this is an XSD colon all right and whatever restrictions I put out here will apply to all of them right with their own apply to comment bill to address ship to address items that are in there etc right so this is also a notion of a grouping and so the attribute for example refers to this whole thing the order date attribute groups probably a little more detailed than what we want to get to but this attribute groups can be used to replace individual attribute declarations this is one thing that is a little important because you will see this notion of a namespace in almost every document in visual documents that you you write you see you have to describe the namespace because there is a different every document XML document that you write would will have a target namespace that it is part of right and it might also refer to things in other namespaces that are source namespaces from which you import definitions right so target namespace is going to be assigned to the schema that you are actually creating at that point so you have to say that this belongs to this target namespace it may be a company name for example right so I describe a PO this company my company is some XYZ business and purchase order definition is specific to this business right that's the notion so one target namespace has to exist and many source namespaces is coming from different places right so in this example the target namespace is www.samplestore.com slash account and I am going to use an account namespace that I am getting from somewhere else right in here that I am going to call ACC this is a name that I am giving that namespace and the account namespace is actually going to be used in here so I am going to declare an element of the product ID that is actually a product code coming defined in this particular namespace account right it turns out that even this definition that I am doing is going to go into the account namespace right so I have to import whatever definitions are there in this account namespace I for the purposes of this definition I call it ACC and I can use whatever is defined within the account namespace in here by referring to it as ACC colon something else okay the same thing is explained so there are obviously the XML elements themselves have to be defined somewhere so there is a namespace that is defined as W3C.org which is the XML schema namespace so importing schema from some schema location this is what I have done well this is the older example does not specify the location of the source schema files here is the example I am going to import a particular namespace which location is specified in this way so this was I guess part of your question is what if I give a local location on disk there would be a problem if it was sent to a place where C colon would not mean the same thing if it was sent to another machine in other words so I am going to call this part right and the parts catalog is being imported from this particular thing so this is being for the purpose of this definition I am going to call it part and then I refer to part something part colon super glue type whatever that happens right so it's basically a namespace delineator to say because there could be other super glue types defined somewhere and if I am inheriting a namespace I have to be explicit as to which super glue type I am referring to it otherwise there would be a clash this we are saying this is the declaration of I am going to use the namespace that I am going to call part right and that namespace is being imported from this location right so this is the part is this it refers to this this is being imported from this location and wherever else in the document I refer to some definition from within this I will say part colon that is all I am saying right see in this case is both the target and the source ACC is both the target and the source right because I am going to go into target which is a sample store.com slash account but that also happens to be a source because I may refer to other definitions that have been made in this before okay so this is we kind of quickly skip through some of this which is okay but attachment actually has all these slides so you will be able to go through this at your leisure the status of this W3C recommendation has been obviously this is a adopted and a lot of tools that will deal with schemas exist for you so the best thing to get a schema primer a lot more details on this is to go to the W3C site which is the standardization organization anyway so you there are a lot of resources that are available at that site including example schemas and stuff that you can look at right so that is W3C.org is your starting point and then you can search for things from within there okay you can create more complicated data out of this alpha numeric and character yeah correct that we use mime types as soap attachments so when we actually send soap messages the soap message is in XML but you can have soap attachments that can be other kinds right so we'll take a look at that when we describe soap okay but it can be done because the common thing that you might have to do is to send a picture a jiff for a jpeg or something like that I as part of the web service so you can do that using soap attachments yeah so that are nothing to do with XML per se that just says that I'm going to ship something else here even a jiff if you want to send this XML can be serialized out into XML format and send which is possible to do that eventually there has to be an on-the-wire representation of that either it can be binary or it can be textual XML is a textual representation of something that's on the wire right so both the choices exist but we'll use soap attachments for that purpose we have to specify by default it is it depends on the binding that is specified right you can actually say what the binding is you can say that this is going to be an RPC type call done using HTTP or whatever for the HTTP it is easy for it is easy to do RPC type calls because the correlation of the request and reply is automatically done for you if it is two one-way messages and you want to RPC then you have to correlate which request is correspond which reply corresponds to it request because if I fire 10 requests and 10 replies come back I have to correlate those messages somehow that means I have to explicitly encode a message ID or request ID or something and I have to say okay this reply will repeat the request ID that I had sent and therefore this is meant for this particular request but with HTTP that correlation comes for free for unique code you will actually specify the encoding also as part of the binding right UTF-8 whatever it is that the encoding is as to be specified UTF-8 is an example of an encoding that is to be done right so it doesn't have to be UTF-8 it could be unique code also