1
00:00:00,330 --> 00:00:03,160
We have most of the podcast
stored locally.

2
00:00:03,160 --> 00:00:08,620
That means if a new episode comes out we
have to update the XML data ourselves.

3
00:00:08,620 --> 00:00:13,180
Yes, you could just link to the RSS
feed like we did with full stack radio.

4
00:00:13,180 --> 00:00:16,190
But this is a lot slower to process and,
of course,

5
00:00:16,190 --> 00:00:18,490
this course is about taking control.

6
00:00:18,490 --> 00:00:23,278
Let's find out what it takes to
control the XML data with PHP.

7
00:00:23,278 --> 00:00:25,640
Create another file in the inc directory.

8
00:00:28,160 --> 00:00:31,959
We'll name this one write_xml.

9
00:00:36,081 --> 00:00:41,340
We'll start by loading the podcast file
we wish to modify into an XML object.

10
00:00:54,004 --> 00:00:57,237
We'll be using the data
from the add_episode form.

11
00:01:21,815 --> 00:01:24,640
Simplexml_load_file and our file.

12
00:01:30,423 --> 00:01:33,233
We want to add an additional item.

13
00:01:33,233 --> 00:01:37,940
So, we're going to call the add
child method on the XML channel.

14
00:01:48,697 --> 00:01:49,197
AddChild('item').

15
00:01:53,170 --> 00:01:55,210
Then we can add our child details.

16
00:02:30,732 --> 00:02:34,701
I'm going to create a new date
object from the form input so

17
00:02:34,701 --> 00:02:36,810
that I can format it properly.

18
00:03:04,130 --> 00:03:05,483
Now, we can add the publication date.

19
00:03:15,840 --> 00:03:22,209
Date -> format, the day name,

20
00:03:22,209 --> 00:03:27,671
day, month, year, hour.

21
00:03:34,918 --> 00:03:39,210
And then for the description,
I'm going to copy the title again.

22
00:03:50,500 --> 00:03:54,010
Let's write out what we have so far so
we can preview this in the browser.

23
00:04:09,180 --> 00:04:12,110
We can use the method asXML.

24
00:04:17,481 --> 00:04:22,695
Simple XML doesn't really handle
making the XML pretty or easy to read.

25
00:04:22,695 --> 00:04:24,815
There are packages that can do this.

26
00:04:24,815 --> 00:04:27,695
But we aren't really going to be
looking at the code itself, so

27
00:04:27,695 --> 00:04:29,015
it doesn't really matter.

28
00:04:29,015 --> 00:04:31,095
It doesn't need line
breaks to be valid XML.

29
00:04:31,095 --> 00:04:33,565
But to make this a little easier for

30
00:04:33,565 --> 00:04:36,665
us to read right now,
let's add our own line breaks.

31
00:04:46,832 --> 00:04:48,430
Anywhere the tags meet.

32
00:04:51,780 --> 00:04:53,360
We're going to add a line break.

33
00:04:56,861 --> 00:04:58,590
Now, let's preview this in a browser.

34
00:05:07,556 --> 00:05:10,130
Let's pull the latest
episode of Educate Yourself.

35
00:05:13,161 --> 00:05:15,495
Add episode.

36
00:05:15,495 --> 00:05:18,910
Choose the Educate Yourself.

37
00:05:21,758 --> 00:05:23,170
And we'll enter the details.

38
00:06:05,130 --> 00:06:08,674
Great, as you can see our
new episode was added.

39
00:06:08,674 --> 00:06:11,760
But there are a few more bits of
information that I want to add.

40
00:06:12,970 --> 00:06:17,120
XML offers many additional options for
adding details.

41
00:06:17,120 --> 00:06:19,470
I'm going to demonstrate one of them.

42
00:06:19,470 --> 00:06:24,285
As you see in the previous episodes, there
are some tags that start with iTunes and

43
00:06:24,285 --> 00:06:26,320
a colon before the name of the tag.

44
00:06:26,320 --> 00:06:28,848
This is the XML way of namespacing.

45
00:06:28,848 --> 00:06:30,240
At the top of the file.

46
00:06:32,640 --> 00:06:36,300
We see these xmlns for namespace.

47
00:06:47,740 --> 00:06:50,370
And here's our iTunes namespace.

48
00:06:50,370 --> 00:06:53,150
We'll copy this and go back to workspaces.

49
00:07:01,568 --> 00:07:02,230
Itunes.

50
00:07:10,881 --> 00:07:12,020
And we just need this URL.

51
00:07:13,460 --> 00:07:18,147
Then we can add the namespace as the third
parameter of the addChild method.

52
00:07:51,457 --> 00:07:55,660
We'll copy this line for
summary, explicit, and duration.

53
00:08:18,959 --> 00:08:21,460
Now, let's preview these
changes in the browser again.

54
00:08:31,041 --> 00:08:33,890
Now, we see the iTunes
information as well.

55
00:08:33,890 --> 00:08:35,510
And we're ready to write this to a file.

56
00:08:39,883 --> 00:08:41,550
Let's comment out this display.

57
00:08:46,709 --> 00:08:50,273
Instead of echoing the asXML,

58
00:08:50,273 --> 00:08:55,350
we can call xml->asXML and pass the file.

59
00:08:58,046 --> 00:09:01,800
We'll then redirect.

60
00:09:06,020 --> 00:09:07,757
To podcasts.

61
00:09:07,757 --> 00:09:10,150
Back in the browser
let's resubmit the form.

62
00:09:21,060 --> 00:09:25,710
Since these are random, we can
refresh until we see the new episode.

63
00:09:25,710 --> 00:09:29,010
We could also specify a specific
episode if we wanted too.

