1 00:00:00,550 --> 00:00:02,470 In this video we'll be learning about XML schema. 2 00:00:03,500 --> 00:00:05,370 Like document type descriptors, XML 3 00:00:05,750 --> 00:00:06,730 schema allows us a way 4 00:00:07,040 --> 00:00:10,200 to give content specific specifications for our XML data. 5 00:00:11,290 --> 00:00:12,540 As you may remember, we send 6 00:00:12,840 --> 00:00:14,900 to a validating XML parser or 7 00:00:15,020 --> 00:00:16,570 XML document as well as a description. 8 00:00:17,240 --> 00:00:19,030 We talked about DTDs in the last video. 9 00:00:19,360 --> 00:00:21,120 We'll talk about XSDs in this one. 10 00:00:21,810 --> 00:00:23,200 The validating XML parser will 11 00:00:23,400 --> 00:00:24,480 check that the document is well 12 00:00:24,600 --> 00:00:26,980 formed, and it will also check that it matches it's specification. 13 00:00:27,970 --> 00:00:29,820 If it does, XML comes out. 14 00:00:30,090 --> 00:00:31,120 If it doesn't we get 15 00:00:31,280 --> 00:00:33,100 an error that the document is not valid. 16 00:00:34,930 --> 00:00:37,160 XML schema is an extensive language, very powerful. 17 00:00:38,180 --> 00:00:39,530 Like document type descriptors we 18 00:00:39,610 --> 00:00:40,800 can specify the elements we 19 00:00:40,880 --> 00:00:41,900 want in our XML data, 20 00:00:42,240 --> 00:00:43,620 the attributes, the nesting of 21 00:00:43,710 --> 00:00:45,230 the elements, how elements need 22 00:00:45,450 --> 00:00:47,170 to be ordered, and and number of occurrences of elements. 23 00:00:47,600 --> 00:00:49,100 In addition we can 24 00:00:49,260 --> 00:00:50,590 specify data types we can 25 00:00:50,740 --> 00:00:52,310 specify keys, the pointers 26 00:00:52,810 --> 00:00:53,910 that we can specify are now 27 00:00:54,260 --> 00:00:56,860 typed like in DTDs and much, much more. 28 00:00:57,970 --> 00:00:59,720 Now, one difference between XML 29 00:01:00,020 --> 00:01:01,660 schema and DTDs is that 30 00:01:01,880 --> 00:01:03,270 the specification locations in XML schemas 31 00:01:03,650 --> 00:01:06,560 called XSD's are actually written in the xml language itself. 32 00:01:06,980 --> 00:01:08,160 That can be useful for example 33 00:01:08,660 --> 00:01:11,070 if we have a browser that nicely renders the XML. 34 00:01:12,140 --> 00:01:13,230 The languages I said is vast. 35 00:01:14,000 --> 00:01:15,300 In this video, we're going 36 00:01:15,490 --> 00:01:17,350 to show one sort of quote easy example. 37 00:01:18,010 --> 00:01:19,310 But that example will give 38 00:01:19,510 --> 00:01:21,290 very much the flavor of XML schema. 39 00:01:21,640 --> 00:01:22,920 And we'll try to highlight the 40 00:01:23,000 --> 00:01:25,860 differences between XML schema and using document type descriptors. 41 00:01:27,470 --> 00:01:30,200 Ok, here were are with our XML document on the left. 42 00:01:31,020 --> 00:01:32,190 On the right we have our 43 00:01:32,560 --> 00:01:34,340 XML schema descriptor or XSD 44 00:01:34,650 --> 00:01:35,960 and we have a 45 00:01:36,070 --> 00:01:38,210 little command line that we're gonna use for our validation command. 46 00:01:39,380 --> 00:01:40,350 Now let me just say up front 47 00:01:40,700 --> 00:01:41,580 that we're not going to be 48 00:01:41,670 --> 00:01:43,080 going through the XSD line 49 00:01:43,390 --> 00:01:45,130 by line in detail the way we did with DTDs. 50 00:01:45,400 --> 00:01:46,630 As you can see it's 51 00:01:46,850 --> 00:01:48,550 rather long and that 52 00:01:48,690 --> 00:01:51,090 would take us far too long and be rather boring. 53 00:01:52,010 --> 00:01:53,640 So what I highly suggest is 54 00:01:53,730 --> 00:01:55,100 that you download the file for 55 00:01:55,170 --> 00:01:56,240 the XSD so you can 56 00:01:56,420 --> 00:01:57,890 look at it yourself and look 57 00:01:57,960 --> 00:01:59,420 at the entire file as well 58 00:01:59,720 --> 00:02:01,350 as the XML and give it a try with validating. 59 00:02:02,430 --> 00:02:03,190 What I'm gonna do in this 60 00:02:03,380 --> 00:02:05,050 demo primarily is focus 61 00:02:05,400 --> 00:02:07,040 on those aspects of 62 00:02:07,270 --> 00:02:09,120 the XSD that are different, 63 00:02:09,450 --> 00:02:11,680 are more powerful than we had in document type descriptors. 64 00:02:12,710 --> 00:02:13,940 First, let's take a look at the data itself. 65 00:02:15,070 --> 00:02:17,880 So we have our bookstore data as usual with two books and three authors. 66 00:02:18,470 --> 00:02:21,440 Its slightly restructured from any of the versions we've used before. 67 00:02:22,030 --> 00:02:23,160 It looks closest to the 68 00:02:23,320 --> 00:02:24,340 last one we used because the 69 00:02:24,420 --> 00:02:25,700 books and authors are separate 70 00:02:26,580 --> 00:02:27,970 and the authors are actually exactly the same. 71 00:02:28,190 --> 00:02:29,150 The have an identifier and a 72 00:02:30,190 --> 00:02:31,340 first name - last name sub element. 73 00:02:31,810 --> 00:02:33,220 But the primary difference is in 74 00:02:33,370 --> 00:02:34,920 the books, instead of using 75 00:02:35,160 --> 00:02:36,940 ID refs attributes to refer 76 00:02:37,270 --> 00:02:38,670 from books to authors, we still, 77 00:02:38,960 --> 00:02:40,170 we now back our back having 78 00:02:40,450 --> 00:02:42,570 an author's sub-element with the 79 00:02:42,930 --> 00:02:44,430 two authors underneath and then 80 00:02:44,600 --> 00:02:46,140 those authors themselves have what 81 00:02:46,260 --> 00:02:49,100 are effectively the pointers to the identifiers for the authors. 82 00:02:49,510 --> 00:02:50,530 And we'll see how that's 83 00:02:50,790 --> 00:02:51,860 going to mesh with the XML 84 00:02:52,070 --> 00:02:54,020 schema descriptor that we're using for this file. 85 00:02:55,100 --> 00:02:56,210 So, the other thing I want 86 00:02:56,420 --> 00:02:57,540 to mention is that right now 87 00:02:57,880 --> 00:02:59,070 we have the XML schema 88 00:02:59,380 --> 00:03:01,750 descriptor in one file and the XML in another. 89 00:03:02,570 --> 00:03:03,550 You might remember for the DTD, 90 00:03:04,050 --> 00:03:05,150 we simply placed the DTDs 91 00:03:05,530 --> 00:03:06,630 specification at the top 92 00:03:07,140 --> 00:03:08,280 of the file with the XML. 93 00:03:08,890 --> 00:03:11,800 For DTDs you can do it either way in the same file or in a separate file. 94 00:03:12,500 --> 00:03:15,290 For XSDs, we always put those in a separate file. 95 00:03:15,980 --> 00:03:17,200 Also notice that the XSD 96 00:03:17,990 --> 00:03:19,250 itself is in XML. 97 00:03:20,300 --> 00:03:21,390 It is using special tags. 98 00:03:21,880 --> 00:03:22,870 These are tags that are part 99 00:03:23,400 --> 00:03:25,660 of the XSD language, but 100 00:03:25,870 --> 00:03:27,790 we are still expressing it in XML. 101 00:03:28,070 --> 00:03:30,950 So we have two XML files, the data file and the schema file. 102 00:03:31,760 --> 00:03:33,000 To validate the data file 103 00:03:33,380 --> 00:03:34,690 against the schema file, we 104 00:03:34,830 --> 00:03:37,100 can use again the XML link feature. 105 00:03:37,890 --> 00:03:39,170 We specify the schema file, 106 00:03:39,620 --> 00:03:41,190 the data file and when 107 00:03:41,360 --> 00:03:43,170 we execute the command 108 00:03:43,540 --> 00:03:45,500 we can see that the file validates correctly. 109 00:03:46,090 --> 00:03:47,400 So I'm now going 110 00:03:47,620 --> 00:03:49,500 to highlight four features of 111 00:03:49,740 --> 00:03:51,670 XML schema that aren't present in DTD's. 112 00:03:52,600 --> 00:03:53,830 One of them is typed values. 113 00:03:54,950 --> 00:03:56,190 One of them is key declarations. 114 00:03:57,160 --> 00:03:58,780 Similar to IDs but a little bit more powerful. 115 00:03:59,730 --> 00:04:01,040 One is references which are again 116 00:04:01,360 --> 00:04:02,410 similar to pointers But a little 117 00:04:02,520 --> 00:04:04,700 more powerful and finally a currents constraints. 118 00:04:06,180 --> 00:04:06,990 So let's start with tights. 119 00:04:08,560 --> 00:04:10,000 In our data we see 120 00:04:10,240 --> 00:04:11,680 that the price attribute is 121 00:04:12,750 --> 00:04:13,880 denoted with a string and 122 00:04:14,140 --> 00:04:15,870 when we had DTDs, all attribute 123 00:04:16,170 --> 00:04:17,410 values were in fact stringed. 124 00:04:18,630 --> 00:04:19,980 In excess fees we can 125 00:04:20,220 --> 00:04:21,130 say that we want to check 126 00:04:21,490 --> 00:04:22,500 that the values which are 127 00:04:22,570 --> 00:04:25,320 still look like strings actually confirm to specific types. 128 00:04:25,970 --> 00:04:28,270 For example we can say that the price must be in integer. 129 00:04:29,170 --> 00:04:30,440 Again I'm not going to 130 00:04:30,490 --> 00:04:32,460 be labor the syntactic details but rather 131 00:04:32,840 --> 00:04:33,970 I'm just going to highlight the 132 00:04:34,030 --> 00:04:35,160 places in the XSD where 133 00:04:35,460 --> 00:04:36,690 we're declaring things of interest. 134 00:04:37,450 --> 00:04:38,860 So specifically here's where we 135 00:04:38,970 --> 00:04:41,000 declare the attribute price and 136 00:04:41,120 --> 00:04:43,140 we say that the type of price must be an integer. 137 00:04:43,760 --> 00:04:45,830 So our document validated correctly, what 138 00:04:45,960 --> 00:04:48,160 if we change this one hundred to be foo instead. 139 00:04:49,170 --> 00:04:50,270 Of course with a DTD this 140 00:04:50,480 --> 00:04:52,430 would be fine because all attributes are treated as strings. 141 00:04:53,330 --> 00:04:54,120 But if we try to validate 142 00:04:54,630 --> 00:04:56,220 now we see an error, 143 00:04:56,660 --> 00:04:58,700 specifically foo is not a value of the correct type. 144 00:04:59,420 --> 00:05:00,570 So let's change that foo back 145 00:05:00,840 --> 00:05:03,530 to a hundred so that we validate correctly. 146 00:05:04,890 --> 00:05:06,150 Next, let's talk about keys. 147 00:05:06,860 --> 00:05:09,170 In DTD's, we were able to specify ID's. 148 00:05:09,470 --> 00:05:11,140 ID's were globally unique 149 00:05:11,510 --> 00:05:12,670 values that could be 150 00:05:12,930 --> 00:05:14,620 used to identify specific elements. 151 00:05:15,250 --> 00:05:16,130 For example, when we wanted 152 00:05:16,660 --> 00:05:18,260 to point to those elements using ID refs . 153 00:05:18,320 --> 00:05:19,990 Keys are a little 154 00:05:20,180 --> 00:05:22,490 bit more powerful or more specific I should say. 155 00:05:23,070 --> 00:05:24,230 If you think about the relational model 156 00:05:24,720 --> 00:05:25,740 a key in the relational model 157 00:05:26,370 --> 00:05:27,410 is an attribute or set of 158 00:05:27,570 --> 00:05:28,860 attributes that must be 159 00:05:28,960 --> 00:05:30,700 unique for each tuple in a table. 160 00:05:31,240 --> 00:05:32,410 So, we don't have tables or 161 00:05:32,470 --> 00:05:33,790 tuples right now but, we 162 00:05:33,950 --> 00:05:36,240 do have elements and we often have repeated elements. 163 00:05:36,980 --> 00:05:38,200 So similarly we can specify 164 00:05:38,780 --> 00:05:40,310 that a particular attribute or component 165 00:05:41,420 --> 00:05:43,880 must be unique within every element of the same type. 166 00:05:44,250 --> 00:05:45,230 And we have two keys 167 00:05:46,050 --> 00:05:48,230 in our specification, one key 168 00:05:48,460 --> 00:05:50,670 which we can see here for books and one for authors. 169 00:05:51,570 --> 00:05:52,760 Specifically we say for books 170 00:05:53,480 --> 00:05:55,560 that the ISBN attribute must be a key. 171 00:05:55,730 --> 00:05:56,940 And we say for authors 172 00:05:57,580 --> 00:05:59,440 that the ident attribute must be a key. 173 00:06:00,260 --> 00:06:01,450 So let's go over to 174 00:06:01,630 --> 00:06:03,450 our data and let's start by looking at the authors. 175 00:06:04,310 --> 00:06:05,370 So if we change, for 176 00:06:05,550 --> 00:06:07,570 example, U to HG 177 00:06:08,550 --> 00:06:09,340 then we should get a key 178 00:06:09,600 --> 00:06:10,970 violation because we'll have two 179 00:06:11,770 --> 00:06:13,780 authors that have the same ident attribute. 180 00:06:14,690 --> 00:06:15,150 Let's try to validate. 181 00:06:16,000 --> 00:06:17,390 In fact, we do correctly get 182 00:06:17,530 --> 00:06:18,600 a key validation we also get 183 00:06:18,780 --> 00:06:19,810 a couple of other errors and 184 00:06:19,930 --> 00:06:20,740 those have to do with the fact 185 00:06:20,980 --> 00:06:22,250 that we are using these items as 186 00:06:22,360 --> 00:06:25,250 the destination of what are affect doubly pointers or references. 187 00:06:25,940 --> 00:06:27,060 So let's change that back 188 00:06:27,320 --> 00:06:28,490 to JU, make sure everything 189 00:06:28,900 --> 00:06:30,810 now validates fine, and it does. 190 00:06:31,190 --> 00:06:32,530 Now lets make another change. 191 00:06:33,390 --> 00:06:34,390 So we have the ident 192 00:06:35,540 --> 00:06:36,970 key here and we have 193 00:06:37,160 --> 00:06:38,590 the ISBN number, being the 194 00:06:38,750 --> 00:06:40,790 number for books, what if changed 195 00:06:41,350 --> 00:06:42,840 the ISBN number to one 196 00:06:43,060 --> 00:06:45,680 of the values we used as a key for the author, say 2HG. 197 00:06:47,480 --> 00:06:48,810 When we did something similar with 198 00:06:49,040 --> 00:06:50,010 DTDs we got an error 199 00:06:50,310 --> 00:06:52,750 because in DTDs, IDs have be globally unique. 200 00:06:53,300 --> 00:06:54,590 Here we should not get an error. 201 00:06:54,970 --> 00:06:55,760 HG should be a perfectly 202 00:06:56,290 --> 00:06:57,510 reasonable key for books because 203 00:06:57,760 --> 00:06:59,170 we don't have another value that's the same. 204 00:07:01,160 --> 00:07:02,070 And in fact it does validate. 205 00:07:03,350 --> 00:07:04,280 Now let's undo that change. 206 00:07:05,380 --> 00:07:06,520 Next, let's talk about references. 207 00:07:07,550 --> 00:07:08,710 So, references allow us to 208 00:07:08,830 --> 00:07:10,070 have what are Possibly typed 209 00:07:10,490 --> 00:07:11,650 pointers, using the dtd. 210 00:07:12,560 --> 00:07:13,750 So, they are called key 211 00:07:13,910 --> 00:07:15,070 refs, and here we 212 00:07:15,220 --> 00:07:17,610 have an example - let me just change this to the middle of the document. 213 00:07:18,770 --> 00:07:19,690 So, one of the reference types 214 00:07:20,030 --> 00:07:21,200 that we've defined in our DTD 215 00:07:21,950 --> 00:07:23,190 is a pointer to authors 216 00:07:23,500 --> 00:07:25,710 that we're using in our books. 217 00:07:26,010 --> 00:07:27,230 Specifically, we want to specify that this 218 00:07:27,640 --> 00:07:29,680 attribute here, the auth ident, 219 00:07:29,860 --> 00:07:30,870 has a value that is 220 00:07:30,990 --> 00:07:32,650 a key for the author elements. 221 00:07:33,410 --> 00:07:34,150 And we want to make sure it's 222 00:07:34,300 --> 00:07:35,270 author elements that its pointing 223 00:07:35,780 --> 00:07:36,970 to and not other types of elements. 224 00:07:37,820 --> 00:07:39,070 Now the syntax for doing 225 00:07:39,430 --> 00:07:42,510 this in XML schema is rather detailed. 226 00:07:43,370 --> 00:07:45,130 Its alright here and 227 00:07:45,270 --> 00:07:46,360 just to give you a flavor, 228 00:07:46,920 --> 00:07:48,800 this middle selector here is 229 00:07:48,900 --> 00:07:50,150 actually using the XPath language 230 00:07:50,470 --> 00:07:51,940 which we'll be using, which we'll 231 00:07:52,180 --> 00:07:53,500 be learning later but what it 232 00:07:53,620 --> 00:07:54,450 says is that when we navigate 233 00:07:54,960 --> 00:07:57,260 in the document down to one of these auth elements. 234 00:07:58,340 --> 00:07:59,830 Within that auth element, the 235 00:08:00,030 --> 00:08:01,280 auth ident attribute is 236 00:08:01,600 --> 00:08:02,950 a reference to what we 237 00:08:03,120 --> 00:08:04,990 have already defined as author keys. 238 00:08:06,320 --> 00:08:08,060 We've done something similar with books. 239 00:08:08,820 --> 00:08:10,760 We have our book /remark/bookref 240 00:08:12,450 --> 00:08:14,450 that brings us down to this element here. 241 00:08:15,260 --> 00:08:17,150 And there we specified that the 242 00:08:17,490 --> 00:08:19,480 book attribute must be 243 00:08:19,610 --> 00:08:20,910 a reference to a book key, 244 00:08:21,600 --> 00:08:22,530 and the book key was earlier 245 00:08:22,890 --> 00:08:24,270 defined to be the ISBN number. 246 00:08:25,030 --> 00:08:25,800 Again, I know this is all 247 00:08:25,980 --> 00:08:27,330 complicated, and the syntax is 248 00:08:27,460 --> 00:08:28,730 very clunky, so I urge 249 00:08:28,840 --> 00:08:32,270 you to download the specification and spend time looking at it on your own. 250 00:08:33,340 --> 00:08:34,330 Now let's make a couple of 251 00:08:34,420 --> 00:08:35,800 changes to our document to 252 00:08:35,920 --> 00:08:38,570 demonstrate how the checking of these typed pointers works. 253 00:08:39,000 --> 00:08:41,130 For example lets change 254 00:08:41,560 --> 00:08:44,300 our first reference here to food. 255 00:08:46,600 --> 00:08:48,230 Let's validate the document and 256 00:08:48,320 --> 00:08:49,680 we should get an error and indeed 257 00:08:49,920 --> 00:08:52,510 we do, the author key rep is incorrect. 258 00:08:55,070 --> 00:08:55,820 Now lets change that FU to JW, 259 00:08:56,870 --> 00:08:58,130 so originally it was JU 260 00:08:59,010 --> 00:09:00,070 But now we're going to have two 261 00:09:00,220 --> 00:09:01,850 authors, both of whom refer to JW. 262 00:09:02,100 --> 00:09:03,790 Now this should not be a problem. 263 00:09:04,080 --> 00:09:05,720 It's simply two pointers to 264 00:09:05,840 --> 00:09:06,800 the same author, and we did 265 00:09:06,980 --> 00:09:07,980 not prohibit that in our 266 00:09:08,390 --> 00:09:11,210 XMLs schema specification and indeed our document validates. 267 00:09:13,260 --> 00:09:14,160 We'll change that one back. 268 00:09:14,860 --> 00:09:16,040 And the last, as a last 269 00:09:16,330 --> 00:09:17,690 change, we'll change our book 270 00:09:17,940 --> 00:09:19,180 reference here to refer 271 00:09:19,700 --> 00:09:20,870 to JW. 272 00:09:22,880 --> 00:09:24,460 This should not validate because this 273 00:09:24,680 --> 00:09:26,340 time, unlike with DTDs, we're, 274 00:09:27,050 --> 00:09:28,190 we've actually specified typed pointers. 275 00:09:28,980 --> 00:09:30,340 In other words, we've specified that 276 00:09:30,580 --> 00:09:31,720 this pointer or this 277 00:09:31,970 --> 00:09:33,350 reference must be to 278 00:09:34,010 --> 00:09:35,710 a book element and not to an author element. 279 00:09:36,240 --> 00:09:38,040 So we'll validate and indeed it fails. 280 00:09:39,990 --> 00:09:41,230 I've undone that change and 281 00:09:41,430 --> 00:09:42,300 now let's move to the last 282 00:09:42,780 --> 00:09:43,800 feature that we're gonna look at 283 00:09:43,920 --> 00:09:45,780 in this demonstration which is a currents constraint. 284 00:09:47,180 --> 00:09:48,190 So in, let me just 285 00:09:48,690 --> 00:09:50,270 bring up the first instance of 286 00:09:50,400 --> 00:09:51,490 it, in XML schema, 287 00:09:51,810 --> 00:09:52,990 we can specify how many 288 00:09:53,220 --> 00:09:55,200 times an element type is allowed to occur. 289 00:09:55,940 --> 00:09:57,370 Specifically we can specify the 290 00:09:57,460 --> 00:09:59,910 minimum number of occurrences and the maximum number of occurrences. 291 00:10:00,370 --> 00:10:01,840 As a default if 292 00:10:02,020 --> 00:10:03,550 we don't specify for an 293 00:10:03,700 --> 00:10:07,240 element the minOccurs or maxiOccurs the default for both of them is one. 294 00:10:08,090 --> 00:10:09,320 So here for books we've 295 00:10:09,550 --> 00:10:10,410 said that we can have 296 00:10:10,750 --> 00:10:12,360 zero Books and we can have any number. 297 00:10:12,750 --> 00:10:15,320 So this is the maximum flexibility, any number of elements. 298 00:10:16,250 --> 00:10:17,760 For authors we've also said 299 00:10:17,990 --> 00:10:19,010 we can have any number of authors 300 00:10:19,480 --> 00:10:21,670 that's in the actual database itself. 301 00:10:22,140 --> 00:10:24,840 Remember that our book store consists of a set of books and a set of authors. 302 00:10:25,620 --> 00:10:26,380 But we are going to specify 303 00:10:26,830 --> 00:10:27,800 something a little different for 304 00:10:27,940 --> 00:10:30,350 how many authors we have within a specific book. 305 00:10:31,470 --> 00:10:32,550 So let's continue to look 306 00:10:32,720 --> 00:10:33,800 at other cases where we've specified 307 00:10:35,270 --> 00:10:35,730 occurrence constraints. 308 00:10:36,750 --> 00:10:37,620 Here is the case where we're 309 00:10:37,760 --> 00:10:39,040 specifying how many authors we 310 00:10:39,160 --> 00:10:40,610 have within a book and 311 00:10:40,730 --> 00:10:42,670 again few boy this 312 00:10:43,060 --> 00:10:44,310 is a lot of XML here 313 00:10:44,670 --> 00:10:45,720 so take your time when looking 314 00:10:46,020 --> 00:10:47,750 at it; or for now just take my word for it. 315 00:10:47,780 --> 00:10:49,750 What we're specifying here is 316 00:10:49,910 --> 00:10:51,450 how many sub elements, how 317 00:10:51,540 --> 00:10:52,900 many auth sub elements we 318 00:10:53,030 --> 00:10:54,730 have within each author's element. 319 00:10:55,790 --> 00:10:57,070 And here we have no minOccurs 320 00:10:57,660 --> 00:10:58,950 specification only a maxOccurs. 321 00:10:59,200 --> 00:11:01,630 That means by default minOccurs is one. 322 00:11:02,420 --> 00:11:04,380 So what this is saying specifically, is 323 00:11:04,550 --> 00:11:06,560 that every book has in 324 00:11:06,730 --> 00:11:08,700 it's authors sub element, atleast 325 00:11:09,240 --> 00:11:10,350 one off, but we can have. 326 00:11:10,780 --> 00:11:12,590 any number of them, that's the string unbounded. 327 00:11:14,240 --> 00:11:15,770 Looking at the remaining occurrence constraints, 328 00:11:16,840 --> 00:11:18,160 for remarks, we have the 329 00:11:18,230 --> 00:11:19,840 minimum number of occurrences is zero. 330 00:11:20,120 --> 00:11:21,580 In other words, we don't have to have a remark. 331 00:11:22,000 --> 00:11:23,560 And we haven't specified max 332 00:11:23,960 --> 00:11:26,150 occurs so the default max occurs is one. 333 00:11:27,000 --> 00:11:28,020 So what we're saying here is that 334 00:11:28,150 --> 00:11:29,320 every book may have either 335 00:11:29,630 --> 00:11:31,060 no remark or exactly one 336 00:11:31,300 --> 00:11:32,140 remark but it may not 337 00:11:32,370 --> 00:11:34,710 have more than that. 338 00:11:34,850 --> 00:11:36,310 And there's a few more occurrence constraints that 339 00:11:36,440 --> 00:11:37,420 you can take a look at again 340 00:11:37,900 --> 00:11:40,210 as you browse the XML schema description on your own. 341 00:11:40,770 --> 00:11:41,940 Now let's make some changes in 342 00:11:42,040 --> 00:11:43,940 the document to test these occurrence constraints. 343 00:11:45,130 --> 00:11:47,740 So first let's remove the authors from our first book. 344 00:11:47,950 --> 00:11:48,810 We won't remove the whole author 345 00:11:49,280 --> 00:11:50,310 sub element but just the two 346 00:11:50,700 --> 00:11:52,360 off sub elements of authors. 347 00:11:53,310 --> 00:11:56,120 We attempt to validate and we see that it doesn't validate. 348 00:11:56,580 --> 00:11:57,810 We're missing some child elements, 349 00:11:58,120 --> 00:11:59,770 specifically the off-child elements 350 00:12:00,260 --> 00:12:02,340 because we expected there to be at least one of them. 351 00:12:03,250 --> 00:12:04,870 Incidentally, if we took 352 00:12:05,100 --> 00:12:07,170 the entire author sub-element out, 353 00:12:07,370 --> 00:12:08,390 we'll also get an error since 354 00:12:08,660 --> 00:12:11,070 we've specified the books must have author sub element. 355 00:12:11,860 --> 00:12:12,950 So now we're missing the entire 356 00:12:13,350 --> 00:12:15,710 author structure in that book and again we don't validate. 357 00:12:17,680 --> 00:12:20,380 Let's put authors back; and 358 00:12:20,560 --> 00:12:21,540 now let's look at the 359 00:12:21,870 --> 00:12:23,690 remark occurrence constraint so 360 00:12:23,800 --> 00:12:24,980 we said that every book can 361 00:12:25,200 --> 00:12:26,610 have zero or one 362 00:12:26,840 --> 00:12:29,490 remarks, so let's just add another remark to this book. 363 00:12:34,710 --> 00:12:37,750 Oh, hi, actually remarks are allowed to be empty. 364 00:12:38,770 --> 00:12:40,230 In any case, we have added a small remark. 365 00:12:40,840 --> 00:12:42,120 We validate and we see 366 00:12:42,430 --> 00:12:43,500 that we have too many remarks 367 00:12:44,340 --> 00:12:45,900 again because we specified that 368 00:12:46,050 --> 00:12:47,610 every book can have at most one remark. 369 00:12:48,040 --> 00:12:49,970 So that concludes our 370 00:12:50,060 --> 00:12:51,850 demonstration of XML schema again, 371 00:12:52,260 --> 00:12:53,590 it's been rather cursory we've 372 00:12:53,760 --> 00:12:54,860 only covered a few of 373 00:12:54,950 --> 00:12:56,150 the constructs but I did 374 00:12:56,430 --> 00:12:57,570 focus on the constructs that 375 00:12:57,720 --> 00:12:59,210 we have in XML schema 376 00:12:59,550 --> 00:13:01,340 that are not specifiable in DTDs. 377 00:13:02,410 --> 00:13:03,600 Finally one more time I 378 00:13:03,820 --> 00:13:05,100 urge you download the access 379 00:13:05,600 --> 00:13:07,820 fee and the document and play around with it yourself