8 Replies Latest reply on May 4, 2016 8:11 AM by electon

    Import XML - specify source

    Extensitech

      Doing a bit of xml "publish and subscribe", which overall is going pretty well.

       

      From one solution, I need to export a series of xml files, which get placed in a web-accessible directory. Done and done.

       

      From another solution, I need to import a small, one-record xml file from that directory, find out if there's an update, and if so, import the other xml files. Again, done and done.

       

      Now I'm trying to introduce a "rollback" option in the first solution. It's basically the same as the "update" in the second, but I'll import the xml data from the temp directory rather than the http path. Basically, same routine with just a different path variable.

       

      However, here's where I'm seeing something I don't understand. (The script step in question is a bit dialog/option heavy, so this might make more sense if you look at the step while reading this.):

       

      I'm in the "Import Records" script step, with "XML data" as the data source.

       

      For "specify xml data source", I'm using "Calculation" ("File or HTTP request specified by calculation"), and using $pth_fil, which, as I can see in my data viewer, currently equals filewin:/C:/Users/ccain/AppData/Local/Temp/S10.16/SYS.xml

       

      Now, I've had that variable pointing to an http address before this, and it's worked fine, but now that $pth_fil is a file path, it's not recognizing the file. The mapping shows nothing on the left, and if I run the step I get error 717.

       

      If I change the option from calculation to "file", and put in the variable, I get the same result (not really surprised).

       

      If I take the contents of the variable (filewin:/C:/Users/ccain/AppData/Local/Temp/S10.16/SYS.xml) and paste it into the File dialog, I can then see fields on the left of the mapping dialog.

       

      Also, if I manually select the file, it gets entered in the File list exactly as it appears in my variable.

       

      So... what's going on here?

       

      I need this file path to be a variable, since it's going to be performed client-side and paths change. I've tried a few file path syntax variations with no success, but my experience to date has been that if you can get the variable to look like what you get when manually selecting a file, there's a reasonable expectation that it'll work.

       

      Anyone encountered this before? Can anyone spot in my description what I might be doing wrong?

       

      Chris Cain

      Extensitech

        • 1. Re: Import XML - specify source
          user19752

          If I got you correctly, your problem is specifing file path as $variable then can't see left side of field mapping, since the variable has value only while running the script.

          To solve it, you can specify second line in file path using example file to import.

          • 2. Re: Import XML - specify source
            electon

            I'm guessing that because you're using it in the "File or HTTP" calculation it doesn't accept the standard filemaker path. The reason might be that the parser needs to guess which method to use or it will only prefer http style paths.

             

            Instead of:

            filewin:/C:/Users/ccain/AppData/Local/Temp/S10.16/SYS.xml

            Try:

            file:///C:/Users/ccain/AppData/Local/Temp/S10.16/SYS.xml

             

            It's a lot of maybies but need to run out and can't test it myself.

             

            on OSX its file:///Volumes/.../.../etc.xml  so that might apply here as well.

             

             

            HTH

            • 3. Re: Import XML - specify source
              Extensitech

              Good thought, but I was running my tests with debugger on, paused at the step, so the variable was set and I could see it in the data viewer.

               

              Chris Cain

              Extensitech

              • 4. Re: Import XML - specify source
                Extensitech

                I tried

                file:///C:/Users/ccain/AppData/Local/Temp/S10.16/SYS.xml

                and got error 718 instead of 717.

                 

                However, if I hard-code the file path under file as

                filewin:/C:/Users/ccain/AppData/Local/Temp/S10.16/SYS.xml

                I don't get either (or any) error. So, even though error 718 is "trouble parsing xml", the file's apparently good xml.

                 

                Still flummoxed...

                 

                Chris Cain

                Extensitech

                • 5. Re: Import XML - specify source
                  electon

                  So I've been playing around with this. Mind you I'm on OSX.

                   

                  It appears that when you specify a file path via the calculation...

                  FileMaker will already prepend the /Volumes/VolumeName part automatically within the calculation.

                  I could see that within the FM error box.

                   

                  Looks like the path is already relative to the main system volume.

                  In my case it works when I substitute out the VolumeName from the Get ( TemporaryPath ).

                  The path is then just as you type it in the terminal.

                  No need for filemac: prefix either

                   

                  Some examples:

                  /Macintosh HD/var/folders/fw/q35srk193ts_8cmx8x2wgh0w0000gn/T/S10.1/UBL-Invoice-2.1-Example.xml

                  Fail

                  /var/folders/fw/q35srk193ts_8cmx8x2wgh0w0000gn/T/S10.1/UBL-Invoice-2.1-Example.xml

                  Works

                   

                  Summarizing:

                  Get rid of any prefixes including the drive letter.

                  • 6. Re: Import XML - specify source
                    electon

                    And on Windows it's a little different.

                    I think I know what is happening. You need to let the parser know that the path is absolute, otherwise it will try and treat it like it was relative.

                    Absolute paths on Windows are DriveLetter:\   with the backslash

                     

                    Substitute ( $filePath ; "/C:/" ; "C:\\" )

                    will get you C:\Users/.../.../filename.xml

                    And that works.

                     

                    FileMaker when it comes to path via calculation does not follow it's own standards shown in other places.

                     

                     

                    Sorry, had to edit the Sub: Substitute ( $filePath ; "/C:/" ; "C:\\" )

                    Backslashes in wrong places

                    2 of 2 people found this helpful
                    • 7. Re: Import XML - specify source
                      Extensitech

                      Thanks, electon, I think that finally did it!

                       

                      Two lessons learned:

                       

                      First, even though when manually selecting a full path, you get "filewin:/" or "filemac:/" (presumably on the mac bit, developing on pc for pc, so not 100% sure), that bit needs to come off if you're using a variable in the calculation option.

                       

                      Second, unlike other imports, even if you have the variable set, you won't see values/columns on the left side of the mapping dialog. You can only see values/columns on the left with a hard-coded file path, so you need to enter the manual file path to do the mapping, then test your variable by actually running the import.

                       

                      Thank you, and thanks to all those who took a look. Mystery solved!

                       

                      Chris Cain

                      Extensitech

                      • 8. Re: Import XML - specify source
                        electon

                        Yes, the lack of consistency is confusing at best.

                        Extensitech wrote:

                         

                        Second, unlike other imports, even if you have the variable set, you won't see values/columns on the left side of the mapping dialog. You can only see values/columns on the left with a hard-coded file path, so you need to enter the manual file path to do the mapping, then test your variable by actually running the import.

                        That's true. You need a test file associated to map the fields.

                        For my xml imports I use XSL and just set it to Matching Names. No need for mapping.

                        But the data usually doesn't come from FileMaker.

                        Even when exporting data I try to come up with my own scheme so that it doesn't look strange to others and I can communicate the scheme to whoever wants the data.