XML - Practical uses?

Kurt Granroth plug-discuss@lists.PLUG.phoenix.az.us
Thu, 21 Jun 2001 12:48:14 -0700


On Thursday 21 June 2001 11:53 am, Steven M. Klass wrote:
> I apologize for this potentially lame question, but I am curious and
> it's killing me.
>
> What is the point of XML and what practical benifit would I get from
> writing in it?

XML exists primarily to markup data in a consistent way that makes
parsing much easier later.

Now the short answer to what benefit you get from writing in it is
"none (in the way that you are thinking of using it)"  XML is only
marginally useful for humans to read -- it's intended for software to
parse.

Now let's take a mailbox with tens of thousands of messages in it.  We
want to search this mailbox for a particular string in the body of the
message but *NOT* in the headers or in any attachments.  This would be
doable, but not fun.  The parsing would require finding out where the
headers started and ended and where the attachments started and
ending.  Everytime you ran the search, these starting and ending
points would have to be recalculated.

Now say we have the same mailbox but this time, each message is
marked-up using XML.  Something like (*very* simplistic):

<message>
  <headers>
  </headers>
  <body>
  </body>
  <attachment>
  </attachment>
  <attachment>
  </attachment>
</message>

Our search engine can now go through the file *very* quickly to find
the body elements.. because we have already shown where the body is!

If we wanted to extend this, we could have such things as:

  <headers>
    <from></from>
    <subject></subject>
  </headers>

Then, we could also search for all From lines without having to use
some convoluted regexp.

Does that make sense?  XML is a standardized way for programs to
figure out just what the data it's seeing really is.
-- 
Kurt Granroth            | http://www.granroth.org
KDE Developer/Evangelist | SuSE Labs Open Source Developer
granroth@kde.org         | granroth@suse.com
            KDE -- Conquer Your Desktop