Re: Why do you use XML?
- From: "Jon Skeet [C# MVP]" <skeet@xxxxxxxxx>
- Date: Fri, 8 Feb 2008 07:23:34 -0800 (PST)
On Feb 8, 3:15 pm, "jehugalea...@xxxxxxxxx" <jehugalea...@xxxxxxxxx>
wrote:
I think it's a good idea to use the right format for the job, but XML
has significant benefits in many places:
1) Reasonable character encoding support
How often is this a real concern? I assume you are talking about
Unicode, UTF8, etc. How hard is it to generate a Unicode file? How
often can't you figure that out?
Often. You'd be amazed at how often people guess at encodings and get
it wrong.
2) No need to manually escape and unescape data (did your SSV file have
no values with spaces in?)
SSV files don't care where the spaces are. The position and length of
fields are static.
That doesn't sound like a space-separated value file. That sounds like
a fixed record file to me. Different kettle of fish, IMO.
XML doesn't need to limit the size of a field,
however, neither does CSV. A quick regular expression can break a CSV
file apart in no time (it is slower though).
Except you've got to know exactly which flavour of CSV is being used.
3) Natural way of representing hierarchies, or multiple tables etc -
SSV/CSV really only describes a single rectangular table easily
I agree this is a good use of XML. However, a long time ago, you
handled heirarchies with a relational schema and had the entities in
separate files, searching on index(which was the line number usually),
which was typically fast and easy to code to.
Searching on line numbers only works with fixed length records (which
has limitations) *and* if you're using a fixed with encoding - so
UCS-2 is okay, but UTF-8 isn't, for example. It also means having to
manage more files.
4) Reasonably self-descriptive, with element and attribute names
I agree about this too. However, again, most other formats support a
header line that has the name of the column. Usually that is all that
is needed. Using my example above, attributes translate to values and
child elements to relations. It can be equally represented.
When you say "usually" - out of what range of uses? Most of my data
sources aren't represented in just a single table form - so I've
either got to have multiple files, or use a richer format such as XML.
5) Well-defined standard - if you give me an XML file, I need to
ask you enough information to *understand* the data, but I don't
need more information in order to *load* it. Compare that with
finding out which particular brand of SSV/CSV/etc you're using
This is another good point. Again, even XML formats are typically
application specific, not global such as XHTML. To some degree the
developer must always know what he is working with. In my opinion, it
takes as long to understand a SSV as it does to understand an XML. DTD
surely helps and having the nesting direclty in the file is also
beneficial.
There's a difference between understanding the syntax and
understanding the semantics. If it's an application-specific file,
you'll have to have some description of the semantics whatever format
you use - but with XML you don't need to have anything extra to
describe the syntax (beyond the option of using a DTD, which the
developer doesn't need to understand - they just give to the XML
parser).
But what experiences have you found XML useful in. I mostly concerned
with knowing a good time to use XML. Like I said, I hear the hype all
the time, but have rarely found a practical application of it.
I use XML all the time, in many, many situations. Persistence,
serialization, project files for Visual Studio, configuration files
for applications, RSS feeds... whereas I can't remember the last time
I had to write code to deal with a fixed size record file.
Jon
.
- Follow-Ups:
- Re: Why do you use XML?
- From: jehugaleahsa@xxxxxxxxx
- Re: Why do you use XML?
- References:
- Why do you use XML?
- From: jehugaleahsa@xxxxxxxxx
- Re: Why do you use XML?
- From: Jon Skeet [C# MVP]
- Re: Why do you use XML?
- From: jehugaleahsa@xxxxxxxxx
- Why do you use XML?
- Prev by Date: Re: Why do you use XML?
- Next by Date: Re: Why do you use XML?
- Previous by thread: Re: Why do you use XML?
- Next by thread: Re: Why do you use XML?
- Index(es):
Relevant Pages
|
Loading