Beginner Tutorial - 11
Beginner Tutorial - 11
2
00:00:03,509 --> 00:00:06,669
pleaded dario and we will proceed with the
3
00:00:06,669 --> 00:00:09,990
XML DOM okay so in the last video
4
00:00:09,990 --> 00:00:13,919
I am I showed you how I am
5
00:00:13,919 --> 00:00:17,000
we use and how we conferred an XML
6
00:00:17,000 --> 00:00:21,289
well 20 XML bomb object okay I am
7
00:00:21,289 --> 00:00:23,190
I'm gonna grab all I
8
00:00:23,190 --> 00:00:26,380
I am I'm gonna make a function to grab the
9
00:00:26,379 --> 00:00:29,599
come for the conversion okay to the DOM object
10
00:00:29,600 --> 00:00:33,050
and I'm callin at that function
11
00:00:33,049 --> 00:00:36,379
wanna call it a
12
00:00:36,380 --> 00:00:39,739
load XML
13
00:00:39,738 --> 00:00:46,738
doc
14
00:00:47,850 --> 00:00:49,359
K
15
00:00:49,359 --> 00:00:53,640
and here I'm gonna say the name I'm gonna give a parameter
16
00:00:53,640 --> 00:00:57,838
K to for us to use
17
00:00:57,838 --> 00:01:01,799
a or to give the name of the file that we want to load the XML file
18
00:01:01,799 --> 00:01:04,978
and down here I'm gonna close it
19
00:01:04,978 --> 00:01:08,379
okay so
20
00:01:08,379 --> 00:01:12,179
now and I'm going to do is I'll
21
00:01:12,180 --> 00:01:15,290
make sure you have about the code
22
00:01:15,290 --> 00:01:19,860
as the same my hair here okay a now after the function
23
00:01:19,859 --> 00:01:23,859
I'm going to show you how we can grab
24
00:01:23,859 --> 00:01:27,420
I whatever a element we want
25
00:01:27,420 --> 00:01:30,769
okay I am or data
26
00:01:30,769 --> 00:01:34,239
up an element we want from the XML file K
27
00:01:34,239 --> 00:01:37,818
I am yet to file is here
28
00:01:37,819 --> 00:01:40,819
is Dom XML I'm gonna grab this
29
00:01:40,819 --> 00:01:44,368
title here okay and output it in a
30
00:01:44,368 --> 00:01:48,009
and web page so to do that the first thing you have to do
31
00:01:48,009 --> 00:01:52,659
is create a parable I'm gonna called my period ball
32
00:01:52,659 --> 00:01:56,530
I am my
33
00:01:56,530 --> 00:02:01,040
now sorry gonna call the
34
00:02:01,040 --> 00:02:08,040
say XML doc and this is going to be
35
00:02:08,360 --> 00:02:11,620
equal to load
36
00:02:11,620 --> 00:02:15,840
XML doc and
37
00:02:15,840 --> 00:02:19,700
the parameter the name is going to be the name
38
00:02:19,699 --> 00:02:22,810
okay file their want to load
39
00:02:22,810 --> 00:02:25,890
which is Dom dot that smell okay
40
00:02:25,889 --> 00:02:29,029
now down here
41
00:02:29,030 --> 00:02:32,180
I'm gonna give now the variables going to be called
42
00:02:32,180 --> 00:02:35,950
txt equals to
43
00:02:35,949 --> 00:02:39,780
arm the XML
44
00:02:39,780 --> 00:02:43,090
XML
45
00:02:43,090 --> 00:02:46,519
doc dot get
46
00:02:46,519 --> 00:02:50,340
element by
47
00:02:50,340 --> 00:02:54,799
I am K name
48
00:02:54,799 --> 00:02:58,219
K an
49
00:02:58,219 --> 00:03:01,930
I'm going to type title to the tag name
50
00:03:01,930 --> 00:03:06,269
I want to grab this is the first one
51
00:03:06,269 --> 00:03:09,670
means the first one and child
52
00:03:09,669 --> 00:03:12,829
or
53
00:03:12,830 --> 00:03:16,099
child nodes as well
54
00:03:16,098 --> 00:03:20,289
first one K
55
00:03:20,289 --> 00:03:23,628
now if I come up down here
56
00:03:23,628 --> 00:03:27,158
and say document right
57
00:03:27,158 --> 00:03:32,829
and
58
00:03:32,830 --> 00:03:38,299
but say txt save this
59
00:03:38,299 --> 00:03:45,299
and I run this in Firefox mmm
60
00:03:45,840 --> 00:03:49,628
okay we have an error K
61
00:03:49,628 --> 00:03:56,628
here let's take it this input I have before
62
00:03:58,878 --> 00:04:00,590
okay
63
00:04:00,590 --> 00:04:06,170
okay in here note hip typed note
64
00:04:06,169 --> 00:04:09,519
value okay which is the Bailey up to node
65
00:04:09,520 --> 00:04:13,140
or the element and that's it
66
00:04:13,139 --> 00:04:16,479
now let's run this now
67
00:04:16,480 --> 00:04:19,870
hopefully it were and it will
68
00:04:19,870 --> 00:04:25,329
output it doesn't out but nothing yet
69
00:04:25,329 --> 00:04:29,539
I don't know why see okay you have a leader
70
00:04:29,540 --> 00:04:32,840
a little ever hear which is get element
71
00:04:32,839 --> 00:04:38,039
is not element is Allemands okay get elements by taking them
72
00:04:38,040 --> 00:04:41,520
title at chant notes and the No
73
00:04:41,519 --> 00:04:44,969
don't value document.write text and now
74
00:04:44,970 --> 00:04:48,360
it will work i render them for Fox
75
00:04:48,360 --> 00:04:52,379
and the output is everyday talent which is
76
00:04:52,379 --> 00:04:55,480
the title in the DOM XML here
77
00:04:55,480 --> 00:05:00,520
okay and obviously if we want to grab the Jetta
78
00:05:00,519 --> 00:05:04,629
the Lauren tees or whatever name is that I can
79
00:05:04,629 --> 00:05:08,100
I am also do their K
80
00:05:08,100 --> 00:05:11,700
what's going here
81
00:05:11,699 --> 00:05:14,969
and is that a title let's type the I'll for
82
00:05:14,970 --> 00:05:18,080
just this one here
83
00:05:18,079 --> 00:05:23,550
but save this and let's run this for Fox and their dates
84
00:05:23,550 --> 00:05:26,819
okay perfect so you see it that's a way that we can
85
00:05:26,819 --> 00:05:30,089
a grab with this build
86
00:05:30,089 --> 00:05:33,168
in function and Dom a
87
00:05:33,168 --> 00:05:36,560
get elements by tagname and
88
00:05:36,560 --> 00:05:40,509
I am grabbed values a and an XML file
89
00:05:40,509 --> 00:05:45,240
okay and output them we can also look through
90
00:05:45,240 --> 00:05:48,590
a instead of using directly I am
91
00:05:48,589 --> 00:05:53,639
the node value to get a specific value we can loop through
92
00:05:53,639 --> 00:05:57,389
all the values a in a.m.
93
00:05:57,389 --> 00:06:00,560
inside an element that s called offer
94
00:06:00,560 --> 00:06:03,910
so for example if I had more books here
95
00:06:03,910 --> 00:06:07,790
so let's copied this
96
00:06:07,790 --> 00:06:11,120
and that's based it
97
00:06:11,120 --> 00:06:14,250
on and let's put another one
98
00:06:14,250 --> 00:06:18,199
just that instead of this let's put here
99
00:06:18,199 --> 00:06:22,439
and book to
100
00:06:22,439 --> 00:06:26,478
sorry book 3
101
00:06:26,478 --> 00:06:29,949
an here book
102
00:06:29,949 --> 00:06:33,779
to K save this
103
00:06:33,779 --> 00:06:37,049
and I'm gonna make a loop to you output the
104
00:06:37,050 --> 00:06:40,439
this titel the second title and third title
105
00:06:40,439 --> 00:06:43,848
K so that's going here
106
00:06:43,848 --> 00:06:47,439
at delete this
107
00:06:47,439 --> 00:06:51,899
you need that and
108
00:06:51,899 --> 00:06:55,449
in here let's see axe
109
00:06:55,449 --> 00:06:59,740
equals to you ok XML
110
00:06:59,740 --> 00:07:06,680
doc cat
111
00:07:06,680 --> 00:07:09,860
element elements
112
00:07:09,860 --> 00:07:13,449
by hmm a
113
00:07:13,449 --> 00:07:19,259
tag name its
114
00:07:19,259 --> 00:07:23,849
title and now
115
00:07:23,850 --> 00:07:27,540
here I can make a loop for loop
116
00:07:27,540 --> 00:07:30,790
just going to be I equals
117
00:07:30,790 --> 00:07:33,910
see ru I is
118
00:07:33,910 --> 00:07:37,910
last then axe dot
119
00:07:37,910 --> 00:07:41,020
lang K
120
00:07:41,019 --> 00:07:44,699
arm and I plus plus
121
00:07:44,699 --> 00:07:48,469
K and I am
122
00:07:48,470 --> 00:07:51,580
let's open curly braces
123
00:07:51,579 --> 00:07:54,969
and here here
124
00:07:54,970 --> 00:08:01,970
let's say document document right
125
00:08:06,980 --> 00:08:10,610
X II child
126
00:08:10,610 --> 00:08:14,050
notes 0
127
00:08:14,050 --> 00:08:17,319
and arm
128
00:08:17,319 --> 00:08:22,230
node value my column
129
00:08:22,230 --> 00:08:26,379
and done here document right
130
00:08:26,379 --> 00:08:29,790
and its
131
00:08:29,790 --> 00:08:35,279
a but here line break and hopefully
132
00:08:35,279 --> 00:08:39,009
this lout but the three different
133
00:08:39,009 --> 00:08:45,019
a.m. title books okay let's run this
134
00:08:45,019 --> 00:08:49,710
approx and perfect there it is
135
00:08:49,710 --> 00:08:54,670
everyday Italian but to book 3 so you see this is a way also the you can use
136
00:08:54,669 --> 00:08:55,179
the
137
00:08:55,179 --> 00:08:58,989
for loop to loop through all the or whatever
138
00:08:58,990 --> 00:09:02,909
elements you want in your XML file okay and output them
139
00:09:02,909 --> 00:09:06,959
okay okay guys so this is all for this video
140
00:09:06,960 --> 00:09:10,139
and the next video I will show you I am
141
00:09:10,139 --> 00:09:13,870
how to also at change at
142
00:09:13,870 --> 00:09:17,750
notes or change the values inside our XML
143
00:09:17,750 --> 00:09:20,799
and I'm Dom okay file
144
00:09:20,799 --> 00:09:22,500
so see you guys next video by