Do what I do (not what I say)?

by Michael S. Kaplan, published on 2006/04/18 03:01 -04:00, original URI: http://blogs.msdn.com/b/michkap/archive/2006/04/18/577922.aspx


Having to deal with the double standard symbolized by the "Do what I say (not what I do!)" that some parents find themselves having to enforce seems almost like a part of life.

Earlier today I got to see us handling it in the converse sense....

Here is what the customer reported:

We have .resx files that contains error message strings in different languages.  These are used to generate satellite assemblies when we compile.  When we first created them, we had a problem with some German characters not appearing properly because of either ANSI or UTF8 encoding used to save the .resx file.  In order to get by this problem, we had to go through each German .resx file and save it with Unicode encoding.  Once this was done, this all worked fine with Visual Studio 2003.

Now that I'm converting to Visual Studio 2005, I got a compiler error because the encoding attribute on the XML header was set to UTF8 but the file was saved as Unicode.  All I did to get by the problem is remove the encoding attribute from the XML header and it recompiled successfully.

Now what better example of "Do what I do (not what I say)" could be found than in a problem caused by what was apparently happening in 1.1 of the .NET Framework -- where we were doing what the BOM/encoding DID rather than what the XML header SAID?

This is obviously not the most defensible strategy when it is stated in such a way -- and frankly, what is the meaning of the situation when the encoding attribute and the actual encoding are not the same? Isn't that just wrong?

Perhaps, as most parents realize (when the found that children would simply not abide such a state of affairs!) it is best to make sure that What we do and What we say are the same thing....

 

This post is sponsored by "" U+feff (ZERO WIDTH NO-BREAK SPACE, of course)


# Mihai on 18 Apr 2006 1:50 PM:

I think failing if there is a mismatch is the right thing to do.
A hint can be found here:
http://www.w3.org/TR/xml11/#sec-guessing
<<Like any self-labeling system, the XML encoding declaration will not work if any software changes the entity's character set or encoding without updating the encoding declaration.>>

# Maurits [MSFT] on 18 Apr 2006 5:42 PM:

Maybe he thought "Unicode" really meant UTF-8 instead of UCS-2LE? Or that VS would sniff the XML header and "save as (that encoding type)"?

Failing is right.  From the XML 1.0 spec:
"It is a fatal error if an XML entity is determined (via default, encoding declaration, or higher-level protocol) to be in a certain encoding but contains octet sequences that are not legal in that encoding. It is also a fatal error if an XML entity contains no encoding declaration and its content is not legal UTF-8 or UTF-16."

Please consider a donation to keep this archive running, maintained and free of advertising.
Donate €20 or more to receive an offline copy of the whole archive including all images.

go to newer or older post, or back to index or month or day