- Shopping Bag ( 0 items )
Well-formed XML is XML that meets certain grammatical rules outlined in the XML 1.0 specification.
You will learn:
If you have Internet Explorer 5, you may find it useful to save some of the examples in this chapter on your hard drive, and view the results in the browser. If you don't have IE5, some of the examples will have screenshots to show what the end results look like.
<name> <first>John</first> <middle>Fitzgerald Johansen</middle> <last>Doe</last> </name>
The words between the < and > characters are XML tags. The information in our document (our data) is contained within the various tags that constitute the markup of the document. This makes it easy to distinguish the information in the document from the markup.
As you can see, the tags are paired together, so that any opening tag also has a closing tag. In XML parlance, these are called start-tags and end-tags. The end-tags are the same as the start-tags, except that they have a "/" right after the opening < character.
In this regard, XML tags work the same as start-tags and end-tags do in HTML. For example, you would create an HTML paragraph like this:
<P>This is a paragraph.</P>
As you can see, there is a <P> start-tag, and a </P> end-tag, just like we use for XML.
All of the information from the start of a start-tag to the end of an end-tag, and including everything in between, is called an element. So:
Whenever you come across a strange-looking term like PCDATA, it's usually a good bet the term is inherited from SGML. Because XML is a subset of SGML, there are a lot of these inherited terms.
The whole document, starting at <name> and ending at </name>, is also an element, which happens to include other elements. (And, in this case, the element is called the root element, which we'll be talking about later.)
To put this new-found knowledge into action, let's create an example that contains more information than just a name.
In Chapter 1, we learned that XML is hierarchical in nature; information is structured like a tree, with parent/child relationships. This means that we'll have to arrange our CD information in a tree structure as well.
1. Since this is a CD, we'll need to capture information like the artist, title, and date released, as well as the genre of music. We'll also need information about each song on the CD, such as the title and length. And, since Weird Al is famous for his parodies, we'll include information about what song (if any) this one is a parody of.
Here's the hierarchy we'll be creating...
...Some of these elements, like <artist>, will appear only once; others, like <song>, will appear multiple times in the document. Also, some will have PCDATA only, while some will include their information as child elements instead. For example, the <artist> element will contain PCDATA for the title, whereas the <song> element won't contain any PCDATA of its own, but will contain child elements that further break down the information.
2. With this in mind, we're now ready to start entering XML. If you have Internet Explorer 5 installed on your machine, type the following into Notepad, and save it to your hard drive as cd.xml...
Posted December 5, 2001
I bought this book at local B&N bookstore. The authors need to update this book. Also, the authors spend a whole page to explain a thing that could be explained in one or two sentences. If they update and bring it up to the latest W3C recommentatins, it should be great.Was this review helpful? Yes NoThank you for your feedback. Report this reviewThank you, this review has been flagged.