8 Replies Latest reply on Jul 29, 2016 5:59 AM by beverly

    UTF-8

    antoine_martin

      Hello,

       

      I've to upload a file to a external server which belongs to an administration.

       

      This external server accepts only files encoded in UTF-8

       

      So, i've copied the file example given by this administration in a field, after having changing the infos resquested by ... [phone number], for instance.

       

      Then, a script substitutes this [infos] by the contents of various fields.

       

      This calcultation is exported as a file with a suffix .xml

       

      As you can imagine, the external server of the administration doesn't accept this file.

       

      But if i open this file with "Text Wrangler", an info tells me the file is encoded in UTF-16 Endian.

       

      If i re-encode it, using Text Wrangler, in UTF-8, I can upload the file to without problem.

       

      So my question is, how having a calculation result encode in UTF-8 ?

       

      Anybody to help me ?

       

      Yes ? You're so kind !

       

      Antoine Martin

        • 1. Re: UTF-8
          beverly

          did you use Export Field Contents?

          https://www.filemaker.com/help/15/fmp/en/index.html#page/FMP_Help/export-field-contents.html

           

          Read the Description and Notes! You are getting UTF-16.

           

          I wrote an article about this:

          https://filemakerhacks.com/2012/09/23/export-field-contents-as-utf-8/

           

          Search this forum for an issue with Windows and this method.

          Alternative may be to use AppleScript or FileMaker Plug-in to get the correct UTF.

           

          I've also used a method to place (via loop script) each "line" (return-in-field") into a new record (one field) and export as tab-delimited. Because it is one field, the return will be correct and the UTF will be as selected in the Export Dialog. It's work, but does well.

          beverly

          1 of 1 people found this helpful
          • 2. Re: UTF-8
            Storganise

            HI Antoine,

             

            This is a strange request! I've downloaded TextWrangler to try and emulate your problem, but I can't find the info telling me the encoding.

             

            In any event, do you need to do it as an xml file? Can you not export to a Tab Separated or Comma Separated list? Then you could just do a quick applescript purge of the speech marks and commas as part of your script....

             

            Export the contents to a file and save the location in the field "Path"

             

            Then run this applescript...

             

            tell application "FileMaker Pro Advanced"

              tell current record

                 set docpath to cell "Path"

              end tell

            end tell

            tell application "TextEdit"

            activate

              open file docpath

              set documenttext to text of document 1

              set {oldTID, my text item delimiters} to {my text item delimiters, "\""}

              set textBits to text items of documenttext

              set my text item delimiters to ""

              set text of document 1 to textBits as text

              set my text item delimiters to oldTID

              save document 1

            set documenttext to text of document 1

              set {oldTID, my text item delimiters} to {my text item delimiters, ","}

              set textBits to text items of documenttext

              set my text item delimiters to ""

              set text of document 1 to textBits as text

              set my text item delimiters to oldTID

              save document 1

              close document 1

            end tell

             

            Will that do what you need?

             

            James

            • 3. Re: UTF-8
              Storganise

              Much better answer than mine, Beverly! Annoying that I was writing my response when yours was posted

              • 4. Re: UTF-8
                antoine_martin

                Many thanks James !

                You'll find bellow the page bottom of Text Wrangler with the code mentioned.

                TW.jpg

                 

                I'm gona try your AppleScript, during my holidays starting in two hours....

                So i'll reply from the seaside in few days !

                 

                Thank you again

                 

                Antoine

                • 5. Re: UTF-8
                  antoine_martin

                  Thank you Beverly for your help.

                  As you can see in my answer to James, my XML file is in UTF-16 and i need an UTF-8;

                  Yes i use the fonction export file contents, and I'm not confortable with the export of records...

                  I'll read slowly and precisely your post...

                  And return to you and suggestion, but ... after my holidays...

                  I already wear my short, palmes and tuba !

                   

                  Thanks again

                   

                  Antoine

                  • 6. Re: UTF-8
                    Mike Duncan

                    If using FM 14 or later, you can use the base64 encoding functions to create a text file directly from text in a field. Say you have your field with xml in it called "xml_field", then set a container field to this calc:

                     

                      Base64Decode ( Base64Encode ( xml_field ) ; "my_file.xml" )

                     

                    The resulting text file will be UTF-8 encoded text, you can export the field contents of that container field to get your file.

                     

                    Mike

                    • 7. Re: UTF-8
                      Mike Duncan

                      Also, here's a snippet that used applescript I've posted before for scripting to convert line endings...

                       

                      This example code puts a text file in a folder on your desktop. The conversion goes from UTF-16 little endian (what you get by exporting field contents from filemaker) to UTF-8.

                       

                      Set Variable [ $path ; "file:" & Get ( DesktopPath ) & "folder_name/" & "/my_utf_16_file.txt"]

                       

                      Export Field Contents [ my_field ; "$path" ]

                       

                      Perform Applescript ["do shell script \"iconv -f UTF-16LE -t UTF-8 " & Substitute ( $path ; ["file:" & Get ( SystemDrive ) ; "/"] ; ["my_utf_8_file.txt"; ""] ) & "my_utf_16_file.txt > " & Substitute ( $path ; ["file:" & Get ( SystemDrive ) ; "/"] ; ["my_utf_16_file.txt"; ""] ) & "my_utf_8_file.txt \""]

                       

                      Hope this helps.

                       

                      Mike

                      • 8. Re: UTF-8
                        beverly

                        yes, if you export as XML and use XSLT, you can specify UTF-8 in the output. However, it appears that you have a single field that you have calculated and/or script to populate.

                         

                        Here is an example of the single-field-many-records Export as I mentioned in the last paragraph of my previous post:

                         

                        beverly