vb6msxmlmsxml4

MSXML4 IXMLDOMNode.nodeTypedValue throwing Type mismatch exception on one machine


I have a VB6 program that is failing on a particular machine.

The nature of the problem is code like this:

'this next line throws Type mismatch exception
If xml_file.documentElement.selectSingleNode("Node").Attributes.getNamedItem("InUse").nodeTypedValue Then
  'do some stuff
End If

The program uses MSXML4, and this problem only occurs on one machine (so far), though it works on many other machines. Furthermore, the InUse attribute is defined in the XML schema as follows:

<xs:attribute name="InUse">
    <xs:simpleType>
        <xs:restriction base="xs:boolean">
            <xs:whiteSpace value="collapse"/>
        </xs:restriction>
    </xs:simpleType>
</xs:attribute>

One more thing.

If I print out TypeName() of that .nodeTypedValue expression, it comes back as a "String". It's not terribly surprising, then, that a type mismatch might occur. But why only on that one machine?

As I'm thinking about it, that machine may have the Locale set to a different language than the other machines that I'm testing. Could that have something to do with it? Does VB6 use the locale determine how to coerce the string "false" into a boolean? If so, is there any way to force it to use English?

Any ideas?


Solution

  • Yes, many type conversion functions and implicit conversions are locale-aware. For reliable operation in a case like this (in particular with XML) use:

    If LCase$(Trim$(string-expression)) = "true" Then
    

    XML schemas are fairly "soft" creatures. You might want to look at:

    http://msdn.microsoft.com/en-us/library/windows/desktop/ms762308(v=vs.85).aspx

    Basically MSXML 4.0 is obsolete and not meant to be used anymore. Even then you need an XDR schema to get stronger typing. As of MSXML 6.0 XDR is not supported.

    Effectively you ought to be using .nodeValue and just dealing with it.