Logo




Subscribe:
RSS 2.0 | Atom 1.0
Categories:

Sign In


[Giagnocavo]Michael::Write()

# Wednesday, October 27, 2004
Massive XML abuse

OK, I've had it. Ever since XML came out, certain people have been misusing it all over the place for no reason at all. *XML IS JUST A FORMAT.* It's not magic. It's not cool. Use if it makes sense. However, it is actually a REAL format; adding < and > to a document doesn't make it XML. LinkPoint needs to learn this.

LinkPoint (owned by First Data) is a rather large company to process credit cards. You would think they'd have people who actually have some clue as to what they are doing when it comes to their programmatic interface eh? Check this code sample out:

protected string ParseTag(string tag, string rsp)
{
  StringBuilder sb = new StringBuilder(256);
  sb.AppendFormat(
"<{0}>",tag);
  int len = sb.Length;
  int idxSt=-1,idxEnd=-1;
  if( -1 == (idxSt = rsp.IndexOf(sb.ToString())))
  {
return ""; }
  idxSt += len;
  sb.Remove(0,len);
  sb.AppendFormat(
"",tag);
  if( -1 == (idxEnd = rsp.IndexOf(sb.ToString(),idxSt)))
  {
return ""; }
  return rsp.Substring(idxSt,idxEnd-idxSt);
}

I'm not making this up. At first I started laughing. And continued. It's one way of processing XML, heh. I also love the use of a StringBuilder *for no reason*. They didn't even have the decency to think about Regular Expressions. (And what's up with that crazy formatting on the ifs??) Sigh.

The whole point of XML is to provide a standard way to process data on whatever platform you wish, eliminating the need for stupid code like that above. With XPath, all that junk comes down to about 3 lines of nice, neat code. So I continued to chuckle as I wrote my nice, elegant code.

Until it came to runtime. Apparently, some folks don't know that XML has *ONE ROOT ELEMENT*. Throwing a bunch of tags together doesn't make it a valid document. And invalid documents mean... yep, you guessed it: Errors from your XML parser. And without a working XML parser, you're back to manually handling it. So why even bother with “XML“ if you're not going to do it correctly? A simple name=value would work just fine...

BTW, this is the second vendor this week I've seen using invalid XML documents.

Quick update: The easiest solution in this case is to just do: theirXml = “<root>” + theirXml + “</root>”; // works like a charm.
Code | Humour
Wednesday, October 27, 2004 5:22:11 AM UTC  #    Comments [2]  |  Trackback

Wednesday, October 27, 2004 6:13:30 PM UTC
Amazing. I wonder if they had a pseudo-developer throwing together samples at the last minute? I wonder if they know what the samples say about thier company?
Sunday, November 14, 2004 6:19:45 AM UTC
Dude - Wow - Are they working for the State of SC? We had some code come in from the guys at the state + their contractors who needed to Fill a Typed DataSet. They filled a untyped dataset and copied the values row by row into the typed one. Anyway, the "Update" part of the component "is giving us trouble" - gasp.

I think a lot of people think that if they use XML - it's cool - no matter how much a33 it sucks. This is horrendous.
OpenID
Please login with either your OpenID above, or your details below.
Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):

Live Comment Preview