Java Reference
In-Depth Information
LISTING 19.1
Continued
14: url=”http://mp3.cadenhead.org/3132.mp3” />
15: </item>
16: <item>
17: <title>Eliot Spitzer Files UDRP to Take EliotSpitzer.Com</title>
18: <link>http://www.cadenhead.org/workbench/news/3130</link>
19: <pubDate>Thu, 22 Feb 2007 18:02:53 -0500</pubDate>
20: <guid isPermaLink=”false”>tag:cadenhead.org,2007:weblog.3130</guid>
21: </item>
22: <item>
23: <title>Fuzzy Zoeller Sues Over Libelous Wikipedia Page</title>
24: <link>http://www.cadenhead.org/workbench/news/3129</link>
25: <pubDate>Thu, 22 Feb 2007 13:48:45 -0500</pubDate>
26: <guid isPermaLink=”false”>tag:cadenhead.org,2007:weblog.3129</guid>
27: </item>
28: </channel>
29: </rss>
Enter this text using a word processor or text editor and save it as plain text under the
name workbench.rss . (You can also download a copy of it from the topic's website at
http://www.java21days.com on the Day 19 page.)
Can you tell what the data represents? Although the ?xml tag at the top might be indeci-
pherable, the rest is clearly a website database of some kind.
The ?xml tag in the first line of the file has a version attribute with a value of 1.0 and
an encoding attribute of “utf-8” . This establishes that the file follows the rules of XML
1.0 and is encoded with the UTF-8 character set.
19
Data in XML is surrounded by tag elements that describe the data. Opening tags begin
with a “<” character followed by the name of the tag and a “>” character. Closing tags
begin with the “</” characters followed by a name and a “>” character. In Listing 19.1,
for example, <item> on line 8 is an opening tag, and </item> on line 15 is a closing tag.
Everything within those tags is considered to be the value of that element.
Elements can be nested within other elements, creating a hierarchy of XML data that
establishes relationships within that data. In Listing 19.1, everything in lines 9-14 is
related; each element defines something about the same website item.
Elements also can include attributes, which are made up of data that supplements the rest
of the data associated with the element. Attributes are defined within an opening tag ele-
ment. The name of an attribute is followed by an equal sign and text within quotation
marks.
 
Search WWH ::




Custom Search