|
|
|
|
 Wednesday, October 27, 2004
|
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("{0}>",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
|
Trackback
|
|
|