14 Replies Latest reply on Dec 23, 2014 4:30 AM by beverly

    How to use curl and xml-response in the best way?

      Hi there,

       

      we have a VoIP-provider offers an API to get information about current users, unanswered calls and also to start calls out of applications (like Filemaker). To achieve that I have to place an curl-command to a https-url and read either json or xml.

       

      How can I handle that cross-plattform-wise and escpecially how can I read the answers without the use of any plugins? Do I have to parse xml myself looking for start and end tags etc.?

       

      Kind regards,

      Luna

        • 1. Re: How to use curl and xml-response in the best way?

          I learned meanwhile that there is a FMPXMLRESULT Grammar etc. But is this really the only way? This approach seems to be quite complex. Isn't there a way to load XML into an arrray like in PHP?

          • 2. Re: How to use curl and xml-response in the best way?
            agrooters

            Hi Luna - I've used Daniel Smith's excellent JSON module to parse the JSON returned by Survey Monkey's API in response to an HTTP POST request sent from FM.  As someone who was unfamiliar with both parsing JSON and with writing a stylesheet to import XML data, I found the JSON much easier to understand.  Check out the JSON to FM video on the page linked above to get an idea how it works.  Once you get the hang of it and can figure out the structure of the data that you're importing, it's pretty straightforward.

             

            Best regards - Amy

            • 3. Re: How to use curl and xml-response in the best way?
              beverly

              The grammar for FMP IMPORT, is not complex. It's similar to spreadsheet, by defining the fields and then displaying the rows of columns of data. Each COL in each ROW is correspoding to the FIELD in the METADATA. the DATA element is the actual content. If the DATA element repeats in a COL, then the field is a related field or repeating field. However, it's NOT recommended to import into related fields, as only the first related field may come in. Rather use multiple XSLT to import into multiple tables from the same XML source.

               

              OTOH, the XSLT can get quite complex to use for import or export with FileMaker XML. That's the power of it!

               

              Yes, it IS possilble to parse raw XML if brought into a field. Perhaps more complex than with XSLT, or perhaps not. It depends on the schema needing to be transformed.

               

              The data that you must parse may be in the formats:

                   <elementName>... data here ...</elementName>

                   <elementName attribute1="abc" attribute2="123" />

              or a combination of the element with data and with attrributes.

               

              The following functions are very useful for raw text parsing that is not very complex:

                   PatternCount()

                   Position()

                   Middle(), Left(), Right()

               

              (and more!)

               

              The use of variables to store snippets of your text and parse further are also great. Tips:

                   script parsing rather than trying to rely on calculations.

                   break it down into many steps, to make it easy to de-bug. if you want to combine (nest) the functions later, that's ok.

                   if you use a parsing routine many times in a script, consider creating a custom function (requires FMPAdvanced) & there may be custom functions available for this already!

               

              Beverly

              • 4. Re: How to use curl and xml-response in the best way?
                beverly

                yes, JSON if a common format that can be parsed. Along with Amy's recommendation of Daniel's post, these may help:

                 

                How to Parse JSON (or any other language) in FileMaker

                 

                FileMaker to JSON Converter : SFR FileMaker Blog

                 

                Beverly

                • 5. Re: How to use curl and xml-response in the best way?

                  Dear Beverly,

                   

                  thanks to all - but I am maybe not tec-savy enough to go the others ways mentioned here, though all are valuable! As in may case the XML (JSON also would be available) is not very nested and complex I will give it a try to write my own scripts do get the needed Information out of it.

                   

                  Btw: I have read about an advice a while ago NOT to use custom functions as there might be problems when migrating  or so. Are there any aspects to have in mind regarding custom functions?

                  • 6. Re: How to use curl and xml-response in the best way?
                    wimdecorte

                    Luna.media wrote:

                     

                     

                    Btw: I have read about an advice a while ago NOT to use custom functions as there might be problems when migrating  or so. Are there any aspects to have in mind regarding custom functions?

                     

                    Can you let us know where you read that?

                    Seems bogus to me.  We use Custom Functions extensively and do plenty of migrations.

                    • 7. Re: How to use curl and xml-response in the best way?
                      Todd Geist

                      It could have been from me.  I have been on record in several places with my distaste for "convenience" custom functions.  Convenience Custom Functions are things like "Null" for empty string.  They are general purpose function that basically save a few keystrokes or supposedly make code readable.  I don't buy that either of these things is worth the fragility of adding dependencies to your code, and making it less portable.

                       

                      However I don't think that Custom Functions  that parse XML or JSON are "convenience" functions. So I think a custom functions would be fine in this case.

                       

                      I would recommend that if you are parsing JSON you take a look at the JSON module mentioned elsewhere in this thread.

                      • 8. Re: How to use curl and xml-response in the best way?

                        Hi there,

                         

                        are there some hints how to get the the response loaded into a variable or field? Shall I use a webviewer and read the returned content in?

                        • 9. Re: How to use curl and xml-response in the best way?

                          Hi all,

                           

                          I found a way mayself. I defined an applescript (that means non-cross-plattform) and in it I save the result to a field in my database. Abstractly the applescript looks like this:

                           

                          "set Curl to \"curl https://api.test.de/api/get.xml -d 'api_key=...' -d 'further_variable=..' \"¶

                          do shell script Curl¶

                          set cell \"global_field_of_current_table\" of current record to result"

                           

                          If anyone knows a way with using the webviewer that might be more cross-plattform I would love to learn about that.

                          • 10. Re: How to use curl and xml-response in the best way?
                            mdenyse

                            Is there some reason you don't want to use the InsertFromURL script step?

                            • 11. Re: How to use curl and xml-response in the best way?
                              Benjamin Fehr

                              never had any issues with custom functions. I'ld be screwed if there would be any. I highly rely on them.

                              My favorite für XML-extraction:

                              GetBetween:

                              FileMaker Custom Function:getbetween(text, starttext, stoptext,occurrence)

                               

                              For XML-files, I use TROI FilePlugIn to load into field, then the GetBetween function can do the extractions job.

                              • 12. Re: How to use curl and xml-response in the best way?

                                Hi,

                                 

                                thanks for the custom function. It works great. Do you have any experience in elegantly getting possible attributes?

                                 

                                Luna

                                 

                                 

                                 

                                 

                                Am 23.12.2014 um 01:45 schrieb efficientbizz <noreply@filemaker.com>:

                                 

                                 

                                                                          

                                How to use curl and xml-response in the best way?

                                Antwort von efficientbizz in Discussions - Komplette Diskussion anzeigen

                                 

                                never had any issues with custom functions. I'ld be screwed if there would be any. I highly rely on them.

                                 

                                My favorite für XML-extraction:

                                 

                                GetBetween:

                                 

                                FileMaker Custom Function:getbetween(text, starttext, stoptext,occurrence)

                                 

                                 

                                 

                                For XML-files, I use TROI FilePlugIn to load into field, then the GetBetween function can do the extractions job.

                                 

                                Sie können auf diese Nachricht antworten, indem Sie diese E-Mail beantworten oder die Nachricht unter FileMaker Community aufrufen

                                Starten Sie eine neue Diskussion in Discussions per E-Mail oder unter FileMaker Community

                                Sie folgen How to use curl and xml-response in the best way? in diesen Aktivitätenlisten: Posteingang

                                Bearbeiten Sie Ihre Emailvoreinstellungen

                                 

                                FileMaker Developer Conference 2015 • Las Vegas, Nevada • July 20-23 • www.filemaker.com/devcon

                                 

                                • 13. Re: How to use curl and xml-response in the best way?
                                  Benjamin Fehr

                                  not elegant or sophisticated: With XML AND html, you always have attributes nested between any kind of start- and end-Tags.

                                  Example:

                                  <invoice:biller ean_party="7601001395329" zsr="F999901">

                                  <invoice:company>

                                  <invoice:companyname>EfficientBizz GmbH</invoice:companyname>

                                  <invoice:postal>

                                   

                                  getbetween(text, "<invoice::companyname>", </invoice::companyname>,1)

                                  => EfficientBizz GmbH

                                  No conflicts as long as Tags are unique! If not, the "occurrence" attribute can extract 1., 2., 3., …

                                  value (or repetition).

                                  Sometimes, it's necessary to embed one cf into another in order to do kind of filtering:

                                  getbetween(getbetween(text, "<invoice::biller>", </invoice::biller>,1),

                                  "<invoice::companyname>", </invoice::companyname>,1)


                                  When using this cf for plain text extraction (no XML, no html), carriage-return for 'stoptext' mostly works. Use char(10) OR char(13) instead of ¶.

                                  • 14. Re: How to use curl and xml-response in the best way?
                                    beverly

                                    There are several "xml" custom functions on the same site, Luna.

                                     

                                    _XMLGetValue ( xml ; xpath )

                                    Micah Woods, Scodigo, Inc.

                                    http://www.briandunning.com/cf/691

                                     

                                    XMLtag_sub ( nameValuePairs )

                                    Martin Spanjaard, Trias Digitaal

                                    http://www.briandunning.com/cf/1663

                                     

                                    ExtractData ( XML ; Attribute ; Instance )

                                    Andy Knasinski, NRG Software

                                    http://www.briandunning.com/cf/1

                                     

                                    GetXMLNode ( XML ; XPath )

                                    Michael Wallace, Richard Carlton Consulting

                                    http://www.briandunning.com/cf/976

                                     

                                    ... and more!

                                     

                                    I don't know if these will help with the attributes. Here are my "rules" that I used to create scripted extraction of attributes:

                                     

                                    • attributes are name/value pairs with a "=" between the name of the attribute and the value of the attribute

                                     

                                    • attribute values in valid XML should always be double-quoted

                                     

                                    • if you are parsing HTML, attribute values may have no quotes (single word only), be single-quoted or double-quoted

                                     

                                    • there is always some "whitespace" before the each name/value pair of attributes - this could be a single space or multiple spaces, and/or tab(s), and/or return

                                     

                                    So, it may depend on how complex your XML is, as to how complex your extraction is!

                                    Beverly