Directory listing of http: uap.unnes.ac.id ebook biblebook Visual Basic 6 com & Library Books

20
C H A P T E R

Introducing XM L

U

nless yo u’ve been living o n the mo o n fo r the last several
years, yo u’ve undo ubtedly heard o f XML. It’s been hailed
as the future o f the Web, the fo undatio n fo r e-c o mmerc e and
the universal info rmatio n exc hange medium. In reality, XML
is merely a language used to desc ribe info rmatio n. In this c hapter, I’ll talk abo ut ho w to c reate an XML do c ument, ho w XML
wo rks with ADO, and why yo u might want to use XML in yo ur
applic atio ns.

Documenting Information
XML stands fo r Extensible Markup Language. It is part o f the
family o f languages develo ped fro m the Standardiz e d Ge ne ral
Purpo se Markup Language (SGML) that inc ludes the vario us
dialec ts o f Hype rTe xt Markup Language (HTML). These languages are used to desc ribe the struc ture o f a do c ument,
but no t the ac tual info rmatio n c o ntained in the do c ument.


Tagging information
All SGML languages, inc luding XML and HTML, are based o n
the c o nc ept o f tags. A tag is fo rmed by inserting a keywo rd
inside a less than and greater than symbo l pair ( ), suc h as
. Mo st tags wo rk in pairs suc h as and
, where the slash in fro nt o f the keywo rd is used
to mark the end o f that tag pair. In XML, this c o mbinatio n is
kno wn as an e le me nt. An element is used to mark the beginning and end o f a piec e o f info rmatio n. So metimes the info rmatio n is a single value, while at o ther times, it may be a
c o llec tio n o f elements.
Elements may be nested and the info rmatio n inside inherits
the c harac teristic s o f all o f the o uter elements. In HTML, fo r
instanc e, the tag identifies a blo c k o f text that sho uld be










In This Cha pter
W riting XML
do cuments
W o rking with XML
and ADO
Understanding the
benefits o f using XML









434


Part V ✦ The Impact of XM L

displayed in italic s, while the tag identifies a blo c k o f text that sho uld be displayed in bo ld. Thus, the fo llo wing HTML statement will display the text in bo th
bo ld and italic s:

You may display text in bold, italics, and both
bold and italics by using different combinations
of tags.

Adding attributes
SGML also allo ws yo u to refine the meaning o f a tag by inc luding o ne o r mo re
attributes inside the tag. Fo r instanc e, the tag is used in HTML to mark the
plac e where an image will be plac ed. Yet kno wing that an image is to be plac ed in a
do c ument isn’t suffic ient unless yo u kno w whic h image is to be used. This info rmatio n is spec ified with the SRC attribute. Thus, the fo llo wing tag wo uld display the
image CJ&Sam.JPG in a Web page:


Many tags suppo rt multiple attributes. The fo llo wing tag no t o nly spec ifies the
name o f the image to be displayed, but its height and width:




Grouping and formatting tags
Tags are gro uped to gether in a do c ument. With very few exc eptio ns, ho w the tags
are plac ed in the do c ument do esn’t matter, as lo ng as the o rder o f the tags remains
c o nstant. Thus, this set o f tags

You may display text in bold, italics, and both
bold and italics by using different combinations
of tags.
and this set o f tags

You may display text in
bold,
italics,
and both
bold and italics
by using different combinations of tags.
and even this set o f tags


You may display text in
bold,
italics,
and both
bold and italics
by using different combinations of tags.

Chapter 20 ✦ Introducing XM L

have exac tly the same meaning and will result in exac tly the same display. This
allo ws yo u to fo rmat yo ur do c uments and make them easy to read witho ut impac ting the meaning o f the info rmatio n c o ntained in the do c ument.

Using XM L tags
Unlike the HTML generic tags, whic h desc ribe ho w info rmatio n is to be fo rmatted in
a do c ument, XML uses meaningful tags that desc ribe the info rmatio n they c o ntain.
A tag c an refer to a single field o r to a c o llec tio n o f fields, whic h c o rrespo nd to a
field name in a table, a database table, o r a hierarc hic al view that is c o nstruc ted
fro m multiple database tables.
Note


Helpful hierarchies: Theoretically, it is possible to describe any com bination of
data in a hierarchy. In fact, som e of the earliest databases, such as IBM’s
Inform ation Managem ent System (IMS), w ere based on a hierarchical data m odel.
When extracting data from a database to send to another application, it is often
useful to arrange it as a hierarchy. This elim inates redundant inform ation and
m akes it easier for the receiving application to reform at the data to fit its ow n
database structures.

A Simple XM L document
Figure 20-1 sho ws a diagram o f my family. It desc ribes the family name (Freeze), the
father (me), the mo ther (Jill), o ur c hildren (Christo pher and Samantha), and o ur
pets (Ko ko mo , Pixel, Terry, Cali, Dusty and Raymo nd).

Figure 20-1: My fam ily

435

436

Part V ✦ The Impact of XM L


Listing 20-1 c o ntains the SQL statements that wo uld c reate a database to ho ld this
info rmatio n. The database c o nsists o f fo ur tables: o ne with the family name, o ne
with info rmatio n abo ut the parents, ano ther with the family’s c hildren, and a fo urth
with info rmatio n abo ut the family’s pets.

Listing 20-1: A family database
Create Table Family (
Name Char(32))
Create Table Parents (
Name Char(32),
Parent Char(32),
Type Char(32))
Create Table Children (
Name Char(32),
Child Char(32),
Type Char(32))
Create Table Pets (
Name Char(32),
Pet Char(32),

Type Char(32))

Yo u c an also easily translate this info rmatio n into an XML do c ument ( see Listing
20-2) . No tic e that the datab ase tab les had to flatten the info rmatio n to fit into
three distinc t tab les, while the XML do c ument maintained the o riginal hierarc hic al struc ture.

Listing 20-2: An XM L document for the Freeze family


Freeze

Wayne
Jill


Christopher
Samantha


Kokomo

Pixel

Chapter 20 ✦ Introducing XM L

Terry
Cali
Dusty
Raymond



On the
CD-ROM

You can find the FAMILY.XML docum ent as \VB6DB\Chapter20\XML\FAMILY.XML on the CD-ROM.

The XML tags are used either to identify a single item, suc h as the name o f the
father o r mo ther, o r to identify a c o llec tio n o f tags that are lo gic ally gro uped
to gether, suc h as the c hildren o r pets.
So me o f the latest generatio n o f Web bro wsers, suc h as Internet Explo rer 5.0, c an

display XML files direc tly (see Figure 20-2). If yo u lo o k at Figure 20-2 c arefully, yo u’ll
see a minus sign ( - ) in fro nt o f the , , , and
tags, in additio n to the raw HTML. By c lic king o n the minus sign next to a tag, yo u
c an hide all o f the tags belo w it in the hierarc hy. The minus sign will c hange to a
plus sign (+), whic h yo u c an c lic k o n to sho w the tags again.

Figure 20-2: View ing XML data in Internet Explorer 5.0

437

438

Part V ✦ The Impact of XM L

XM L attributes
Ano ther way to inc lude info rmatio n in an XML do c ument is to use attributes. Like
element names, yo u determine whic h attributes yo u want to inc lude in the do c ument. I’ve taken the XML do c ument fro m Listing 20-2 and rewritten it to mo ve the
info rmatio n abo ut the type o f family member to an attribute within an element, as
sho wn in Listing 20-3.


Listing 20-3: An XM L document for the Freeze family


Wayne
Jill
Christopher
Samantha
Kokomo
Pixel
Terry
Cali
Dusty
Raymond


Using attributes lets yo u inc lude mo re info rmatio n in a single element. The do wnside is that it makes the do c ument mo re c o mplic ated to read; it may also hide so me
hierarc hy info rmatio n.
Fo r the mo st part, yo u sho uld use attributes to ho ld info rmatio n abo ut yo ur data.
Fo r example, the fo llo wing element uses the attribute Currency to desc ribe the
type o f c urrenc y used in the value fo r LISTPRICE. This is a go o d example o f using
attributes to c larify the info rmatio n fo r a partic ular data value.

29.99
Tip

Extendable elements: If you’re not sure w hether to code a value as an elem ent or
an attribute, you should probably code the value as an elem ent. This approach is
m ore flexible, w hich is im portant if you plan to include new elem ents and
attributes in the future.

Chapter 20 ✦ Introducing XM L

Writing XM L Documents
The rules fo r XML are fairly straightfo rward, and if yo u want, yo u c an c reate yo ur
XML do c uments in any o ld text edito r, inc luding No tepad. Ho wever, fo r the mo st
part, yo u sho uld use an alternate way to lo ad a file. Pro bably the best way is to
write a pro gram that generates the do c ument fo r yo u. By do ing this yo u c an ensure
that the do c ument is generated pro perly. See Chapter 21 fo r o ne metho d yo u might
use in Visual Basic .
Note

Extensive XM L: I highly recom m end the XML Bible by Elliotte Rusty Harold, published by IDG Books. This w ell-w ritten book goes into all of the details you should
know before you build an XML-based application.

Creating an XM L document
At the to p o f an XML do c ument is a header tag, whic h desc ribes info rmatio n abo ut
the do c ument (see Listing 20-4). Typic ally, all yo u will c o de is the versio n level,
tho ugh the XML standard defines several o ther attributes that yo u may want to
inc lude.

Listing 20-4: A minimal XM L document




Fo llo wing the header tag is the ro o t level element. Every XML do c ument is a hierarc hy, with o ne and o nly o ne ro o t element. In Listing 20-4, the ro o t level element is
and , while in Listing 20-2 the ro o t
level element is and .

Identifying XM L elements
Unlike HTML, yo u must c reate the XML elements yo u use in yo ur do c ument. Fo r
instanc e, I c reated the fo llo wing element to identify my so n:

Christopher

439

440

Part V ✦ The Impact of XM L

The tag marks the beginning o f a blo c k o f data, while the tag marks
the end o f the tag. Yo u c an nest pairs o f tags within eac h o ther, like this:


Christopher
Samantha

The tag marks the c o llec tio n o f elements that c o mprises the c hildren in
my family. Elements c an and sho uld be nested to desc ribe gro ups o f data. A gro up o f
data might be so mething as simple as identifying a rec o rd, a c o llec tio n o f rec o rds, o r
a table.
The fo llo wing element


c an be written as


In this c ase, it means that there is no info rmatio n asso c iated with that partic ular
element.
In o rder to be c o nsidered a well-fo rmed XML do c ument, the start and sto p tags
must no t o verlap. They need to be c lo sed in the reverse o rder in whic h they were
o pened. The fo llo wing statement is legal in HTML, but will c ause an erro r in XML:

Hi Jill
Thus, yo u need to rewrite the statement as fo llo ws:

Hi Jill

Creating XSL Style Sheets
The Extensible Style Sheet Language (XSL) is used to fo rmat an XML do c ument. An
XSL Style Sheet is similar in c o nc ept to a Casc ading Style Sheet fo r an HTML do c ument. Bo th to o ls allo w yo u to c reate a template that c an be used to pro vide a c o mmo n fo rmatting to a do c ument.
Note

And that ain’t all: This is an overly abbreviated section that describes w hat you
can do w ith just a few XSL statem ents. XSL is a very rich language, w hich can be
used to form at som e very com plex docum ents.

The basic appro ac h used in the XSL is that the first element in the do c ument applies
to the ro o t element o f the XML do c ument. The rest o f the elements o n the XML do c ument are fo rmatted rec ursively fro m the ro o t element. All XSL elements have a pre-

Chapter 20 ✦ Introducing XM L

fix o f xsl:.XSL is derived fro m SMGL and XML, so it is a tag-o riented language that
has to fo llo w the same basic rules used fo r any XML do c ument. Unlike so me o ther
languages, XSL is c ase sensitive, so all tags must be entered using lo werc ase c harac ters. Figure 20-3 sho ws the same FAMILY.XML do c ument fro m Listing 20-2, but it uses
the style c o des fro m the XSL do c ument sho wn in Listing 20-5.

Figure 20-3: Form atting an XML docum ent w ith an XSL style sheet

Listing 20-5: An XSL style sheet for the FAM ILY.XM L
document










Continued

441

442

Part V ✦ The Impact of XM L

Listing 20-5 (continued)



The

Family





Parents:






(father)





(mother)




Children:






(son)





Chapter 20 ✦ Introducing XM L


(daughter)




Pets:






(dog)





(cat)





(stingray)




On the
CD-ROM

The XSL style sheet is found on the CD-ROM in the \VB6DB\CHAPTER20\FAMILY.XSL file. I’ve also included a m odified version of the FAMILY.XML file, called
FAMILY1.XML, that w ill use this style sheet to form at the inform ation.

The xsl:stylesheet element
The xsl:stylesheet element is the ro o t element o f an XSL style sheet. The primary
attribute to this element is the xlsnm:xsl, whic h is used to spec ify the name spac e
fo r the do c ument. The name spac e identifies all o f the elements and their attributes.
This is a URL referenc e to a Web site like the o ne belo w. Ho wever, mo st XML vendo rs
o nly verify the name; they do n’t ac tually lo o k up the do c ument o n the Web.

http://www.w3.org/TR/WD-xsl

443

444

Part V ✦ The Impact of XM L

Name spac es are used in XML to help c larify a referenc e. Fo r instanc e, if yo u have a
tag c alled name, it may have many different meanings depending o n the c o ntext in
whic h it is used. By adding the name spac e and a c o lo n in fro nt o f the element, yo u
c an c larify whic h name spac e the element was used fro m. In fac t, the xsl: in fro nt
o f the xsl:stylesheet element identifies the element as belo nging to the xsl name
spac e.

The xsl:template element
The xsl:template element is the fundamental element to c o ntro l ho w a partic ular
part o f yo ur XML do c ument is fo rmatted. Co nsider the fo llo wing fragment fro m the
FAMILY.XSL do c ument:




(stingray)


This c o de will pro c ess the fo llo wing STINGRAY element fro m the XML do c ument:

Raymond
The match attribute identifies the XML element that will be pro c essed by this XSL
element. No te that there are many o ther ways to asso c iate the XSL template with an
XML element. The match attribute is just o ne o f the easier o nes to use.
Onc e the partic ular template element has been defined, the info rmatio n inside the
element will be displayed and any XSL elements will be exec uted. In this c ase, the
fo llo wing info rmatio n will be o utput:

Raymond (stingray)
Where the text c o mes direc tly fro m this element, the wo rd Raymond will be
generated by the element, fo llo wed by the text (stingray) and
. There is no reaso n that I c o uldn’t have inc luded o ther HTML elements,
suc h as an IMG element, to display a pic ture o f a stingray o r a hyperlink to ano ther
do c ument. Also , yo u sho uld no te that the info rmatio n is pro c essed in o rder o f ho w
it is listed. Thus, yo u c an perfo rm tasks befo re and after any o ther XSL tags yo u
wish to use.
Note

Office-oriented: The xsl:template elem ent is sim ilar to the concept of Style,
used in Microsoft Office. In a typical Word docum ent for exam ple, you m ay use
specific styles for headers, body text, tables, etc. . If you w ant to change the font
used in a header, all you have to do is update the style w ith the new font. Then all
of the headers in the docum ent w ill autom atically be updated. Without styles, you
w ould have to m anually update each individual header.

Chapter 20 ✦ Introducing XM L

The xsl:value-of element
The xsl:value-of element returns the value o f an element. If yo u use the selec t
attribute and spec ify a perio d as the value, then the value o f the c urrent element
will be returned. Thus, fo r this XSL template




(daughter)


and this XML element

Samantha
the will return the value Samantha.

The xsl:apply-templates element
The xsl:apply-templates element pro c esses templates fo r all o f the elements
within the c urrent element. In the fo llo wing XSL template



Parents:



an HTML header wo uld be c reated c o ntaining the wo rd Parents, and then the
FATHER and MOTHER elements beneath the PARENTS tag wo uld be pro c essed fro m
the XML do c ument fragment sho wn belo w:


Wayne
Jill

Any info rmatio n o utput by pro c essing the templates asso c iated with these elements wo uld fo llo w the info rmatio n o utput befo re the
element was reac hed in the XSL template. After all o f the templates have been
pro c essed, the tag wo uld be o utput.c

445

446

Part V ✦ The Impact of XM L

Other XM L tools
There are a few o ther to o ls that yo u sho uld be aware o f when c reating an XML do c ument. These to o ls help ensure that yo ur XML do c uments are c reated pro perly, as
well as help o ther users understand yo ur do c ument.

XM L parsers
One to o l that yo u’ll find valuable is an XML parser. Given the nature o f the XML language, it c an be a real pain fo r yo u to write c o de to c o nvert the XML elements into
so mething a bit mo re meaningful, muc h less verify that the XML do c ument yo u
rec eived is well fo rmed.
CrossReference

Microsoft has released an XML parser called MSXML that you can call from your
program . I’ll talk about this parser in m ore detail in Chapter 21.

Document Type Definitions
Ano ther feature o f XML is the ability to c reate a set o f rules that go verns ho w an
XML do c ument is c reated. These rules are kno wn as Do cume nt Type De finitio ns, o r
DTD. This info rmatio n c an be useful when c reating XML do c uments, sinc e it ensures
that yo u c an’t c reate an invalid do c ument. Yo u do n’t have to inc lude a DTD with
yo ur XML do c ument, and in prac tic e, many to o ls, suc h as Internet Explo rer 5.0,
do n’t bo ther to use it even if yo u do inc lude it.

XLinks and XPointers
The Exte nsible Linking Language (XLL) helps yo u lo c ate XML reso urc es o utside the
lo c al do c ument. XLL has two main parts: XLinks and XPo inters. XLL is similar in
c o nc ept to an HTML link. An XPo inter is a way to identify a lo c atio n in an XML do c ument, while an XLink uses a URL, and perhaps an Xpo inter, to lo c ate a sec tio n o f a
do c ument.

Working with XM L and ADO
ADO has the ability to save info rmatio n fro m a Recordset o bjec t into an XML file.
This makes it easy to c reate ADO do c uments that c an be sent to o ther applic atio ns.
But while the file is fo rmatted ac c o rding to XML rules, there are a few unique c harac teristic s that yo u sho uld understand.

Chapter 20 ✦ Introducing XM L

Creating an XM L File with ADO
Co nsider the fo llo wing Select statement:

Select CustomerId, Name
From Customers
Where State = ‘MD’
Yo u c an easily use it to po pulate a Recordset with data fro m the sample database
and save the results to an XML file with the statements in Listing 20-6.

Listing 20-6: The Command1_Click event in SaveXM L
Private Sub Command1_Click()
Dim db As ADODB.Connection
Dim rs As ADODB.Recordset
Set db = New ADODB.Connection
db.Open “provider=sqloledb;data source=Athena;” & _
“initial catalog=VB6DB”, “sa”, “”
Set rs = New ADODB.Recordset
rs.Open “Select CustomerId, Name From Customers “ & _
“Where State=’MD’”, db, adOpenForwardOnly, adLockReadOnly
rs.Save App.Path & “\results.xml”, adPersistXML
rs.Close
db.Close
End Sub

On the
CD-ROM

The SaveXML program and a copy of the Results.XML file can be found on the
CD-ROM in the \VB6DB\Chapter20\SaveXML directory.

Looking at the XM L file
The XML file will c o ntain all o f the info rmatio n nec essary to rec o nstruc t the
Recordset, inc luding a desc riptio n o f eac h Recordset and eac h ro w o f info rmatio n
retrieved fro m the database (see Listing 20-7).

447

448

Part V ✦ The Impact of XM L

Listing 20-7: A sample XM L file created by ADO



















Note

It looks different on disk: While the XML file generated by ADO is hum an readable, it isn’t very printer friendly. Therefore, I’ve restructured how the elem ents are
displayed in Listing 20-5, w ithout changing any of the content.

Chapter 20 ✦ Introducing XM L

The ro o t element o f the XML do c ument is the xml element. It is used to define the
name spac es that are used within the do c ument. Fo ur name spac es are typic ally
defined:

✦ s defines the sc hema
✦ dt defines data types
✦ rs defines Recordset info rmatio n
✦ z c o ntains ro w info rmatio n
The XML file is bro ken into two main elements: the sc hema element and the rec o rdset element. The sc hema element is deno ted by the tag , while the
rec o rdset element is deno ted by the tag.
In the s:schema element, glo bal rec o rdset info rmatio n is defined in the
s:ElementType element. Within this element, info rmatio n abo ut eac h o f the
c o lumns is defined. The s:AtrributeType element is used to define the c o lumn
name that will be used in the rec o rdset’s z:row element, alo ng with its data type.
Then eac h ro w o f data in the rec o rdset is listed in the rs:data element. This is the
mo st understandable element in the file. Eac h ro w in the rec o rdset is identified with
the z:row element name. Within the ro w, eac h c o lumn is listed as an attribute, with
its c o rrespo nding data value.

Understanding the Benefits of Using XM L
So , no w yo u kno w that XML is a way that yo u c an intelligently desc ribe data. But
why wo uld yo u want to use it in yo ur applic atio ns? In sho rt, no t all applic atio ns will
benefit fro m XML, but many will.

Data interchange
XML is based o n the c o nc ept that a do c ument is the best way to exc hange info rmatio n between o rganizatio ns. All kinds o f do c uments are used in a business: purc hase
o rders, invo ic es, c o ntrac ts, pro duc t spec ific atio ns, and so o n. A do c ument c reated by
o ne o rganizatio n must then be read and understo o d by ano ther. Do c uments c o ntain
two parts: the framewo rk fo r presenting the info rmatio n and the info rmatio n itself.
Co nsider a pro duc t c atalo g. It c o nsists o f a number o f individual spec ific atio n
sheets. Fo r a gro up o f similar pro duc ts, eac h o f the c atego ries in the spec ific atio n
sheet is the same, inviting the reader to make apples-to -apples c o mpariso ns
between pro duc ts.

449

450

Part V ✦ The Impact of XM L

There are many different ways to exc hange data between applic atio ns, eac h with
its limitatio ns and pro blems. In o rder to understand why yo u wo uld use XML,
yo u sho uld understand the mo re traditio nal metho ds o f data interc hange.

Binary files
Binary files typic ally c o ntain a raw dump o f the data fro m yo ur applic atio n. No
info rmatio n abo ut the data struc ture o f the file is c o ntained in the file, and usually a
c usto m pro gram needs to be written to read the info rmatio n fro m the file and refo rmat it into so mething that the rec eiving applic atio n c an use.
Onc e the file is c reated, it is transpo rted to ano ther c o mputer via a netwo rk, flo ppy
disk, o r so me o ther metho d, then lo aded into the sec o nd c o mputer. Any erro rs o r
pro blems enc o untered o n the remo te c o mputer are usually returned bac k to the
first c o mputer, using the same tec hnique that was used to send the data in the first
plac e. Ho wever, this tec hnique means that there is a delay between the time the
data is c reated in the sending applic atio n and the time befo re the rec eiving applic atio n has po sted the c hanges. In many c ases this do esn’t matter, but in so me c ases it
c an be a big pro blem.
There are o ther drawbac ks to using binary files. Different c o mputers use different
ways o f sto ring numeric data. Intel c o mputers, fo r instanc e, sto re a 16-bit integer
lo w byte then high byte, while o ther types o f c o mputers may sto re the same value
high byte then lo w byte. This means that yo u may have to transfo rm the ac tual values in o rder to ac c urately pro c ess the file.

Text files
Text files are also kno wn as flat file s. These files usually c o ntain a fo rmatted dump
o f data fro m the sending applic atio n. When dealing with mainframe-based applic atio ns, these files typic ally use a fixed data fo rmat, where eac h field o c c upies the
same c o lumn po sitio ns in eac h line o f the file.
PC-based applic atio ns typic ally use delimited files, suc h as Co mma Se parate d Value
(CSV) files o r tab delimited files, where eac h field in a line is separated fro m the next
field by a spec ial c harac ter, suc h as a c o mma o r tab. Eac h rec o rd in the file is separated fro m the next by a c arriage return, line feed, o r c arriage return line feed pair.
Like binary files, text files usually do n’t c o ntain info rmatio n abo ut the data itself.
So metimes the first line o f the file will c o ntain the names o f the fields, but o ther info rmatio n, suc h as data type and size info rmatio n, is almo st never inc luded. Also , like
binary files, text files need to be transpo rted to the remo te c o mputer either thro ugh
a netwo rk o r thro ugh remo vable media, suc h as a flo ppy disk o r magnetic tape.

COM components
Using COM to exc hange data is merely a matter o f building a COM c o mpo nent in
the rec eiving applic atio n that c an be c alled by the sending applic atio n as the data
is c reated. This makes is easier to send the data, sinc e the rec eiving applic atio n is

Chapter 20 ✦ Introducing XM L

able to pro c ess the data as it is rec eived. There is no pro blem parsing the vario us
fields that are being transpo rted, sinc e eac h field is sto red in its o wn pro perty with
its o wn spec ific data type.
One pro blem enc o untered when using COM fo r data interc hange revo lves aro und
the real-time nature o f COM. As the data is generated in the sending applic atio n, the
rec eiving applic atio n must be available to pro c ess it. If nec essary, yo u c an use a
message queue between the COM c o mpo nents that allo ws the two applic atio ns to
pro c ess data at their o wn speed. This prevents the sending applic atio n fro m transmitting data faster than the rec eiving applic atio n c an pro c ess it.
Yo u do n’t have to wo rry abo ut byte o rder o r any o ther c o mpatibility issues like that
bec ause the COM spec ific atio n ensures that tho se pro blems c an’t arise. Of c o urse,
using COM c o mpo nents means that yo u have to run in a Windo ws enviro nment.
While there are tec hniques that allo w yo u to run COM o n no n-Windo ws systems,
they generally aren’t as stable as using COM natively.

Separating content from formatting
It is po ssible to build generic Web pages that lo ad and display the info rmatio n
fo und in an XML do c ument, ho wever it is o ften desirable to c reate a pro gram that
reads the HTML do c ument and extrac ts meaningful info rmatio n fro m the do c ument.
By using an XML do c ument, yo u c an easily extrac t the info rmatio n yo u need.

Better searches
It is po ssib le to perfo rm b etter searc hes o f an XML file when c o mpared to an
unstruc tured file. Yo u c an use the tags to igno re data yo u do n’t want to searc h.
Fo r instanc e, if yo u have an XML file c o ntaining a list o f b o o ks, yo u c an searc h
o nly the autho r tags if yo u’re lo o king fo r a b o o k written b y a partic ular autho r.
While this may no t make a b ig differenc e when searc hing fo r so meo ne named
Elizab eth Tho rnb erry, it may help to eliminate false hits when searc hing fo r titles
written b y Red Bo o k.

Local access
Fo r all prac tic al purpo ses, yo u c o uld use an XML do c ument as a primitive database.
All o f the info rmatio n needed to desc ribe the data is kept within the do c ument, so it
wo uld be easy to retrieve data fro m a remo te database server and save it lo c ally in
an XML file whic h c o uld be used as input to vario us to o ls, suc h as a repo rt writer o r
statistic al analysis pro gram. Bec ause yo u have a lo c al c o py o f the data, yo u do n’t
impac t the database server’s perfo rmanc e when yo u pro c ess the data as yo u try
vario us repo rt fo rmats o r c reate c o mplex statistic al analysis pro grams.

Easily compressed
Bec ause XML tags and data are sto red using no rmal c o mmo n ASCII c harac ters, the
data is easily c o mpressed. Thus to o ls, suc h as a dial-up mo dem that auto matic ally
inc ludes data c o mpressio n helps to c o mpensate fo r the fac t that XML do c uments

451

452

Part V ✦ The Impact of XM L

are muc h larger than a straight binary file. No te that even with c o mpressio n, the
XML do c ument will mo st likely still be larger than the equivalent binary file, but
using data c o mpressio n go es a lo ng way to ward eliminating the extra o verhead.

Vendor independence
XML is independent o f any partic ular vendo r and has the benefit o f being inc o rpo rated into many different pro duc ts. Thus, it is easily inc o rpo rated into applic atio ns.
Unlike c o mma separated value files that have to be parsed, there are many different
XML parsers available to help yo u read an XML do c ument. So as lo ng as yo u c an
agree o n the elements in the XML do c ument, it do esn’t matter whether a COBOL
pro gram running o n an IBM mainframe o r a Visual Basic pro gram running o n
Windo ws 2000 pro c esses the XML do c ument.

Industry acceptance
Many industry-spec ific gro ups are being fo rmed to determine the elements and
o rganizatio n fo r do c ument exc hange. This is very impo rtant, sinc e it will allo w yo u
to exc hange info rmatio n with o ther applic atio ns and no t wo rry if, fo r example,
so meo ne c ho o ses to c all so meo ne’s name FIRST_NAME, FIRSTNAME o r FNAME.
There are a number o f industry gro ups c urrently wo rking o n standardizing XML
tags so that o rganizatio ns c an exc hange do c uments with the kno wledge that they
will understand the struc tures used in the do c uments.

Thoughts on Using XM L
Not every application w ill benefit from XML. Specifically, adding XML support to closed
applications (for exam ple, those applications that don’t share data w ith other applications)
is probably a w aste of tim e and m oney. There are better w ays to share data w ithin an application, such as a database or a COM object. How ever, if you have an open application that
needs to exchange data w ith other applications, XML m ay be the solution for you.
It’s m y opinion that XML is one of the m ost over-hyped technologies in the m arket today.
Every vendor is scram bling to dem onstrate their com m itm ent to XML and claim that their
products are XML-enabled. In reality, XML is only a tool for facilitating data exchange. The real
pow er of XML com es from the fact that m any industries are defining XML-based standards for
inform ation interchange. Having a standard that describes how to subm it a purchase order
for autom otive parts or return inform ation about your checkbook is w hat is really im portant.

Chapter 20 ✦ Introducing XM L

Summary
In this c hapter yo u learned:

✦ ho w XML do c uments are fo rmatted.
✦ abo ut XML tags and attributes.
✦ ho w to translate a database design into an XML do c ument.
✦ ho w to c reate an XML do c ument with an edito r.
✦ ho w to view an XML do c ument with Internet Explo rer 5.
✦ abo ut XSL style sheets.
✦ ho w ADO saves rec o rdsets in XML fo rmat.
✦ abo ut the benefits o f using XML







453