1. Moshe Tangi
  2. PowerBuilder
  3. Monday, 30 August 2021 15:56 PM UTC

Hello all

 

I am trying to read an xml file from my app - just using the standard way . fileopen , fileread , pos and mid to get the data .

The file contains Hebrew letters which shown on screen as symbols . 

I have tried encoding ans so on but nothig helps .

if i open the file with notepad / explorer its looks great.

 

What can i do ? 

you can see the files attached below how the file  looks like  opend in explorer and after reading it into my app 

 

I am using pb2019 R3 build 2670 , windows 10 

 

any ideas ?

 

Thanks

 

Attachments (2)
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Monday, 30 August 2021 16:17 PM UTC
  2. PowerBuilder
  3. # 1

Hi Moshe;

   FWIW: If you open the XML file in NotePad and then select the FILE = > SAVEAS menu option in Notepad (you do not need to save it), the SaveAs dialogue will tell you what encoding format that the XML file is using.

HTH

Regards ... Chris

Comment
  1. Moshe Tangi
  2. Wednesday, 1 September 2021 13:03 PM UTC
i can see its UTF8 Encoding , in the notepad i can see the HEBREW characthers well , but opens the file within the app and populate it into a mle control

the charecthers are all unreadble

why ?
  1. Helpful
  1. Andreas Mykonios
  2. Wednesday, 1 September 2021 13:11 PM UTC
You don't need to specify encoding when opening a file. Fileopen will detect the right encoding. Anyway, if you try to use fileopen with wrong encoding, fileopen will return -1. This is documented to help file. Now, have you tried to use the font that notepad uses? Maybe this is a font issue. What font are you using?



Andreas.
  1. Helpful
  1. Chris Pollach @Appeon
  2. Wednesday, 1 September 2021 13:56 PM UTC
Hi Moshe ... remember that all Appeon PB controls work in UTF-16LE encoding. So your UTF-8 data needs to be converted in order to be displayed properly.
  1. Helpful 1
There are no comments made yet.
Mark Goldsmith Accepted Answer Pending Moderation
  1. Wednesday, 1 September 2021 15:26 PM UTC
  2. PowerBuilder
  3. # 2

Hi Moshe,

When following Chris' steps, if you're seeing that it's UTF-8 encoding then I suspect the file is UTF-8 WITHOUT BOM and that may be causing your issue. PowerBuilder can only correctly read a UTF-8 encoded file as long as it has the BOM (or Byte Order Mark) in place, although there is a way around this...see below.

@Andreas...you're mostly correct with the exception that PB will not properly detect UTF-8 without BOM and will default to ANSI which is likely what is causing Moshe's issue versus having the correct font.

Moshe, what I would suggest is that you follow Chris' steps to File, Save As but continue on to save it but when doing so change the encoding to UTF-8 with BOM. Then try to process the file. If it works then you have a few options for a more permanent solution:

  1.  Convert each file you wish to process using the above steps, but this may not be convenient/ efficient to have to do this each time,
  2.  See if the source/ provider of the file can have it created using UTF-8 with BOM,
  3.  Process it the way you have been but with these lines of code first (I have not included variable declarations but hopefully they are obvious):

li_file_handle = FileOpen(ls_path_filename, StreamMode!, Read!, LockReadWrite!, Append!, EncodingANSI!)
ll_chars_read = FileReadEx(li_file_handle,lblb_file_contents)
ls_contents_as_utf8 = String(lblb_file_contents, EncodingUTF8!)

The above opens the file with ANSI encoding, reads the file into a BLOB variable and then converts it into a String variable using the String function and specifying EncodingUTF8!  You can then process the contents of the String variable or write it back out to a text file with UTF-8 with BOM encoding and process it from there.

HTH...regards,

Mark

Comment
  1. John Fauss
  2. Wednesday, 1 September 2021 15:57 PM UTC
A very good explanation, Mark - Nicely done!
  1. Helpful
  1. Mark Goldsmith
  2. Wednesday, 1 September 2021 19:44 PM UTC
Thanks John :) , appreciate the feedback!
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.