9 Replies Latest reply on Feb 17, 2011 12:49 PM by Brett Elliott

    (CS5 JS) XML File Path with Accents etc.

    Brett Elliott

      Long time since I've needed to ask a question but I'm stuck on this one.

       

      I have a database of names (~10,000), and many of these names have accents etc. Each name has their own file path for a photo and this photo is imported into my templates via XML using a JavaScript. Unfortunately when I upgraded to CS5 my XML would no longer see accents and the like, instead it would replace these characters with chinese characters.

       

      Below is the XML that worked in CS4 (Windows 7 platform).

       

      <PHOTO href="file://prod/VEC/BulkCandidatePhotoImport/Borough of Queenscliffe 2008/Queenscliffe Borough Council/BUTLER, Hélène/BUTLER, Hélène.bmp" /></PHOTO>

       

      Below is the XML that CS5 exports if I have the data in the template, so it works in CS5.

       

      <PHOTO href="file:///V:/BulkCandidatePhotoImport/Borough%20of%20Queenscliffe%202008/Queenscliffe%20Boro ugh%20Council/BUTLER%2c%20H%c3%a9l%c3%a8ne/BUTLER%2c%20H%c3%a9l%c3%a8ne.bmp"></PHOTO>

       

      As you can see CS5 has added a load of character mapping in the file path.

       

      My question is. Can I code/adjust this so my CS4 version work in CS5?

       

      Please let me know if there is more information that is requried, thanks.

       

       

      Regards,

      Brett

        • 1. Re: (CS5 JS) XML File Path with Accents etc.
          herr mueller Level 1

          Search for escape() or unescape()

          These should get you where you need to go.

          1 person found this helpful
          • 2. Re: (CS5 JS) XML File Path with Accents etc.
            Brett Elliott Level 1

            Thanks for the tip. Can't believe we have to decode plain text now when it was never required. But I trust the devs have a good reason for doing this...

            • 3. Re: (CS5 JS) XML File Path with Accents etc.
              fivan Level 1

              I have the same problem.

              I read links from document and I put paths in the XML Structure as "href" attribute but accents first generates a "-29" error next IDCS5 crashes.
              escape() avoids the error and the crash but generats a strange character not permitted exporting XML in UTF8 or UTF16.

               

              The error happens on xmlAttributes.add() and ID crashes also if I use a Try {}catch(e) structure.

               

              any ideas?

              • 4. Re: (CS5 JS) XML File Path with Accents etc.
                fivan Level 1

                encodeURI()


                Create an UTF-8 ASCII encoded version of the path.

                Usefull for me.

                • 5. Re: (CS5 JS) XML File Path with Accents etc.
                  Brett Elliott Level 1

                  Hi herr mueller,

                   

                  I just had a long weekend so I didn't have the opportunity to test this until now and there is something screwy going on whith InDesign I'm sure.

                   

                  Here is what is happening.

                   

                  I have my XML (UTF-16 only from a VBA datasource, can't be done in UTF-8), I manually or automatically import and it asks for Hélène's photo instead of using the tagged link. I select the photo manually and then export the XML to see what I get. This is it:

                  H%c3%a9l%c3%a8ne.bmp (this works for the import XML as it is the correct hex)

                   

                   

                  Unfortunately if I unescape the text in IDCS5 I get this:

                  Hélène.bmp (looks wrong but if it works...)

                   

                   

                  So I tried to escape a manually typed Hélène from IDCS5 and this is what I get.

                  H%E9l%E8ne (this is the wrong hex, I think this may be a bug)

                   

                   

                  I have spoken to my software developers here and they are going to manually add the hex code for these special characters, unfortunately this adds another layer of complexity to a rather simple task. Thanks for your help guys.

                   

                   

                  Kind regards,

                  Brett

                  • 6. Re: (CS5 JS) XML File Path with Accents etc.
                    fivan Level 1

                    Hi Brett,

                     

                    Try using decodeURI() and encodeURI() insted of escape() and unescape()

                    • 7. Re: (CS5 JS) XML File Path with Accents etc.
                      Brett Elliott Level 1

                      Hi fivan,

                       

                      Thanks for the help! The encodeURI() seems to work fine if I use it on a string, eg encodeURI("Hélène"). Just like the esape() command I get the output "H%C3%A9l%C3%A8ne".

                       

                      Where I am not getting any progress is how to apply this to an XML tag as IDCS5 tries to import the XML before I can apply the command. And if I apply the command to the XML file name it only encodes the file name and not the contents.

                       

                      Here is the code I use to import the XML.

                       

                      var myTemplate = File("/v/......blah.indd"),
                      myFolder = Folder("/v/......blahblah"),
                      myDocs = myFolder.getFiles("*.xml");
                      for (i = 0; i < myDocs.length; i++) {

                           var newDoc = app.open(myTemplate);

                           newDoc.importXML(myDocs[i]);

                       

                      As you can see I am batch importing the XML into a template I have made and in that template there are taged frames. So by the time I get to the newDoc line it is already importing the XML without the encoding. If I apply the encodeURI() to myDocs[i] it only encodes the name of the XML and not the contents.

                       

                      So I guess my question has changed a little as I now need to be able to apply the encodeURI() command to a XML tag before or while it imports into the template? The only examples of this command that I have found apply to the file name only, is this the case?

                       

                      Kind regards,

                      Brett

                      • 8. Re: (CS5 JS) XML File Path with Accents etc.
                        fivan Level 1

                        Hi Brett

                         

                        Try to read the xml document as a txt and uncode the content.

                        Next overwrite the it and try to import as XML.

                         

                        I agree with you that it is unbelievable we have to decode plain text now when it was never required...

                         

                        Fivan

                        1 person found this helpful
                        • 9. Re: (CS5 JS) XML File Path with Accents etc.
                          Brett Elliott Level 1

                          Hi fivan,

                           

                          I have tried this without success. I am now in the process of re-writing my code and unlinking my image frames in the template. Then I'll try re-tagging and linking the photos through code after I apply the encodeURI command. It's a bit of a hack but it may work...

                           

                          Brett