Join Joe Marini for an in-depth discussion in this video Describing information with XML, part of XML Essential Training.
- View Offline
Recall earlier that I said that, one of the main things XML is used for is to structure and describe information. So let's take a look at an example of that now. To illustrate this example, we'll consider some information that you typically find on a business card, such as a person's name, various phone numbers, maybe an email address. And there might some additional information on a business card, but just to keep the example simple, let's just say that this is some fairly common data. Okay, so which one is my work number? Well, you don't know, right? Which is why business cards usually also provide things like labels that clearly identify what the information needs.
So once the labels are visible, you can say, oh okay, the work number is the 800 number. And there are other numbers on there that mean different things. But those labels are there to describe the information that's on the business card. And this is an example of what XML does. It applies description and structure to the data that you're working with. So, if we were to take the same example and look at it in XML, we might be able to structure it in a certain way. So for example, I might have a tag called BusinessCard.
And the BusinessCard tag might be the root tag that holds the other data like so, for example, a name. And then there might be various tags like phone. And the phone tag might have an attribute that describes what kind of phone it is, home, work, mobile. And then there's a tag for email. Now, you might be looking at this and saying, wait a second. BusinessCard tag? Phone tag? I've never seen anything like this. And you're right. Now if there was a BusinessCard XML tag set existing that I could use to solve this data problem, I could go ahead and use it.
Now imagine for a moment that there was no such XML standard. And the truth is I don't know if there is or if there isn't. But I decide to sit down and create my own XML language called BusinessCard. Remember, the X in XML stands for eXtensible. So, if you have a particular data related problem or task, and you want to use XML to solve it, you can either use an existing XML language, if there is one. But if there isn't one, just make one up. So I sat down and said, well, if I'm going to structure a business card in XML, I'll probably need a root tag, and I'll just call that BusinessCard.
And then I made up the tag's name and phone and email. And if I wanted to add other tags, like address, and so on, I could go ahead and do that. Now, once I've done this, once I've collected this data here in XML, I can now take this XML data and give it to any other XML aware program. And that program can then parse and extract data from this business card. Now that program may not know what a business card is, or what the various tags mean, but because XML is an open text-based standard, any application that can read XML would be at least able to extract the data from the business card.
Alright, so now that we understand how to describe information, let's talk a little bit about what some of the advantages and disadvantages of XML are.
- What is XML?
- The advantages and drawbacks of XML
- Proper XML syntax
- Working with namespaces
- Styling XML tags with CSS
- Extracting and manipulating data
- Taking XPath and XSLT for a spin
- Creating document type definitions and schema definitions