- [Instructor] In this video, we want to take
a look at a different type of formatting.
In our last video, we took a look at JSON formatting.
Now we're going to take a look at XML.
That's eXtensible Markup Language.
Extensible means that we can extend its abilities
by adding our own tags.
And when we think of a markup language,
we might think of HTML used for web development,
and we can add the tags to the HTML of a web page
to do things like italicize or bold text.
Oftentimes when I'm writing a blog post,
I'll use HTML to set the type of header that I want
for a piece of text.
For example, let's say that I wanted a type four header.
To do that, I can enter a less than and a greater than sign
with h4 for header four in the middle.
I do that just before my type four header,
and then after the header text,
I enter that again, except this time
I put a forward slash before the h4,
this says that I'm ending my type four header.
That's one of the things we need to understand about tags.
There's going to be a start tag and an end tag.
And a markup language can use those tags for formatting,
but as we said, an eXtensible Markup Language
means that we can create our own tags.
Now let's take a look at some of the pieces and parts
that make up this XML format.
And to work through this,
let's take a look at a very simple piece of XML code
that you see here on screen.
And we're going to break this down line by line,
but the first thing I want to draw your attention to
is the XML declaration.
And the declaration, that's what's at the top.
You see it blinking there on screen,
and this is the first line of an XML document.
If we use it, we don't have to use it, this is optional.
If we do use it, we're saying, here's the type
of information that's contained in this XML document.
And as you can see on the screen it says,
here is the version of XML that we're using.
We're going to say what type of encoding that we're using,
and here we're saying that we're using version 1.0
and the encoding is UTF-8.
That's an eight bit encoding scheme
that lets us represent all of our Unicode characters.
And there's something else that you rarely see
but it's in the documentation.
So I wanted to mention it, it's standalone.
You can say standalone equals yes in quotes,
or standalone equals no in quotes.
Here's what that's all about.
There's something called a DTD.
A document type definition, and a DTD defines the structure
of an XML document and it says what components
it's allowed to have,
and we can encode this DTD directly in the XML file.
If we do that, then standalone equals yes,
if it's external to the file, then standalone equals no.
But again, in the real world we would rarely
if ever use standalone.
So what we see on screen is very typical
of an XML declaration.
Now let's take a look at another component of XML.
This one is a tag and we've already mentioned a tag.
A tag is a string of text that's enclosed between
a less than sign and a great event sign.
For example, name here on screen.
Notice I've got a tag of voice VLAN
and it's enclosed in the name tag.
The tag starts with name in those brackets if you will,
between the less than and greater than signs.
And it ends with naming those brackets except this time
there's a forward slash in front of it.
So we've got a start tag and end in tag.
And here's another one, we've got a VLAN tag,
but notice that VLAN tag has some extra stuff after it.
It says voice equals 300 in quotes.
We'll talk about that in a moment,
but realize this is just some extra information.
This is a VLAN tag, so we've got a tag of VLAN,
and inside we have a name tag.
And we've got a comment, that we'll discuss in a few moments
and then our tag ends with a forward slash VLAN
inside of those less than and greater than brackets.
That's our definition of a tag.
It's a string of text inside those less than
and greater than signs.
And we have both a start tag and an end tag
in between those tags, we have data.
For example, voice underscore VLAN, that's data
contained in the name tag.
Now let's talk more specifically about the data
that's inside of those tags.
We call that data, an element.
For example, voice underscore VLAN, that's an element.
That's the data that's located between
the start and end tags.
And we can have elements within elements.
In fact, we can go several layers
deep in this hierarchical nesting if we need to.
Now let's take a look at the VLAN start tag
where it says in quotes, voice equals 300.
What is going on there?
Well, that is an attribute.
The voice equals 300 in quotes is an attribute.
And an attribute is going to give us more detail
about an element.
And the value of this attribute is 300,
and it has to be in quotes, and it is.
And the next piece of XML code
I want you to understand, is a comment.
Oftentimes we want to self document what things mean
when we're creating a configuration file
or in this case an XML file.
And I've added a comment to our XML file.
Let me highlight it for you.
I'm saying this voice VLAN traffic
is treated with high priority.
But notice that string of text is enclosed between
a less than sign followed by an exclamation point,
followed by two dashes.
That's at the beginning and then at the end,
we have two dashes and a greater than sign.
That's the way that we write a comment.
And a comment like we said,
is used to provide documentation within a file.
So we can better interpret what's going on.
We can remind ourselves what we were thinking
when we wrote this code.
Or if somebody else is looking at our code,
they could understand better what we were thinking.
And it's much like a description,
that you might give in Cisco iOS for an interface.
But this line is comment, it is not executed.
And the way we set this up,
is we begin a comment with a less than sign
followed by an exclamation point, followed by two dashes.
Then when we're done, we end it with two dashes
and a greater than sign.
And that's an overview of the basic pieces of parts
of XML that we might be using
to send some data down to a network controller,
from an application.
But before we wrap up this video,
I'd really like to contrast XML with JSON formatting
that we saw in the previous video.
And I found a converter on the web,
that lets you enter a code in either JASON or XML format
and it converts between the two.
And there are several converters out there,
but here's one that I came across,
and I've pasted in the XML code
that we've been going through.
Let's click on this right arrow
to convert between XML and JSON.
Let's click the right arrow,
and here's what it looks like in JSON format.
Notice that we have this object.
And the object is a name value pair.
The name is VLAN, but notice the value,
the value is another object.
We've got one object nested within another object.
And this other nested object contains
a name of hyphened voice and a value of 300,
and we've got another name value pair with a name of name,
and the value of voice underscore VLAN.
And by the way, XML format is a format
that you can open up in a web browser.
And your experience may vary depending
on which particular web browser you're using,
or how your XML was constructed.
But in my case, I saved out our sample code to an XML file
and I opened it up inside of the Safari web browser.
And this is what it looks like.
It simply says, voice underscore VLAN.
Notice that it didn't show the comment,
it didn't show the attribute of voice equals 300,
it just showed voice underscore VLAN.
And that's a look at XML,
the eXtensible Markup Language format.