- [Instructor] Recall earlier that I said that one of the main purposes of XML is to structure and describe information. We're going to take a look at an example of that now. To illustrate this example, let's consider some information that you would typically find on a business card, such as a person's name, various phone numbers, and maybe an email address, and there might be some additional information on a business card, like a company name, but just to keep the example simple, let's just agree that this is some fairly common data you'd find on a business card. Alright, so, which one's my work phone number? Well, you don't know, right, which is why business cards usually also provide things like labels that clearly identify what the information means.
So once the labels are visible you can say, okay, the work number is the 800 one, and so on. 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 business card tag might be the root tag that holds other data, like for example, the name.
And there might be various tags like phone, and the phone tag might have an attribute that describes what kind of phone it is, whether home or work or mobile, and there might be a tag for email. Now, you might be looking at this and saying, well, wait a second, business card tag, phone tag, I've never seen anything like this, and you're right. Now, if there was a business card XML tag set existing already that I could use to solve this data problem, I could go ahead and use it, but imagine for a moment that there was no such XML standard and the truth is I don't know if there is or isn't, but I could decide to sit down and create my own XML language called business card.
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 could either use an existing XML language if there is one, or you could 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 business card, and then I made up the tags name and phone and email, and if I wanted to add other tags, like address, I could do that. Now, once I've done this, once I've collected this data here in XML, I can now take this data and give it to any other XML aware program.
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 at least be able to parse this data from the business card file.
- What is XML?
- Advantages and drawbacks of XML
- Proper XML syntax
- Working with XML namespaces
- Styling XML tags
- Discovering and creating document content
- Manipulating XML content using XPath and XSLT
- Document type definitions and XML schema