9 Replies Latest reply on Apr 14, 2014 11:18 AM by beverly

    Extracting XML from FileMaker's XML

    mikewson

      I find that the several custom functions written to extract xml values work great if the xml is from web content. But NOT if the xml source is generated by FileMaker. I have tried ExtractData by Andy Knasinski and _XMLGetValue by Micah Woods. Both fail when trying grab any specific field's value. I'm baffled. I am working in FMP 13. Do these custom functions no longer work with FMP 13? Thanks in advance.

        • 1. Re: Extracting XML from FileMaker's XML
          beverly

          Extract for what purpose? The grammar for export can import into FileMaker directly. If you have another grammar/schema that it needs to be:

          1. Use XSLT

          Or

          2. Calculate what you want.

           

          Since FMPXMLRESULT can import into FileMaker, use it as the grammar for export as well.

           

          -- sent from my iPhone4 --

          Beverly Voth

          --

          • 2. Re: Extracting XML from FileMaker's XML
            mikewson

            Hi Beverly...nice to hear from you again!

            We  have a Ping system that verifies customer's subscription once a day, and passes some data back and forth. We used to connect thru FMP network connectivity (5003) but now use xml thru the 'Insert From URL' functionality. Basically we use the 'Insert From URL' to pack all the data that goes 'up' and then unpack it when it arrives. Then we repeat going the other direction.  We have a custom xml layouts at each end that only includes the fields we need to send. The 'Insert from URL' technique has proven to be dramatically faster and dramatically more reliable.  The issue here is that we have historically parsed out the field data separately for each field using messy calculations, which do work, but are a pain to set up for each new field.  Our plan is to streamline our scripts with a custom function so as to ease the setup time when we add a new field to the upstream or downstream systems.  Tnx for asking.

            • 3. Re: Extracting XML from FileMaker's XML
              beverly

              So, you are needing a custom function to parse FMPXMLRESULT grammar in XML source?

               

              Beverly

              • 4. Re: Extracting XML from FileMaker's XML
                mikewson

                I built a custom function over the weekend that successfully parses FileMaker's XML.  It never occured to me that FileMaker's XML would be different from the various websites XML that we have used. do you think anyone would be interested in this custom function?

                • 5. Re: Extracting XML from FileMaker's XML
                  beverly

                  Sure! Please post, mikewson.

                   

                  The FMPXMLRESULT grammar is relatively simple. Near the top is the METADATA and lists all the fields. How ever many FIELD elements, are the number of corresponding COL element in each ROW element.  The DATA element inside the COL element can be repeated, if the FIELD is a related field or repeating field. That's the tricky part, if you haven't worked it out in the Custom Function. Perhaps you can get some feedback.

                   

                  XSLT, of course can handle this.

                  Beverly

                  • 6. Re: Extracting XML from FileMaker's XML
                    mikewson

                    XSLT is not in my knowledge base!  Sigh....  Here is the custom function I wrote:

                     

                    Extract FMP XML Field Data

                    Parameters: XML, FieldName

                     

                    Let (

                    [

                    StartTagPosition = Position ( xml ; "<field name="& "\""& FieldName & "\"><data>" ; 1 ; 1) ;

                    LengthStartTag = Length ("<field name="& "\""& FieldName & "\"><data>") ;

                    StartDataPosition = StartTagPosition + LengthStartTag ;

                    EndDataPosition = Position ( xml ; "</" ; StartTagPosition ; 1 )

                     

                     

                    ] ;

                    Middle ( xml ; StartDataPosition ; EndDataPosition - StartDataPosition)

                    )

                     

                     

                    It works very well.

                    • 7. Re: Extracting XML from FileMaker's XML
                      beverly

                      To clarify you are NOT using the FMPXMLRESULT, but the FMPDSORESULT grammar, is that correct? If so, then your custom function works with that grammar only.

                      Also, per my previous advice on the DATA element, as it also can repeat within the FMPDSORESULT grammar, so be wary!!

                       

                      Remember that DSO is a deprecated grammar and cannot be used (directly) with import into FMP. However, you can transform to FMPXMLRESULT (with XSLT!) to Import. There may already be XSLT for this transformation. The Library is no longer available on the FMI website, but a google search may find one.

                       

                      Another custom function must be written to parse FMPXMLRESULT, as the one provided here will not work for that grammar.

                       

                       

                      Beverly

                      • 8. Re: Extracting XML from FileMaker's XML
                        mikewson

                        You have puzzled me Beverly.  We are merely using a single script step "Insert from URL".  We are not specifying any grammer at all.  We go to a special layout that has the fields we need and use the script step  "Insert from URL". We make the xml land in a field called XML Results.  It is incrediably fast (instantaneous) and then all we do is to parse out the data we need. That is where we use are new custom function. We did notice that that each field appears twice in the xml. The first time the attributes of the field are described, and the second time the data is included. Our custom function only grabs the second usage that includes the data we want.

                         

                        Is there something I am missing?

                         

                        TIA for all you help.  I look forward to seeing you again at DevCon.

                        • 9. Re: Extracting XML from FileMaker's XML
                          beverly

                          'Insert from URL' has to be calling something, right?

                           

                          and you referred to

                          xml source is generated by FileMaker.

                           

                          in your original post.

                           

                          can you post an example of your "URL" (obscure sensitive info)?

                           

                          The XML source as FileMaker knows is one of several grammars.

                          The FM PHP API uses 'fmresultset' grammar.

                          Custom web publishing can use 'fmresultset, FMPXMLRESULT, or FMPXMLLAYOUT' grammars.

                          IMPORT xml into FileMaker uses the FMPXMLRESULT grammar

                          Export xml from FileMaker also uses the FMPXMLRESULT (and deprecated FMPDSORESULT).

                           

                          If you are working with DDR, that's another "grammar/schema" in XML. And of course there is XML used within FileMaker other places not readily apparent (nor needs to be).

                           

                          So, my main question is what does your "xml source" look like? can you post some of it (notable the top several lines)? and/or the URL that you are using?