• Tidak ada hasil yang ditemukan

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


Academic year: 2017

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


Teks penuh


Introducing XM L


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 hap-ter, 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 lan-guages 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 tagis fo rmed by inserting a keywo rd inside a less than and greater than symbo l pair (<>) , suc h as <HEADER1>. Mo st tags wo rk in pairs suc h as <HEADER1>and </HEADER1>, 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 begin-ning and end o f a piec e o f info rmatio n. So metimes the info r-matio 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 <I>identifies a blo c k o f text that sho uld be

2 0

benefits o f using XML


displayed in italic s, while the tag <B>identifies a blo c k o f text that sho uld be dis-played 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 <B>bold</B>, <I>italics</I>, and both <B><I>bold and italics</I></B> 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 <IMG>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 rma-tio n is spec ified with the SRC attribute. Thus, the fo llo wing tag wo uld display the image CJ&Sam.JPGin 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:

<IMG SRC=”CJ&Sam.JPG” HEIGHT=”640” WIDTH=”480”>

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 <B>bold</B>, <I>italics</I>, and both <B><I>bold and italics</I></B> by using different combinations of tags.

and this set o f tags

You may display text in <B>bold</B>,

<I>italics</I>, and both

<B><I>bold and italics</I></B>

by using different combinations of tags.

and even this set o f tags

You may display text in <B>bold</B>, <I>italics</I>, and both


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 t-ing the meant-ing 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.

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 (IM S), 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


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 hi-c al struhi-c ture.

Listing 20-2:

An XM L document for the Freeze family

<?xml version=”1.0”?> <FAMILY>








<CAT>Terry</CAT> <CAT>Cali</CAT> <CAT>Dusty</CAT>



You can find the FAM ILY.XM L docum ent as \VB6DB\Chapter20\XML\FAM-ILY.XMLon 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 <FAMILY>, <PARENTS>, <CHILDREN>, and <PETS> 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 XM L data in Internet Explorer 5.0


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 u-ment. 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

<?xml version=”1.0”?> <FAMILY Name=”Freeze”>

<PARENT Type=”Father”>Wayne</PARENT> <PARENT Type=”Mother”>Jill</PARENT> <CHILD Type=”Son”>Christopher</CHILD> <CHILD Type=”Daughter”>Samantha</CHILD> <PET Type=”Dog”>Kokomo</PET>

<PET Type=”Cat”>Pixel</PET> <PET Type=”Cat”>Terry</PET> <PET Type=”Cat”>Cali</PET> <PET Type=”Cat”>Dusty</PET>

<PET Type=”Stingray”>Raymond</PET> </FAMILY>

Using attributes lets yo u inc lude mo re info rmatio n in a single element. The do wn-side 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 Currencyto 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.


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.


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 .

Extensive XM L: I highly recom m end the XML Bibleby Elliotte Rusty Harold, pub-lished by IDG Books. This w ell-w ritten book goes into all of the details you should know before you build an XM L-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

<?xml version=”1.0”?> <root_element_tag> </root_element_tag>

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

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:



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




The <CHILDREN>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:

<B><I>Hi Jill</B></I>

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

<B><I>Hi Jill</I></B>

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 u-ment. 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 m-mo n fo rmatting to a do c ument.

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


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 XM L docum ent w ith an XSL style sheet

Listing 20-5:

An XSL style sheet for the FAM ILY.XM L


<?xml version=”1.0”?>

<xsl:stylesheet xmlns:xsl=”http://www.w3.org/TR/WD-xsl”> <xsl:template match=”/”>

<html> <head> </head> <body>

<xsl:apply-templates/> </body>



<xsl:value-of select=”.”/>

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

The xsl:stylesheet element

The xsl:stylesheetelement 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.



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:stylesheetelement identifies the element as belo nging to the xsl name spac e.

The xsl:template element

The xsl:templateelement 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:

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


The matchattribute 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 matchattribute 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:

<li>Raymond (stingray)</li>

Where the text <li>c o mes direc tly fro m this element, the wo rd Raymondwill b e generated b y the <xsl:value-of>element, fo llo wed b y the text (stingray)and </li>. There is no reaso n that I c o uldn’t have inc luded o ther HTML elements, suc h as an IMGelement, 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 b efo re and after any o ther XSL tags yo u wish to use.

Office-oriented: The xsl:templateelem 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.


The xsl:value-of element

The xsl:value-ofelement 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

<xsl:template match=”DAUGHTER”> <li>

<xsl:value-of select=”.”/> (daughter)

</li> </xsl:template>

and this XML element


the <xsl:value- of select=”.”/>will return the value Samantha.

The xsl:apply-templates element

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

<xsl:template match=”PARENTS”> <p>

<h2>Parents:</h2> <xsl:apply-templates/> </p>


an HTML header wo uld be c reated c o ntaining the wo rd Parents, and then the FATHERand MOTHERelements beneath the PARENTStag wo uld be pro c essed fro m the XML do c ument fragment sho wn belo w:




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 lan-guage, 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.

Microsoft has released an XM L parser called M SXM L 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 Recordseto 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 har-ac teristic s that yo u sho uld understand.


Creating an XM L File with ADO

Co nsider the fo llo wing Se le ctstatement:

Select CustomerId, Name From Customers

Where State = ‘MD’

Yo u c an easily use it to po pulate a Recordsetwith 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



End Sub

The SaveXM L program and a copy of the Results.XMLfile can be found on the CD-ROM in the \VB6DB\Chapter20\SaveXMLdirectory.

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 Recordsetand eac h ro w o f info rmatio n retrieved fro m the database ( see Listing 20-7) .


Listing 20-7:

A sample XM L file created by ADO

<xml xmlns:s=’uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882’ xmlns:dt=’uuid:C2F41010-65B3-11d1-A29F-00AA00C14882’ xmlns:rs=’urn:schemas-microsoft-com:rowset’


<s:Schema id=’RowsetSchema’>

<s:ElementType name=’row’ content=’eltOnly’ rs:CommandTimeout=’30’>

<s:AttributeType name=’CustomerId’ rs:number=’1’ s:writeunknown=’true’>

<s:datatype dt:type=’int’ dt:maxLength=’4’ rs:precision=’10’

rs:fixedlength=’true’ rs:maybenull=’false’/>


<s:AttributeType name=’Name’ rs:number=’2’ rs:nullable=’true’ rs:writeunknown=’true’>

<s:datatype dt:type=’string’ rs:dbtype=’str’ dt:maxLength=’64’/>


<s:extends type=’rs:rowbase’/>




<z:row CustomerId=’84’ Name=’Fred Price’/> <z:row CustomerId=’205’ Name=’Joseph Bell’/> <z:row CustomerId=’385’ Name=’Kali Carlisle’/>



It looks different on disk:While the XM L file generated by ADO is hum an read-able, 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.


The ro o t element o f the XML do c ument is the xmlelement. 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:

✦sdefines the sc hema

✦dtdefines data types

✦rsdefines Recordsetinfo rmatio n

✦zc 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 rd-set element. The sc hema element is deno ted by the tag <s:schema>, while the rec o rdset element is deno ted by the <rs:data>tag.

In the s:schemaelement, glo bal rec o rdset info rmatio n is defined in the s:ElementTypeelement. Within this element, info rmatio n abo ut eac h o f the c o lumns is defined. The s:AtrributeTypeelement is used to define the c o lumn name that will be used in the rec o rdset’s z:rowelement, alo ng with its data type.

Then eac h ro w o f data in the rec o rdset is listed in the rs:dataelement. This is the mo st understandable element in the file. Eac h ro w in the rec o rdset is identified with the z:rowelement 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 rma-tio n between o rganizarma-tio 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.


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 r-mat 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 a-tio 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 val-ues 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 a-tio 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 sepa-rated 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 r-matio n, suc h as data type and size info rr-matio 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


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 trans-mitting 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. 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


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, FIRSTNAMEo 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 XM L. Specifically, adding XM L 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 appli-cation, 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, XM L m ay be the solution for you.



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



Figure 20-1: My family
Figure 20-2: Viewing XML data in Internet Explorer 5.0
Figure 20-3: Formatting an XML document with an XSL style sheet


Dokumen terkait

Adapun tujuan diadakannya indeks saham syariah sebagaiman Jakarta Islamic Index yang melibatkan 30 saham terpilih, yaitu sebagai tolak ukur untuk mengukur kinerja

You can download and install the soft file of this incredible book Time Mends (Timber Wolves, Book 2) By Tammy Blackwell currently and in the link offered.. Yeah, different with

Indonesia merupakan negara dengan orang muslim terbesar didunia, akan tetapi setiap ormas muslim sendiri tentunya berbeda dalam memutuskan suatu masalah baru yang muncul

n salinannya sebagaimana tertuang dalam lam proses pembuktian kualifikasi

Uang merupakan uang milik masyarakat atau uang beredar di masyarakat (di luar Bank Sentral seperti Bank Indonesia dan perbankan atau semua bank), yang terdiri dari :.. Uang Kertas

Puji syukur kami panjatkan kepada Tuhan Yang Maha Esa atas limpahan rahmat dan hidayah-Nya sehingga Prosiding Seminar Nasional MIPA Universitas Negeri Yogyakarta

As everybody recognizes, book Carr: Five Years Of Rape And Murder By Edna Buchanan is very popular as the window to open up the globe. It implies that reading publication Carr:

Teori investasi menjelaskan bahwa ketidakpastian IHSG pada suatu pasar bursa disebabkan oleh adanya pengaruh faktor lingkungan bisnis yang terdiri dari faktor lingkungan