Download 9 Page Layout
Transcript
Spry Data Sets CosmoFarmer’s IT staff could decide to come up with their own XML format to store this data. In this case, the same information might be written in XML like this: <plants> <plant> <name latin="Pueraria lobata">Kudzu</name> <description>Kudzu is a climbing, woody or semi-woody, perennial vine capable of reaching heights of 66-98 ft, but also scrambles extensively over lower vegetation.</description> <area>1200</area> <image>images/kudzu.jpg</image> </plant> </plants> Kind of like HTML, right? But with a completely different set of tags. This new markup makes the meaning of each chunk of information clearer. You can easily tell that this data describes a plant (the <plant> tag) with a regular name, a Latin name, and so on. In a nutshell, that’s what XML offers: tags that meaningfully identify the information inside them. Rules of the Road Because XML is intended to be an easy way to exchange data between different computers, operating systems, programs, institutions, and people, it has some fairly strict requirements to ensure that everyone’s playing by the same rules. If you’ve done your fair share of writing raw HTML code, much of this will be familiar to you (see page 6). In fact, if you’ve written XHTML code (see page 9), you’ve already been writing XML. XHTML is an XML version of HTML that just has a few more rules than plain old HTML. • Every XML document must have a single “root” element. A root element is a tag that surrounds all other tags in a document, and appears only once in a document. In an XHTML (and an HTML) document, this tag is the <html> tag. In the CosmoFarmer XML format introduced above, this tag is <plants>. If you’re creating your own XML-formatted file, you can make this root element whatever you want: <events>, <employees>, and so on. It makes sense for this tag to describe whatever content you’re storing inside the file. • All tags must be nested properly, with no overlapping tags. This rule works just as it does in HTML. You can’t have code like this: <b><i>Bold and italics</b> </ i>. Since the opening <i> tag appears after the opening <b> tag, its closing tag—</i>—must appear before (or inside of) the closing <b> tag, like this: <b><i>Bold and italics</i></b>. • All tags must have both an opening and closing tag, or be self-closing. In HTML, a paragraph of text is indicated by both an opening <p> and a closing </p>. Some HTML tags, however, don’t hold content, like the <img> tag or the line break (<br>) tag. The XML version of these tags include a forward slash at the end of the tag, like this: <br />. This type of tag is called an empty element. Chapter 12: Spry 479