1 00:00:00,750 --> 00:00:02,760 This video introduces the basics of XML. 2 00:00:04,210 --> 00:00:05,160 XML can be thought of as 3 00:00:05,310 --> 00:00:06,670 a data model, an alternative to 4 00:00:06,780 --> 00:00:08,440 the relational model, for structuring data. 5 00:00:09,240 --> 00:00:10,420 In addition to introducing XML, 6 00:00:10,850 --> 00:00:11,640 we will compare it to the 7 00:00:11,730 --> 00:00:13,330 relational model, although it 8 00:00:13,370 --> 00:00:14,750 is not critical to have watched 9 00:00:15,040 --> 00:00:17,830 the relational model videos in order to get something out of this one. 10 00:00:19,290 --> 00:00:22,100 The full name of XML is the extensible markup language. 11 00:00:23,390 --> 00:00:24,230 XML is a standard for 12 00:00:24,350 --> 00:00:26,290 data representation and exchange, and 13 00:00:26,350 --> 00:00:27,880 it was designed initially for exchanging 14 00:00:28,500 --> 00:00:29,620 information on the Internet. 15 00:00:30,510 --> 00:00:31,370 Now don't worry if you 16 00:00:31,480 --> 00:00:33,580 can't read the little snippet in the corner of the video here. 17 00:00:33,710 --> 00:00:35,200 You're not expected to at this point. 18 00:00:36,320 --> 00:00:37,940 XML can be thought 19 00:00:38,210 --> 00:00:40,230 of as a document format similar 20 00:00:40,470 --> 00:00:42,370 to HTML, if you're familiar with HTML. 21 00:00:42,820 --> 00:00:43,290 Most people are. 22 00:00:43,890 --> 00:00:45,090 The big difference is that 23 00:00:45,280 --> 00:00:46,950 the tags in an HTML document 24 00:00:47,880 --> 00:00:49,230 describe the content of the 25 00:00:49,310 --> 00:00:50,450 data rather than how to 26 00:00:50,660 --> 00:00:51,790 format the data, which is 27 00:00:51,880 --> 00:00:53,530 what the tags in HTML tend to represent. 28 00:00:55,040 --> 00:00:56,270 XML also has a streaming 29 00:00:56,620 --> 00:00:58,030 format or a streaming standard, 30 00:00:58,810 --> 00:00:59,690 and that's typically for the use 31 00:01:00,010 --> 00:01:01,670 of XML in programs, for 32 00:01:01,920 --> 00:01:03,550 admitting XML and consuming XML. 33 00:01:04,850 --> 00:01:06,890 So now let's take a look at the XML data itself. 34 00:01:07,840 --> 00:01:10,630 You see on the left side of the video a portion of an XML document. 35 00:01:11,200 --> 00:01:12,690 The entire document is available 36 00:01:13,230 --> 00:01:14,430 from the website for the course. 37 00:01:16,020 --> 00:01:17,570 XML has three basic components. 38 00:01:18,270 --> 00:01:19,780 Again, fairly similar to HTML. 39 00:01:20,460 --> 00:01:21,950 The first is tagged element. 40 00:01:22,390 --> 00:01:24,680 So, for example let's take a look at this element here. 41 00:01:24,920 --> 00:01:26,180 This is an element saying, 42 00:01:26,450 --> 00:01:28,020 that the data here is a first name. 43 00:01:28,280 --> 00:01:31,070 So we have a opening tag and we have a matching closing tag. 44 00:01:31,950 --> 00:01:33,120 We also have nesting development. 45 00:01:33,870 --> 00:01:36,470 So for example here we have an element that's authored. 46 00:01:37,280 --> 00:01:38,490 We have the opening tag here, the 47 00:01:38,730 --> 00:01:39,900 closing tag here, and we 48 00:01:40,140 --> 00:01:42,170 have a nesting of the first name and last name elements. 49 00:01:42,470 --> 00:01:44,000 Even larger we have 50 00:01:44,310 --> 00:01:45,830 a book element here with opening 51 00:01:46,200 --> 00:01:47,500 and closing tags with a 52 00:01:47,560 --> 00:01:49,330 nesting of numerous elements inside 53 00:01:50,150 --> 00:01:52,040 and the entire document actually is 54 00:01:52,130 --> 00:01:53,440 one element whose opening tag 55 00:01:53,750 --> 00:01:54,860 is bookstore and the closing tag 56 00:01:55,490 --> 00:01:57,150 isn't visible on the video here. 57 00:01:58,060 --> 00:01:59,570 So that's what elements consist 58 00:02:00,000 --> 00:02:02,050 of, an opening tag, text or 59 00:02:02,470 --> 00:02:05,270 other sub-elements and a closing tag. 60 00:02:06,090 --> 00:02:07,530 In addition we have have 61 00:02:07,800 --> 00:02:09,200 attributes so each element 62 00:02:09,590 --> 00:02:11,330 may have within its opening 63 00:02:11,590 --> 00:02:13,350 tag and let's take a look at the book element here. 64 00:02:13,950 --> 00:02:15,050 A set of attributes and 65 00:02:15,370 --> 00:02:16,530 an attribute consists of 66 00:02:16,620 --> 00:02:18,210 an attribute name, the equal 67 00:02:18,580 --> 00:02:19,930 sign and then an attribute value. 68 00:02:20,450 --> 00:02:21,930 So, our book element 69 00:02:22,460 --> 00:02:24,050 right here has three attributes. 70 00:02:24,450 --> 00:02:25,900 One called ISPN, one called 71 00:02:26,200 --> 00:02:27,260 Price and one called 72 00:02:27,570 --> 00:02:29,080 Edition. And any element 73 00:02:29,500 --> 00:02:31,400 can have any number of 74 00:02:31,630 --> 00:02:33,460 attributes as long as the attribute names are unique. 75 00:02:34,570 --> 00:02:36,110 And finally, the third component of 76 00:02:36,470 --> 00:02:37,630 XML is the text itself 77 00:02:38,140 --> 00:02:39,140 which is depicted here in black. 78 00:02:39,840 --> 00:02:41,680 So, within elements, we can have strengths. 79 00:02:42,240 --> 00:02:43,410 We have a strength all right 80 00:02:43,650 --> 00:02:44,860 here, we have a title 81 00:02:45,130 --> 00:02:46,680 here, here we have a remark. 82 00:02:47,420 --> 00:02:48,800 And so, that's generally sort 83 00:02:49,000 --> 00:02:50,060 of, think of XML as 84 00:02:50,310 --> 00:02:52,160 a tree, the strings form, or 85 00:02:52,280 --> 00:02:54,470 the text form, the leaf element of the tree. 86 00:02:55,170 --> 00:02:57,510 So, again, those are the three major components of xml. 87 00:02:57,950 --> 00:02:59,930 Look's a lot like HTML, except 88 00:03:00,390 --> 00:03:01,660 the tags are describing the 89 00:03:01,770 --> 00:03:04,130 content of the data, and not how to format it. 90 00:03:05,710 --> 00:03:08,680 Now let's spend some time comparing the relational model against XML. 91 00:03:09,510 --> 00:03:10,730 Again, it's not critical, that you 92 00:03:10,860 --> 00:03:11,980 learn about the relational model and 93 00:03:12,050 --> 00:03:13,150 you can skip this material if 94 00:03:13,260 --> 00:03:15,250 you're not interested, but in many 95 00:03:15,600 --> 00:03:17,330 cases when designing an application that's dealing 96 00:03:17,650 --> 00:03:18,770 with data you might have to 97 00:03:18,910 --> 00:03:20,140 make a decision whether you want 98 00:03:20,410 --> 00:03:21,830 to use a relational database or whether 99 00:03:22,070 --> 00:03:23,590 you want to store the data in XML. 100 00:03:23,890 --> 00:03:24,880 So let's look at a 101 00:03:24,960 --> 00:03:25,790 few different aspects of the 102 00:03:26,580 --> 00:03:27,650 data and how it's used and 103 00:03:27,850 --> 00:03:29,650 how it compares between relational and XML. 104 00:03:30,400 --> 00:03:32,100 Let's start with the structure of the data itself. 105 00:03:32,940 --> 00:03:34,240 So as we learn, the structure 106 00:03:34,790 --> 00:03:37,700 in a relational model is basically a set of tables. 107 00:03:38,260 --> 00:03:40,660 So we define the set of columns and we have a set of rows. 108 00:03:41,990 --> 00:03:43,940 XML is generally, again it's 109 00:03:44,150 --> 00:03:45,270 usually in a document or 110 00:03:45,560 --> 00:03:46,550 a string format, but if you 111 00:03:46,650 --> 00:03:49,310 think about the structure itself, the structure is hierarchical. 112 00:03:50,530 --> 00:03:54,290 The nested elements induce a hierarchy or a tree. 113 00:03:55,860 --> 00:03:57,240 There are constructs that actually allow 114 00:03:57,530 --> 00:03:59,280 us to have links within 115 00:03:59,750 --> 00:04:00,760 documents and so, you can 116 00:04:00,910 --> 00:04:03,540 also have XML representing 117 00:04:03,590 --> 00:04:04,790 a graph though, in general, it's 118 00:04:04,980 --> 00:04:06,430 mostly thought of as a tree structure. 119 00:04:08,090 --> 00:04:09,050 Next, let's talk about schemas. 120 00:04:10,220 --> 00:04:12,180 In the relational model the schema is very important. 121 00:04:12,800 --> 00:04:14,300 You fix your schema in 122 00:04:14,510 --> 00:04:15,510 advance, when you design your database, 123 00:04:16,400 --> 00:04:18,630 and them you add the data to conform to the schema. 124 00:04:19,680 --> 00:04:21,470 Now, in XML, you have a lot more flexibility. 125 00:04:22,240 --> 00:04:23,410 So the schema is flexible. 126 00:04:24,760 --> 00:04:26,100 In fact, a lot of 127 00:04:26,190 --> 00:04:27,880 people refer to XML as self-describing. 128 00:04:28,680 --> 00:04:29,840 In other words, the 129 00:04:29,910 --> 00:04:31,800 schema and the data kind of mixed together. 130 00:04:32,520 --> 00:04:34,230 The tags on elements are 131 00:04:34,490 --> 00:04:35,590 telling you the kind of data 132 00:04:35,890 --> 00:04:37,720 you'll have, and you can have a lot of irregularity. 133 00:04:38,860 --> 00:04:39,780 Now I will say that 134 00:04:39,910 --> 00:04:41,360 their are many mechanisms for introducing 135 00:04:41,840 --> 00:04:43,750 schemas into XML but they're not required. 136 00:04:44,480 --> 00:04:46,890 In the relational model schemas are absolutely required. 137 00:04:47,480 --> 00:04:49,780 In XML they're more optional. 138 00:04:50,240 --> 00:04:51,850 In particular, let's go 139 00:04:52,020 --> 00:04:52,890 back and take a look 140 00:04:53,370 --> 00:04:54,910 at our example, and we'll 141 00:04:55,120 --> 00:04:56,660 see that we have sort of 142 00:04:56,790 --> 00:04:57,740 some structure in our example, 143 00:04:58,660 --> 00:05:00,110 but not everything is perfectly structured, 144 00:05:00,480 --> 00:05:01,750 as it would be in the model. 145 00:05:02,510 --> 00:05:03,910 So, coming back here and taking a look, 146 00:05:04,170 --> 00:05:05,240 first of all, we have 147 00:05:05,790 --> 00:05:07,120 the situation where in this 148 00:05:07,630 --> 00:05:09,990 first book, we have an attribute called edition, the third edition. 149 00:05:10,790 --> 00:05:11,910 Whereas in the second book 150 00:05:12,180 --> 00:05:14,830 we only have two attributes, so there's no addition in this book. 151 00:05:15,560 --> 00:05:16,890 Now in the relational model, 152 00:05:17,550 --> 00:05:18,470 we would have to have a column 153 00:05:18,690 --> 00:05:20,470 for addition, and we have one for every book. 154 00:05:20,620 --> 00:05:23,410 Although of course we could have null editions for some books. 155 00:05:24,000 --> 00:05:25,630 In XML, it's perfectly acceptable 156 00:05:26,260 --> 00:05:27,440 to have some attributes for some 157 00:05:27,650 --> 00:05:30,250 elements and those attributes don't appear in other elements. 158 00:05:31,470 --> 00:05:32,680 Here's another example where we 159 00:05:32,840 --> 00:05:33,910 have a component in one book 160 00:05:34,080 --> 00:05:36,310 that's not in another and it's this remark component. 161 00:05:36,900 --> 00:05:37,870 So here we have a book 162 00:05:37,990 --> 00:05:38,730 where we happen to have a 163 00:05:38,970 --> 00:05:41,460 remark and incidentally, you can 164 00:05:41,610 --> 00:05:42,950 see that this book suggests, this 165 00:05:43,150 --> 00:05:43,990 remark suggests that we buy 166 00:05:44,280 --> 00:05:46,160 the complete book together with the first course. 167 00:05:46,420 --> 00:05:47,210 The first course is a subset, 168 00:05:47,330 --> 00:05:48,100 so it's not a very 169 00:05:48,280 --> 00:05:50,870 good suggestion, although Amazon actually did make that one. 170 00:05:51,550 --> 00:05:52,260 Anyway, enough of the asides. 171 00:05:53,300 --> 00:05:54,210 We do see that we have 172 00:05:54,320 --> 00:05:55,320 remark for the first book 173 00:05:55,650 --> 00:05:56,650 and we have no remark for the 174 00:05:56,780 --> 00:05:57,890 second book and that's not 175 00:05:58,230 --> 00:06:00,250 a problem whatsoever in XML. 176 00:06:00,960 --> 00:06:02,610 In the relational model, we 177 00:06:02,700 --> 00:06:04,560 would again have to use null values for that case. 178 00:06:04,750 --> 00:06:06,100 And the third example I 179 00:06:06,220 --> 00:06:07,860 just wanted to give is the number of authors. 180 00:06:08,390 --> 00:06:10,040 So this first book has two authors. 181 00:06:10,840 --> 00:06:13,070 The second book - you can't see them all, but it has three authors. 182 00:06:13,830 --> 00:06:15,220 Not a problem in XML. 183 00:06:15,820 --> 00:06:17,680 Having different numbers of things 184 00:06:18,340 --> 00:06:19,250 is perfectly standard. 185 00:06:19,940 --> 00:06:21,090 So the main point being 186 00:06:21,350 --> 00:06:22,540 that there's a lot of flexibility 187 00:06:23,720 --> 00:06:24,650 in XML in terms of the schema. 188 00:06:25,450 --> 00:06:26,870 You can create your database with 189 00:06:27,090 --> 00:06:28,330 certain types of elements, later 190 00:06:28,660 --> 00:06:29,820 add more elements, remove elements, 191 00:06:30,300 --> 00:06:33,280 introduce inconsistencies in 192 00:06:33,380 --> 00:06:34,790 the structure, and it's not a problem. 193 00:06:35,810 --> 00:06:37,080 And again, I'll mention one more 194 00:06:37,800 --> 00:06:39,280 time that there are mechanisms for 195 00:06:39,490 --> 00:06:41,840 adding schema-like elements to 196 00:06:42,080 --> 00:06:44,480 XML or schema-like specifications to XML. 197 00:06:44,700 --> 00:06:47,650 We will be covering those in the next two videos actually. 198 00:06:49,050 --> 00:06:50,760 Next, let's talk about how this data is queried. 199 00:06:51,650 --> 00:06:53,470 So for the relational model, we have relational algebra. 200 00:06:53,920 --> 00:06:54,540 We have SQL. 201 00:06:55,200 --> 00:06:58,480 These are pretty simple, nice languages, I would say. 202 00:06:58,740 --> 00:06:59,670 It's a little bit of a 203 00:06:59,850 --> 00:07:02,650 matter of opinion, but I'm going to give them a smiley face. 204 00:07:03,750 --> 00:07:05,790 XML querying is a little trickier. 205 00:07:06,500 --> 00:07:07,740 Now, one of the 206 00:07:07,820 --> 00:07:08,870 factors here is that XML 207 00:07:09,230 --> 00:07:10,150 is a lot newer than the 208 00:07:10,380 --> 00:07:11,740 relational model and querying XML 209 00:07:12,020 --> 00:07:14,530 is still settling down to some extent. 210 00:07:14,960 --> 00:07:15,920 But I'm just gonna say, it's a little 211 00:07:16,280 --> 00:07:17,190 less, so I'm gonna give 212 00:07:17,310 --> 00:07:18,910 it a neutral face here, in 213 00:07:19,120 --> 00:07:20,550 terms of how simple and 214 00:07:20,700 --> 00:07:21,960 nice the languages are for querying 215 00:07:22,050 --> 00:07:23,240 XML and we'll be spending some 216 00:07:23,600 --> 00:07:25,800 time in later videos learning some of those languages. 217 00:07:27,260 --> 00:07:29,840 Next, in our chart is the aspect of ordering. 218 00:07:30,470 --> 00:07:31,690 So the relational model is 219 00:07:32,040 --> 00:07:33,600 fundamentally an unordered model 220 00:07:34,410 --> 00:07:35,880 and that can actually be considered a bad thing to some extent. 221 00:07:35,970 --> 00:07:36,400 Sometimes in data applications it's nice to have ordering. 222 00:07:36,580 --> 00:07:38,150 We learned the order by clause in SQL and that's a way to get order in query results. 223 00:07:38,490 --> 00:07:39,210 But fundamentally, the data in our table, in our relationship database, is a set of data, without an ordering within that set. 224 00:07:39,240 --> 00:07:39,630 Now, in XML we do have, I would say, an implied ordering. 225 00:07:39,790 --> 00:07:41,100 So XML, as I said, can be thought of as either a document model or a stream model. 226 00:07:48,140 --> 00:08:02,750 And either case, 227 00:08:03,330 --> 00:08:04,450 just the nature of the 228 00:08:05,050 --> 00:08:06,070 XML being laid out in 229 00:08:06,210 --> 00:08:07,240 a document as we have here 230 00:08:08,010 --> 00:08:09,880 or being in a stream induces an order. 231 00:08:10,250 --> 00:08:12,720 Very specifically, let's take a look at the authors here. 232 00:08:13,000 --> 00:08:14,390 So here we have two authors, 233 00:08:14,960 --> 00:08:16,800 and these authors are in an order in the document. 234 00:08:17,590 --> 00:08:20,560 If we put those authors in a relational database, there would be no order. 235 00:08:20,850 --> 00:08:21,580 They could come out in either 236 00:08:21,850 --> 00:08:23,390 order unless we did 237 00:08:23,760 --> 00:08:24,850 a order-by clause in our 238 00:08:25,110 --> 00:08:26,940 query, whereas in XML, 239 00:08:27,670 --> 00:08:29,990 implied by the document structure is an order. 240 00:08:30,210 --> 00:08:31,940 And there's an order between these two books as well. 241 00:08:32,290 --> 00:08:34,380 Sometimes that order is meaningful; sometimes it's not. 242 00:08:34,670 --> 00:08:37,250 But it is available to be used in an application. 243 00:08:38,700 --> 00:08:39,890 Lastly, let's talk about implementation. 244 00:08:40,760 --> 00:08:41,940 As I mentioned in earlier 245 00:08:42,310 --> 00:08:43,790 videos, the relational model has 246 00:08:43,930 --> 00:08:45,680 been around for as least 247 00:08:45,860 --> 00:08:47,170 35 years, and the systems 248 00:08:47,630 --> 00:08:49,550 that implement it have been around almost as long. 249 00:08:50,110 --> 00:08:51,650 They're very mature systems. 250 00:08:52,500 --> 00:08:54,270 They implement the relational model 251 00:08:54,790 --> 00:08:56,220 as the native model of the 252 00:08:56,300 --> 00:08:58,130 systems and they're widely used. 253 00:08:59,000 --> 00:09:00,650 Things with XML are 254 00:09:00,720 --> 00:09:02,300 a little bit different, partly again because 255 00:09:02,560 --> 00:09:03,950 XML hasn't been around as long. 256 00:09:04,600 --> 00:09:05,990 But what's happening right now 257 00:09:06,380 --> 00:09:07,740 in terms of XML and conventional 258 00:09:08,040 --> 00:09:10,410 database systems is XML is typically an add-on. 259 00:09:11,290 --> 00:09:13,240 So in most systems, XML 260 00:09:13,900 --> 00:09:16,080 will be a layer over the relational database system. 261 00:09:16,400 --> 00:09:17,730 You can enter data in 262 00:09:17,890 --> 00:09:19,510 XML; you can query data in XML. 263 00:09:19,740 --> 00:09:22,190 It will be translated to a relational implementation. 264 00:09:23,720 --> 00:09:24,340 That's not necessarily a bad thing. 265 00:09:24,990 --> 00:09:26,140 And it does allow you to 266 00:09:26,590 --> 00:09:28,100 combine relational data and 267 00:09:28,520 --> 00:09:29,750 XML in a single system, sometimes 268 00:09:30,130 --> 00:09:31,660 even in a single query, but 269 00:09:31,790 --> 00:09:33,410 it's not the native model of the system itself. 270 00:09:34,760 --> 00:09:37,250 Now you might have noticed that the name of this video is "Well-formed-XML". 271 00:09:37,280 --> 00:09:39,840 So well-formed XML is 272 00:09:39,990 --> 00:09:41,770 actually the most flexible XML. 273 00:09:42,030 --> 00:09:44,080 An XML document or 274 00:09:44,150 --> 00:09:45,050 an XML stream is considered 275 00:09:45,530 --> 00:09:46,790 well formed if it adheres 276 00:09:47,250 --> 00:09:49,130 to the basic structural requirements of XML. 277 00:09:49,370 --> 00:09:50,240 And there aren't many. 278 00:09:51,190 --> 00:09:52,530 Just that we have a single 279 00:09:52,820 --> 00:09:54,200 root element, as we discussed 280 00:09:54,410 --> 00:09:55,540 before, a single bookstore in this 281 00:09:55,710 --> 00:09:56,980 case; that all of 282 00:09:57,130 --> 00:09:58,310 our tags are matching, we don't 283 00:09:58,590 --> 00:10:00,220 have open tags without closed 284 00:10:00,700 --> 00:10:02,240 tags; and our tags 285 00:10:02,570 --> 00:10:04,470 are properly nested, so we don't have interweaving of elements. 286 00:10:05,120 --> 00:10:06,960 And finally, within each 287 00:10:07,030 --> 00:10:08,900 element if we have attribute names, they're unique. 288 00:10:09,460 --> 00:10:10,380 And that's about it. 289 00:10:10,700 --> 00:10:12,360 That's all we require for a 290 00:10:12,630 --> 00:10:14,280 XML document, or 291 00:10:14,350 --> 00:10:16,300 a set of XML data to be considered well-formed. 292 00:10:16,870 --> 00:10:19,370 And for many applications, that's all we're concerned about. 293 00:10:20,950 --> 00:10:22,250 In order to test whether a 294 00:10:22,490 --> 00:10:23,710 document is well-formed, and specifically 295 00:10:24,430 --> 00:10:25,850 to access the components of 296 00:10:25,960 --> 00:10:27,070 the document in a program, 297 00:10:27,630 --> 00:10:29,010 we have what's called an XML parser. 298 00:10:29,920 --> 00:10:31,040 So, we'll take an XML 299 00:10:31,370 --> 00:10:33,160 document here, and we'll 300 00:10:33,640 --> 00:10:34,690 feed it to an XML parser, 301 00:10:35,640 --> 00:10:36,910 and the parser will check the 302 00:10:37,110 --> 00:10:39,510 basic structure of the document, 303 00:10:40,300 --> 00:10:42,360 just to make sure that everything is okay. 304 00:10:43,310 --> 00:10:44,820 If the document doesn't appear to 305 00:10:45,120 --> 00:10:46,680 these three requirements up here, 306 00:10:46,850 --> 00:10:49,130 the parser will just send an error saying it's not well-formed. 307 00:10:50,320 --> 00:10:51,560 If the document does adhere 308 00:10:51,910 --> 00:10:54,570 to the structure, then what comes out is parsed XML. 309 00:10:54,800 --> 00:10:56,330 And, there's various standards 310 00:10:57,320 --> 00:10:59,830 for how we show parsed XML. 311 00:11:00,050 --> 00:11:01,390 One is called the document object 312 00:11:01,720 --> 00:11:03,310 model, or DOM; it's a 313 00:11:03,600 --> 00:11:05,750 programmatic interface for sort 314 00:11:05,920 --> 00:11:08,070 of traversing the tree that's implied by XML. 315 00:11:08,720 --> 00:11:10,000 Another popular one is SAX. 316 00:11:10,750 --> 00:11:12,640 That's a more of a stream model for XML. 317 00:11:12,900 --> 00:11:13,950 So these are the ways in 318 00:11:14,040 --> 00:11:15,660 which a program would access the 319 00:11:15,760 --> 00:11:17,660 parsed XML when it comes out of the parser. 320 00:11:18,770 --> 00:11:19,900 So one issue that comes up, 321 00:11:20,070 --> 00:11:21,240 because the XML data is used 322 00:11:21,540 --> 00:11:23,010 frequently on the internet, is 323 00:11:23,250 --> 00:11:25,170 how we display XML. 324 00:11:25,990 --> 00:11:27,140 So one way to display XML is just 325 00:11:27,210 --> 00:11:28,790 as we see it here, but very 326 00:11:29,010 --> 00:11:30,310 often we want to format the 327 00:11:30,380 --> 00:11:31,640 data that's in an XML 328 00:11:31,810 --> 00:11:32,920 document or an XML string 329 00:11:33,050 --> 00:11:34,760 in a more intuitive way. 330 00:11:36,000 --> 00:11:37,870 And actually there's a nice setup for doing that. 331 00:11:38,470 --> 00:11:39,790 What we can do is use a 332 00:11:40,040 --> 00:11:41,550 rule-based language to take 333 00:11:41,980 --> 00:11:42,680 the XML and translate it automatically 334 00:11:42,730 --> 00:11:46,110 to HTML, which we can then render in a browser. 335 00:11:46,440 --> 00:11:47,750 A couple of popular languages 336 00:11:48,440 --> 00:11:49,950 are cascading style sheets known 337 00:11:50,340 --> 00:11:51,620 as CSS or the extensible 338 00:11:51,930 --> 00:11:53,720 style sheet language known as XSL. 339 00:11:54,380 --> 00:11:55,050 We're going to look a little bit 340 00:11:55,320 --> 00:11:56,340 with XSL on a later video 341 00:11:57,060 --> 00:11:58,830 in the context of query in XML. 342 00:11:59,210 --> 00:12:01,170 We won't be covering CSS in this course. 343 00:12:01,670 --> 00:12:03,170 But let's just understand how these 344 00:12:03,410 --> 00:12:05,500 languages are used, what the basic structure is. 345 00:12:05,740 --> 00:12:06,900 So the idea is that 346 00:12:07,060 --> 00:12:08,040 we have an XML document 347 00:12:09,000 --> 00:12:09,930 and then we send it to 348 00:12:10,390 --> 00:12:13,570 an interpreter of CSS or 349 00:12:13,900 --> 00:12:14,310 XSL, but we also have to have 350 00:12:14,330 --> 00:12:16,200 the rules that we're going to use on that particular document. 351 00:12:17,140 --> 00:12:17,980 And the rules are going to do things 352 00:12:18,210 --> 00:12:19,340 like match patterns or add 353 00:12:20,230 --> 00:12:21,900 extra commands and once 354 00:12:22,120 --> 00:12:23,600 we send an XML document thorugh 355 00:12:23,640 --> 00:12:25,450 the interpreter we'll get an 356 00:12:25,680 --> 00:12:28,810 HTML document out and then we can render that document in the browser. 357 00:12:29,510 --> 00:12:30,610 Now, one thing I should mention is 358 00:12:30,730 --> 00:12:32,210 that we'll also check with the 359 00:12:32,350 --> 00:12:33,590 parser to make sure 360 00:12:33,870 --> 00:12:35,080 that the document is well formed 361 00:12:35,340 --> 00:12:37,440 as well before we translate it to HTML. 362 00:12:38,520 --> 00:12:40,520 To conclude, XML is a 363 00:12:40,610 --> 00:12:42,240 standard for data representation and exchange. 364 00:12:42,830 --> 00:12:44,260 It can also be thought of as a data model. 365 00:12:44,610 --> 00:12:45,720 Sort of a competitor to the 366 00:12:45,810 --> 00:12:47,840 relational model for structuring the data in one's application. 367 00:12:48,860 --> 00:12:49,780 It generally has a lot more 368 00:12:50,030 --> 00:12:50,960 flexibility than the relational 369 00:12:51,490 --> 00:12:53,170 model, which can be a plus and a minus, actually. 370 00:12:54,440 --> 00:12:55,940 In this video we covered the 371 00:12:56,210 --> 00:12:57,520 well formed XML, so, XML 372 00:12:58,010 --> 00:12:59,330 that adheres to basic structural requirements, 373 00:13:00,300 --> 00:13:01,180 in the next video we will 374 00:13:01,320 --> 00:13:02,990 cover valid XML, where we 375 00:13:03,050 --> 00:13:04,070 actually do introduce a kind of 376 00:13:04,250 --> 00:13:05,660 schema for XML. 377 00:13:05,900 --> 00:13:07,310 The last thing I want to mention, is 378 00:13:07,450 --> 00:13:10,150 that the formal specification for XML is quite enormous. 379 00:13:10,720 --> 00:13:11,920 There are a lot of bells and whistles. 380 00:13:12,620 --> 00:13:13,530 We're going to cover, in these 381 00:13:13,760 --> 00:13:14,900 videos, the most important components 382 00:13:15,630 --> 00:13:16,900 for understanding anything XML.