Article 27KRE CodeSOD: Sche-ma

CodeSOD: Sche-ma

by
Remy Porter
from The Daily WTF on (#27KRE)

In the early 2000s, it was a time of darkness, a world of fear, it was the age of XML. As someone who was just entering the industry at the time, you couldn't type three lines of code without a PHB asking, "Have you considered using XML for this?" Since this was 2002, "this" was likely trying to find a way to emulate the marquee tag in JavaScript, the answer was usually, "No," at which point you'd be reminded that we should be using XML for everything, so throw it out and start over in XML.

One of the key selling points of the grand power of XML was the idea of schemas. These magical little files allowed you to use XML to specify the structure of some other XML, and then validate various XML documents against that schema. Combined with the ability to use namespaces, this was truly the One Format to Rule Them Alla.

The real magic, of course, was that since XML was a text based format with a clear (if complicated) parsing mechanism, it could be produced and consumed by any system, including those pesky legacy mainframes that were sure to be replaced any year now. Vendor after vendor came up with new and interesting ways to bolt XML onto your mainframe, so that you could wire modern applications up to those legacy back ends, and when you wanted to replace that legacy backend (they're going away, any year now! Really!), you could slap a modern backend behind the same XML interface.

I bring up this history lesson because John B works for a "very large, government-type" organization. He maintains an XML data-feed that passes around location data. I strongly suspect that the schema for that XML data-feed was generated based off of an older flat-file dataset from a legacy system. Why? Well, let's look at a sample file.

 <LatitudeAndLongitudeMinutes04DecimalPlaces> <LatitudeDegrees>01</LatitudeDegrees> <LatitudeMinutes04DecimalPlaces>01.6122</LatitudeMinutes04DecimalPlaces> <LatitudinalHemisphere>N</LatitudinalHemisphere> <Hyphen>-</Hyphen> <LongitudeDegrees>001</LongitudeDegrees> <LongitudeMinutes04DecimalPlaces>001.1641</LongitudeMinutes04DecimalPlaces> <LongitudinalHemisphere>W</LongitudinalHemisphere> </LatitudeAndLongitudeMinutes04DecimalPlaces>

There's something odd there- I can't quite put my finger on it- there's a strange character- just jammed into the middle- what?

Yes, there is a <Hyphen> element. And not only is this element there, it's absolutely required. Here's the schema for the LatitudeAndLongitudeMinutes04DecimalPlaces:

 <xsd:complexType name="LatitudeAndLongitudeMinutes04DecimalPlacesType"> <xsd:annotation> <xsd:appinfo> <FudName>LATITUDE AND LONGITUDE, MINUTES, 0-4 DECIMAL PLACES</FudName> <FudExplanation>THE INTERSECTING LINES OF LATITUDE AND LONGITUDE WHICH DETERMINE THE GEOGRAPHICAL POSITION OF ANY PLACE ON THE EARTH'S SURFACE, EXPRESSED UP TO ONE TEN THOUSANDTH OF A MINUTE.</FudExplanation> <FieldFormatIndexReferenceNumber>2571</FieldFormatIndexReferenceNumber> <FudNumber>1</FudNumber> <VersionIndicator>2.0</VersionIndicator> <FudSponsor/> <FudRelatedDocument/> </xsd:appinfo> </xsd:annotation> <xsd:sequence> <xsd:element name="LatitudeDegrees" type="LatitudeDegreesType"> <xsd:annotation> <xsd:appinfo> <ElementalFfirnFudnSequence>1</ElementalFfirnFudnSequence> </xsd:appinfo> </xsd:annotation> </xsd:element> <xsd:element name="LatitudeMinutes04DecimalPlaces" type="LatitudeMinutes04DecimalPlacesType"> <xsd:annotation> <xsd:appinfo> <ElementalFfirnFudnSequence>2</ElementalFfirnFudnSequence> </xsd:appinfo> </xsd:annotation> </xsd:element> <xsd:element name="LatitudinalHemisphere" type="LatitudinalHemisphereType"> <xsd:annotation> <xsd:appinfo> <ElementalFfirnFudnSequence>3</ElementalFfirnFudnSequence> </xsd:appinfo> </xsd:annotation> </xsd:element> <xsd:element name="Hyphen" type="HyphenType"> <xsd:annotation> <xsd:appinfo> <ElementalFfirnFudnSequence>4</ElementalFfirnFudnSequence> </xsd:appinfo> </xsd:annotation> </xsd:element> <xsd:element name="LongitudeDegrees" type="LongitudeDegreesType"> <xsd:annotation> <xsd:appinfo> <ElementalFfirnFudnSequence>5</ElementalFfirnFudnSequence> </xsd:appinfo> </xsd:annotation> </xsd:element> <xsd:element name="LongitudeMinutes04DecimalPlaces" type="LongitudeMinutes04DecimalPlacesType"> <xsd:annotation> <xsd:appinfo> <ElementalFfirnFudnSequence>6</ElementalFfirnFudnSequence> </xsd:appinfo> </xsd:annotation> </xsd:element> <xsd:element name="LongitudinalHemisphere" type="LongitudinalHemisphereType"> <xsd:annotation> <xsd:appinfo> <ElementalFfirnFudnSequence>7</ElementalFfirnFudnSequence> </xsd:appinfo> </xsd:annotation> </xsd:element> </xsd:sequence> </xsd:complexType>

If you haven't worked with XML schemas before, count your blessings, and don't try and make sense out of this. Just pay attention to this tag: <xsd:element name="Hyphen" type="HyphenType">"</xsd:element>, which actually references an external schema. That's right, this isn't just a Hyphen element, it's a whole datatype just to represent hyphens.

 <xsd:simpleType name="HyphenType"> <xsd:annotation> <xsd:appinfo> <FudName>HYPHEN</FudName> <FudExplanation/> <FieldFormatIndexReferenceNumber>1025</FieldFormatIndexReferenceNumber> <FudNumber>2</FudNumber> <VersionIndicator>1.0</VersionIndicator> <MinimumLength>1</MinimumLength> <MaximumLength>1</MaximumLength> <LengthLimitation>Fixed</LengthLimitation> <Type>String</Type> <FudSponsor/> <FudRelatedDocument/> <EntryType>Individual</EntryType> </xsd:appinfo> </xsd:annotation> <xsd:restriction base="xsd:string"> <xsd:enumeration value="-"> <xsd:annotation> <xsd:appinfo> <DataType>String</DataType> <Explanation/> <DataCode>-</DataCode> <DataItem>HYPHEN</DataItem> <DataItemSequenceNumber>1</DataItemSequenceNumber> </xsd:appinfo> </xsd:annotation> </xsd:enumeration> </xsd:restriction> </xsd:simpleType>

Not only is there a HyphenType, but the HyphenType contains an enumeration! This makes it extensible, for if you ever need to add different kinds of hyphen-like characters, like "-", "-", or "a'".

release50.png[Advertisement] Release!is a light card game about software and the people who make it. Play with 2-5 people, or up to 10 with two copies - only $9.95 shipped! TheDailyWtf?d=yIl2AUoC8zAgsBkLwcZtX4
External Content
Source RSS or Atom Feed
Feed Location http://syndication.thedailywtf.com/TheDailyWtf
Feed Title The Daily WTF
Feed Link http://thedailywtf.com/
Reply 0 comments