LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

CVIXML character encoding puzzle

I have an app that parses an XML file generated by .NET with the CVIXML library. The contents of that XML file have 2 bytes per character, and under normal situations the contents fit within the plain ASCII set, so every character only needs one byte, and can be represented within char[] in CVI.

 

I have been pleased to see that the CVIXML library (or underlying MS DLL?) handles the 2-byte to 1-byte transition in parsing, but issues arise when the XML file contains characters that use 2 bytes.  Here is a hex view of such a case in the file with a 2-byte character (Greek alpha):

hex.png

There seems to be a best-effort attempt to find and correct this 2 byte to 1 byte transition for non-ASCII characters, but it is not always possible.  Specifically:

  • Greek alpha becomes 'a' which seems reasonable.
  • Greek delta becomes 'd' which seems reasonable.
  • Greek beta shows up as a beta, which can be found elsewhere in the ASCII set (0xDF) - nice!
  • Greek gamma becomes '?' - uh-oh!

The most problematic aspect of this is that we will lose uniqueness of the output values with all unsupported characters mapping to '?'.

 

The CVIXMLGetAttributeValue function returns 0 (success) in all these cases.

 

So my question is: Is there any way within the library to detect cases where the the XML file contains unsupported 2-byte characters?  Or would I need to separately parse that input file and look at it byte-by-byte?

 

0 Kudos
Message 1 of 4
(2,621 Views)

Hi Ian,

 

From my research, there does not seem to be any functionality in library which can handle greek characters in the way that you have mentioned. There may be a C function call (not specific to the CVIXML library) which can handle it but I'm not too sure of that. The best course of action will most likely be to separately parse the file and look like it byte by byte as you have mentioned.

 

Also, out of curiousity, what version of LabWindows/CVI are you using?

Applications Engineering
National Instruments
0 Kudos
Message 2 of 4
(2,592 Views)

SaileshK, thanks for the investigation and the reply. I had feared that.  This old application is still on the old compiler (~2010). Would you expect the result to be different with the latest version of CVI?

0 Kudos
Message 3 of 4
(2,537 Views)

Ian,

 

Unfortunately I haven't found any evidence that a newer version of LabWindows/CVI would result in a different outcome (no changelogs mention anything about the behavior you are seeing). However, if you attach your source code, I can try and see if a different result than what you are getting occurs!

Applications Engineering
National Instruments
0 Kudos
Message 4 of 4
(2,519 Views)