15.04.2018 Views

programming-for-dummies

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

260<br />

Storing Data in Text Files<br />

The “other” universal file <strong>for</strong>mat<br />

The biggest drawback with text files is that they<br />

can’t contain any <strong>for</strong>matting in<strong>for</strong>mation. So if<br />

you need to transfer a word processor document<br />

from an ancient Atari ST computer to a<br />

modern Macintosh computer, you lose all <strong>for</strong>matting<br />

in that document.<br />

To prevent this problem, computer scientists<br />

created a universal file <strong>for</strong>mat that can retain<br />

both data and <strong>for</strong>matting. This new file <strong>for</strong>mat,<br />

XML (Extensible Markup Language), contains<br />

both data and instructions <strong>for</strong> how to display<br />

the data. For example, the sentence “This is the<br />

text you would actually see” looks like this in an<br />

XML file:<br />

This is the text you<br />

would actually see<br />

Essentially, an XML file is just a text file with <strong>for</strong>matting<br />

instructions or tags that define the<br />

appearance of data. Because XML files are<br />

text files, any computer can read them. To fully<br />

read an XML file, a computer needs a special<br />

program — an XML parser — which not only<br />

reads the data but also translates the XML <strong>for</strong>matting<br />

tags that tell the computer how to display<br />

that data.<br />

To create a universal file <strong>for</strong>mat <strong>for</strong> word<br />

processor documents, spreadsheets, databases,<br />

and presentation files, computer scientists<br />

have created a new file <strong>for</strong>mat, based on<br />

XML — the OpenDocument standard. The main<br />

idea behind this OpenDocument standard is to<br />

define a universal file <strong>for</strong>mat that retains both<br />

data and <strong>for</strong>matting commonly found in word<br />

processors, spreadsheets, databases, and<br />

presentation program files. Unlike proprietary<br />

file <strong>for</strong>mats, which a single company can control,<br />

the OpenDocument standard is freely<br />

available to anyone.<br />

The OpenDocument file <strong>for</strong>mat has even gained<br />

the support of many governments, which want<br />

to insure that people can still read and edit their<br />

files no matter what computer or software they<br />

may be using in the future. If you store important<br />

files in a proprietary file <strong>for</strong>mat, such as<br />

Microsoft Word or Microsoft Access, there’s a<br />

chance that programs in the future won’t know<br />

how to open those files, which means your data<br />

could potentially be lost <strong>for</strong>ever. By using the<br />

OpenDocument standard, your data can remain<br />

accessible <strong>for</strong>ever (or at least until computer<br />

scientists create another “universal” file <strong>for</strong>mat).<br />

However, to identify data that should logically be lumped together, programs,<br />

such as databases and spreadsheets, offer the option of saving text<br />

files as either<br />

✦ A comma-delimited text file (also known as CSV or Comma Separated<br />

Values) simply divides text into logical chunks, such as<br />

Joe Smith, 123 Main Street, New York, NY, 10012<br />

✦ A tab-delimited text file divides text by tabs (spaces), like this:<br />

Joe Smith 123 Main Street New York NY 10012

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!