Cool graphics in XML
The entire universe is going XML. Everywhere you turn, somebody is turning something into XML. This is, as Ms. Stewart is wont to say, "A good thing."
The beauty of XML is it provides a whole new way of structuring "stuff" that goes beyond just organizing data. With XML, data is imbued with meaning and purpose . . . wait a minute, that implicitly makes it information. Cool.
Today, we'll look at one of the latest and most promising applications of XML - Scalable Vector Graphics (SVG).
SVG is currently a W3C Candidate Recommendation (see www.w3.org/TR/SVG/) under the name "Scalable Vector Graphics (SVG) 1.0 Specification" and dated Nov. 2, 2000. The abstract of the specification summarizes SVG as "a language for describing two-dimensional vector and mixed vector/raster graphics in XML."
Sounds pretty dry, doesn't it? In fact, SVG is terribly exciting if you're inclined toward trying whiz-bang graphics on the Web. If you're not, SVG is cool anyway.
The reason for such coolness is what SVG can do. Quoting the W3C specification: "SVG allows for three types of graphic objects: vector graphic shapes (e.g., paths consisting of straight lines and curves), images and text. Graphical objects can be grouped, styled, transformed and composited into previously rendered objects. The feature set includes nested transformations, clipping paths, alpha masks, filter effects and template objects. SVG drawings can be interactive and dynamic. Animations can be defined and triggered declaratively (that is, by embedding SVG animation elements in SVG content) or via scripting."
SVG has a document object model that provides access to all elements, attributes and properties in an SVG graphic document. There are also event handlers such as the ever-popular "onmouseover" and "onclick."
SVG's MIME type will be "image/svg+xml" when the W3C registers it as such - apparently around the time when SVG is approved as a W3C recommendation (no date set). The specification also recommends that SVG files should have the extension ".svg" (all lower case) on all platforms.
OK, enough of the dry stuff. Let's cut code! Here's an example of an SVG document:
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20000303 Stylable//EN" "http://www.w3.org/TR/2000/03/WD-SVG-20000303/DTD/svg-20000303-stylable.dtd">
<svg xml:space="preserve" width= "3in" height="3in">
<text style="fill:blue;" y="15">Gearhead was here.</text> <text font-family="serif" font-size="12pt" fill="black" x="0" y="0" transform="rotate(-90) translate(-100, 180) scale(1.5, 1)">
To see what this code does, install the Adobe SVG viewer (it's free from Adobe) in Internet Explorer. Next, put the above code in a file called test1.svg and load it into your browser.
Next week, we'll explain what's going on. Revelations to firstname.lastname@example.org.
Comments and suggestions to email@example.com.
The place to discuss Gibbs's columns.
Check out this week's edition of
Backspin for more musings from Gibbs.