00:00Alrighty, so I did my due diligence, and we have your three screens open up at the same
00:04time.
00:05We first have here our domain, LearnXMLNow.com, as it is at this stage while we're creating
00:10a course.
00:11We have our domain itself, our server, which supports PHP.
00:16And we have our editor, Smoltron, and I'm using Cyberduck, because it's a really great
00:21editor.
00:22Simple while I'm on a Mac, but you should work with whatever editor you feel like working
00:26with.
00:27If you find it hard to find an editor for this, contact us, and we'll be more than happy
00:33to help you in our commuted forums, on our Facebook chat, on pages, and so on and so forth.
00:39So let's look at our PHP file and just take a peek and see what's inside of it right now.
00:43What's really nice about this editor is I could edit the PHP, and it will automatically,
00:47as soon as I save the file, update it back onto the server so we could see live updates.
00:52Alright, so we did our intro to this, and now we're ready to start scripting some
00:56PHP.
00:57Now, like I said in our previous video, there's a lot of different ways of working
01:01with XML, and actually one of the most simple ways of doing it in PHP is a library that's
01:07called SimpleXML, and I want to show you how SimpleXML works.
01:13Now there's really two main ways how you'd be working with XML on the server side.
01:18You might be generating the XML yourself, and then trying to output that to the user,
01:24and you might be just wanting to fetch an XML that already exists to fetch information
01:28out of it.
01:29Both are legitimate.
01:30So let's look at the first tab and the second tab at the same time.
01:34First of all, let's imagine that we want to create an XML on our own, and let's
01:37imagine that we had a string that was that XML that we wanted.
01:41So let's create that string.
01:42So first of all, this is how we create a variable in PHP.
01:47If you don't know PHP, notice how we have it with this dollar sign.
01:50That's our definition of our variable.
01:52Without it, we would get into trouble.
01:55And I'm going to create my little sample XML.
01:57It's going to be very, very rudimentary, and I'm just going to have here some code
02:01that says Hello World, and I'm ready to do something, right?
02:07So first of all, I have a string.
02:08Now I really want to convert that into an XML so I could work with it.
02:13The way I convert it into a SimpleXML in PHP is really, really simple, so I'm going
02:17to create a variable, I'm going to call it SimpleSM or SX for SimpleXML, and I'm
02:23going to create a new SimpleXML element, and I'm going to send into it that string
02:31that we just created.
02:32Now that string could have came from anywhere, but really it's just a string,
02:37any string.
02:38Now obviously if I run it right now because we're running in PHP, we wouldn't
02:40see anything, so I really have to output something.
02:42Now because I created a really, really basic element, if I just try to echo
02:47that simple element, if I just try to echo it the way it is, it's just going to output
02:52that child because it's a simple node and we're actually already inside of it when
02:57we name it, right, because we're in the root as soon as we call it.
03:00So if I save this and just refresh my browser, we're going to see that, I'm going
03:05to see that Hello World, and we have here our first native, simple XML application.
03:10We're ready to start building and creating dynamically new XMLs and integrate them into
03:17our PHP.
03:18Now let's see a really, a more, you know, a more realistic scenario where instead
03:23of this, we'd actually have that XML on a file waiting for us, which is actually
03:28this file.
03:29If we click on our edit so we could see what's in that file, we'll see that
03:32I created a very, very simple XML file.
03:34It has a header, it has a header, and it has a title.
03:38So let's see how we could actually fetch that file.
03:40Very, very simple with simple XML.
03:43There's a very simple function.
03:45All I have to do is set my XML, and I could then just call the function
03:49simple XML load file with these underlines, underlines, simple XML,
03:57underline load, underline file, and all that's left is for me to name the
04:01name of the file that I want to load.
04:03In my case, it's info.xml.
04:07And there you go.
04:08After line seven, we already have an XML, and we could test this out and see
04:11if that's really true, and I could just echo out, let's echo out, let's see
04:17in our XML, if I just echo out our XML, I'm not going to get anything
04:20because this is a complicated element, which really is going to take us to
04:24our next topic, which is going to be how to actually access information
04:28inside of the XML.
04:29So now we're not getting anything, but we definitely have that XML.
04:32Only when we're trying to output it, we're trying to output all this,
04:35so automatically it's just returning to us nothing or emptiness.
04:40So we just covered two really major stuff.
04:43One we saw how to create our own XML ourself.
04:46If this was a simple XML, which had only a line of text right here, we would
04:50output it, but it's not right now, and obviously our next step is to see how
04:53to go to travel through the XML.