1
votes

I'm trying to edit an xml file in labVIEW for use by a .NET assembly later on in the program, however, when labview saves the file it changes the encoding. This prevents the .NET assembly from being able to open the file, since it needs to be in UTF-16 or UCS-2.

Is there a way to change the encoding in labview? I can do it manually in notepad++ but obviously that wont't work when I'm actually trying to use the program. I've tried using the labview "write to xml file.vi" which allows you to specify an encoding, but it just erases most of the file. I'm sorry if I'm being a bit vague here.

I've included a link to a drive folder with 3 xml files, which should be almost the same (at least they are when view in notepad++, not so much in drive), however the one called "working" can be loaded into my .NET assembly and the one called "postLabviewEdit" cannot. Notice that both have the same encoding declaration (UTF-16). If I take the one that isn't working (postLabviewEdit) and open it in notepad++ and click encoding>Encode in UCS-2 Little Endian and save it it starts working again (I included this one as well).

enter image description here

XML files before and after running through the program

3
If you want photos, edit the question to include links to them. Someone will then edit the question to have them directly in the question. - Makyen♦
There are multiple ways to edit XML in LabVIEW. Are you using the property nodes/invoke nodes of standard library Document object? Or EasyXML? Or LabXML? Or something else? - mzu
The way to change XML encoding depends on the library you are using to handle XML file - mzu
Mikhail, I'm using property nodes - LabviewMustDie
XML Document has a property: encoding - mzu

3 Answers

1
votes

All your files are UTF-16; but Working.xml have BOM and postLabviewEdit.xml has not (the inicial pair of bytes (377 376=UTF16-LE)).

$ od -c postLabviewEditEncodedInNotepad.xml | head -1
0000000 377 376   <  \0   ?  \0   x  \0   m  \0   l  \0      \0   v  \0
$ od -c postLabviewEdit.xml| head -1
0000000   <  \0   ?  \0   x  \0   m  \0   l  \0      \0   v  \0   e  \0
$ od -c Working.xml| head -1
0000000 377 376   <  \0   ?  \0   x  \0   m  \0   l  \0      \0   v  \0
localhost:Download$

Apparently .NET needs BOM?

3
votes

Ok So it looks like the problem was that LabVIEW was removing the BOM, as pointed out by JJoao. I created this VI to rewrite the file with the the BOM added to the beginning. Once I run the file through this it looks like the .NET assembly will accept it. Thanks for the help!

2
votes

The code provided has the following problem: you change the element of the XML file while saving it - race condition. Edit it like that: enter image description here