.comment-link {margin-left:.6em;}

Ben Cops

Thursday, March 08, 2007

XmlPreProcess - false values are undefined!

The kind of problem that makes you check absolutely everything and declare that it should just work. We have this overly complicated MSI generation process that has two calls to XmlPreProcess in it. Our system test installer was working fine, but our production installer didn't work - an installed config file was coming out with an error message from XmlPreProcess stating that a particular property was not defined. It was. In the end I downloaded the source code for XmlPreProcess and stepped through the property parsing routines and found the following line, deep in a mass of uncommented functions:

if (null != propertyValue &&
!propertyValue.ToUpper().Equals("FALSE"))
{
properties.Add(propertyName, DeQuote(propertyValue));
}


In other words if the property is empty of equal to false, its undefined. WTF? To be fair, it does mention this in the documentation, which of course I hadn't read:

Boolean Properties
All property values are treated as strings with the exception of the word False (case is irrelevant). If you set a property to the value False, it will have the effect of un-defining it. There are some cases where you may actually want the literal value of "False" to be replaced. To accomplish this, enclose it in single or double quotes. The quotes will be stripped, and the value will simply be treated like any other string property.


This is the kind of undisclosed "feature" that drives me insane. Just like the "helper" function we had on our project that read an XML element value at an XPath - if it didn't find it it returned a blank string. Cue another baffling bug (null is not equal to false!). If you're going to write this kind of garbage, call the function "ReadXMLAtXPathAndReturnBlankIfItDoesntExist". And no, putting the info in the <Remarks> tag does not count.

Actually, writing APIs with this kind of stuff in it reminds me of this bit from HHGTTG:

Shortly before the Vogons demolish the Earth to make way for a hyperspace bypass, they inform the planet that "All the planning charts and demolition orders have been on display in your local planning department on Alpha Centauri for fifty of your Earth years, so you've had plenty of time to lodge any formal complaint and it's far too late to start making a fuss about it now." When someone objects to this, Protstetnic Vogon Jeltz replies, "What do you mean you've never been to Alpha Centauri? For heaven's sake mankind, it's only four light years away you know. I'm sorry, but if you can't be bothered to take an interest in local affairs that's your own lookout."

1 Comments:

  • I came across this old post when I was trying to solve the same issue. Fortunately, version 2.0.18 of XmlPreprocess added a new command line flag called /fixFalse (or /f) which corrects the default behaviour:

    /fixFalse (/f) Do not use the value of "False" to undefined settings. (instead use "#undef")

    This is nicer than having to surround false with quotes.

    By Anonymous Simon Clendon, at 11:49 pm  

Post a Comment

<< Home