8 Replies Latest reply on Apr 21, 2016 10:50 AM by kamal1234

    Building filemaker nested xml structure?

    kamal1234

      Dear Community Members,

       

      I am trying to build filemaker readable xml structure from the regular xml?

      I am using php to build it.

       

      $returnStr = '';

      $returnStr = $returnStr . '<?xml version="1.0" encoding="UTF-8" ?>';

      $returnStr = $returnStr . '<FMPXMLRESULT xmlns="http://www.filemaker.com/fmpxmlresult">';

      $returnStr = $returnStr . '<ERRORCODE>0</ERRORCODE>';

      $returnStr = $returnStr . '<PRODUCT BUILD="04-14-2016" NAME="FileMaker" VERSION="ProAdvanced 14.0v3"/>';

      $returnStr = $returnStr . '<DATABASE DATEFORMAT="M/d/yyyy" LAYOUT="" NAME="IMS.fmp12" RECORDS="1" TIMEFORMAT="h:mm:ss a"/>';

      $returnStr = $returnStr . '<METADATA>';

      $returnStr = $returnStr . '<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="Description" TYPE="TEXT"/>';

      $returnStr = $returnStr . '<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="PartNumber" TYPE="NUMBER"/>';

      $returnStr = $returnStr . '<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="QtyInPack" TYPE="NUMBER"/>';

      $returnStr = $returnStr . '<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="QtyAvailable" TYPE="NUMBER"/>';

      $returnStr = $returnStr . '<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="sellPrice" TYPE="NUMBER"/>';

      $returnStr = $returnStr . '<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="costPrice" TYPE="NUMBER"/>';

      $returnStr = $returnStr . '<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="lcd" TYPE="NUMBER"/>';

      $returnStr = $returnStr . '</METADATA>';

      $returnStr = $returnStr . '<RESULTSET FOUND="1">';

      $returnStr = $returnStr . '<ROW MODID="1" RECORDID="1">';

      $returnStr = $returnStr . '<COL>';

      $returnStr = $returnStr . '<DATA>'.trim($array_data['stockcheckresp']['part']['@attributes']['desc']).'</DATA>';

      $returnStr = $returnStr . '</COL>';

      $returnStr = $returnStr . '<COL>';

      $returnStr = $returnStr . '<DATA>'.trim($array_data['stockcheckresp']['part']['@attributes']['partno']).'</DATA>';

      $returnStr = $returnStr . '</COL>';

      $returnStr = $returnStr . '<COL>';

      $returnStr = $returnStr . '<DATA>'.trim($array_data['stockcheckresp']['part']['@attributes']['caseqty']).'</DATA>';

      $returnStr = $returnStr . '</COL>';

      $returnStr = $returnStr . '<COL>';

      $returnStr = $returnStr . '<DATA>'.trim($array_data['stockcheckresp']['part']['@attributes']['qtyavail']).'</DATA>';

      $returnStr = $returnStr . '</COL>';

      $returnStr = $returnStr . '<COL>';

      $returnStr = $returnStr . '<DATA>'.trim($array_data['stockcheckresp']['part']['@attributes']['sell']).'</DATA>';

      $returnStr = $returnStr . '</COL>';

      $returnStr = $returnStr . '<COL>';

      $returnStr = $returnStr . '<DATA>'.trim($array_data['stockcheckresp']['part']['@attributes']['cose']).'</DATA>';

      $returnStr = $returnStr . '</COL>';

      $returnStr = $returnStr . '<COL>';

      $returnStr = $returnStr . '<DATA>'.trim($array_data['stockcheckresp']['part']['@attributes']['lcd']).'</DATA>';

      $returnStr = $returnStr . '</COL>';

      $returnStr = $returnStr . '</ROW>';

      $returnStr = $returnStr . '</RESULTSET>';

      $returnStr = $returnStr . '</FMPXMLRESULT>';

       

      My above xml conversion is working correctly.

       

      I want to add data in a loop as a part of the above xml structure.

       

      How can I integrate following array into above filemaker xml?

       

      How do I define the metadata and column and data  for the structure below as it has multiple elements.

       

       

       

      [choice] => Array

                              (

                                  [0] => Array

                                      (

                                          [@attributes] => Array

                                              (

                                                  [lcd] => 12K

                                                  [partno] => 1548

                                                  [desc] => THROTTLE BDY

                                                  [linemfg] => BBK PERFORMANCE

                                              )

       

       

                                      )

       

       

                                  [1] => Array

                                      (

                                          [@attributes] => Array

                                              (

                                                  [lcd] => 226

                                                  [partno] => 1548

                                                  [desc] => STOP THROTTL

                                                  [linemfg] => WEATHERHEAD BRASS FITT

                                              )

       

       

                                      )

       

       

                                  [2] => Array

                                      (

                                          [@attributes] => Array

                                              (

                                                  [lcd] => 766

                                                  [partno] => 1548

                                                  [desc] => YOKE

                                                  [linemfg] => MOOG U-JOINTS

                                              )

       

       

                                      )

       

       

                                  [3] => Array

                                      (

                                          [@attributes] => Array

                                              (

                                                  [lcd] => 82P

                                                  [partno] => 1548

                                                  [desc] => IGNITOR PRES

                                                  [linemfg] => PERTRONIX

                                              )

       

       

                                      )

       

       

                                  [4] => Array

                                      (

                                          [@attributes] => Array

                                              (

                                                  [lcd] => VT

                                                  [partno] => 1548

                                                  [desc] => ORIGINALS

                                                  [linemfg] => V-TECH

                                              )

       

       

                                      )

       

       

                              )

       

      Thank you,

      Kamal.

        • 1. Re: Building filemaker nested xml structure?
          IanJempson

          You should take a look at some of the PHP classes for building XML they'll likely simplify things considerably. I've not done this in PHP but did do it in Ruby a few years back and it was pretty straightforward. I realise that's not a direct comparison as Ruby's a more expressive language but you certainly shouldn't need to do any string concatenation. Using XML classes will not only be simpler, but it will be much more robust.

          • 2. Re: Building filemaker nested xml structure?
            beverly

            yes and not only what Ian said. PHP can use XSLT to transform the xml you read into FMPXMLRESULT grammar.

            beverly

            • 3. Re: Building filemaker nested xml structure?
              kamal1234

              Hello Beverly,

               

              Thank you for looking into my problem. I tried a lot to find an example about how to write repeating elements or fields in FMPXMLRESULT grammar but could not get much help online.

               

              My following element is repeating

              [choice] => Array

                                      (

                                          [0] => Array

                                              (

                                                  [@attributes] => Array

                                                      (

                                                          [lcd] => 12K

                                                          [partno] => 1548

                                                          [desc] => THROTTLE BDY

                                                          [linemfg] => BBK PERFORMANCE

                                                      )

               

               

                                              )

               

               

                                          [1] => Array

                                              (

                                                  [@attributes] => Array

                                                      (

                                                          [lcd] => 226

                                                          [partno] => 1548

                                                          [desc] => STOP THROTTL

                                                          [linemfg] => WEATHERHEAD BRASS FITT

                                                      )

               

               

                                              )

               

              How can I write metadata and row column data for it. It you have brief example it will be great help.

              My idea is to build FileMaker Compatible XML and parse and store it using script rather then using import menus and tools in filemaker. Later I need to do some modification on this raw data.

               

              Thank you

              Kamal.

              • 4. Re: Building filemaker nested xml structure?
                kamal1234

                Finally, after 48 hours of extensive search, I found my answer on following xml document.

                 

                http://www.northcountryconsulting.com/sites/default/files/078973723X_ch24.pdf

                 

                In student parents detail, Parents tag is nested with first name, last name and parent tag. It is repeating for single student record for two times. This document shows how to convert it and display it into FMPXMLRESULT.

                 

                Thank you,

                Kamal.

                • 5. Re: Building filemaker nested xml structure?
                  beverly

                  Please give credit to the book/author:

                  http://www.quepublishing.com/store/special-edition-using-filemaker-9-9780789737236

                  Special Edition Using FileMaker 9

                  by Jesse Feiler

                   

                  beverly

                  • 6. Re: Building filemaker nested xml structure?
                    kamal1234

                    Yes, Absolutly I am thankful to every one who post to my question and people who write about Filemaker.

                    Basically, It is saving my job. I am more or less month old now with term Filemaker.

                    Daily I am struggling a lot with it but I am learning with every problem.

                     

                    Once again thank you.

                    Kamal.

                    • 7. Re: Building filemaker nested xml structure?
                      beverly

                      I did not see where your answer was using PHP (in the chapter from Jesse's book). Can you post what you finally did, so others may learn?

                      thanx,

                      beverly

                      • 8. Re: Building filemaker nested xml structure?
                        kamal1234

                        In my original response  ['choice'] has a nested xml elements. PartNumber, LCD, Description and Supplier has multiple values.

                        I did not understand how to write METADATA and ROW for repeating elements.

                         

                        In the following student example "Red" colour element for student is repeating for parents.

                        <?xml version=”1.0” encoding=”UTF-8” ?> <FMPXMLRESULT xmlns=”http://www.filemaker.com/fmpxmlresult”> 
                          <ERRORCODE>0</ERRORCODE> <PRODUCT BUILD=“8-11-2005” NAME=”FileMaker Pro” VERSION=“8.0v2”/> <DATABASE DATEFORMAT=”M/d/yyyy” LAYOUT=”” NAME=”Student.fp7” RECORDS=”1” 
                          TIMEFORMAT=”h:mm:ss a”/> <METADATA> 
                          <FIELD EMPTYOK=”YES” MAXREPEAT=”1” NAME=”NameFirst” TYPE=”TEXT”/> <FIELD EMPTYOK=”YES” MAXREPEAT=”1” NAME=”NameLast” TYPE=”TEXT”/> <FIELD EMPTYOK=”YES” MAXREPEAT=”1” NAME=”NameMiddle” TYPE=”TEXT”/> <FIELD EMPTYOK=”YES” MAXREPEAT=”1” NAME=”Address” TYPE=”TEXT”/> <FIELD EMPTYOK=”YES” MAXREPEAT=”1” NAME=”City” TYPE=”TEXT”/> <FIELD EMPTYOK=”YES” MAXREPEAT=”1” NAME=”State” TYPE=”TEXT”/> <FIELD EMPTYOK=”YES” MAXREPEAT=”1” NAME=”Zip” TYPE=”TEXT”/> 
                          <FIELD EMPTYOK=”YES” MAXREPEAT=”1” NAME=”County” TYPE=”TEXT”/> <FIELD EMPTYOK=”YES” MAXREPEAT=”1” NAME=”District” TYPE=”TEXT”/> <FIELD EMPTYOK=”YES” MAXREPEAT=”1” NAME=”School” TYPE=”TEXT”/> <FIELD EMPTYOK=”YES” MAXREPEAT=”1” NAME=”Parents” TYPE=”TEXT”/> 
                          </METADATA> <RESULTSET FOUND=”1”> 
                          <ROW MODID=”0” RECORDID=”1”> <COL><DATA>Jonathan</DATA></COL> <COL><DATA>Middlesex</DATA></COL> <COL><DATA>A</DATA></COL> <COL><DATA>123 Oak Way</DATA></COL> <COL><DATA>Bensenville</DATA></COL> <COL><DATA>AK</DATA></COL> <COL><DATA>09080-1001</DATA></COL> <COL><DATA>Hightower</DATA></COL> <COL><DATA>Sparta</DATA></COL> <COL><DATA>Bensenville Junior High</DATA></COL> <COL><DATA>Sharon Middlesex(Parent), 

                        Martin Middlesex (Parent)</DATA></COL> </ROW>

                          </RESULTSET> 
                        </FMPXMLRESULT> 

                         

                         

                        The only thing at all noteworthy is the treatment of the parent information. The inbound student information is not completely “flat.” The nested <parents> element almost implies a new table, in relational database terms. We could choose to handle it that way, and bring the parent information into a separate table, but we chose instead to flatten the parent data into a single field. This was more to illustrate a particular technique than because it’s actually a good idea to do that. Whether it really is a good idea depends on the application.

                         

                         

                        From the book chapter and example, I have decided to split my repeating element into another FMPXMLRESULT structure (below is the new structure). I am creating a temparary table to store repeating data and then process it as suggested by author. 

                         

                         

                        if (!empty($array_data['stockcheckresp']['part']['choice'])) {

                                $returnStr = '';

                                $returnStr = $returnStr . '<?xml version="1.0" encoding="UTF-8" ?>';

                                $returnStr = $returnStr . '<FMPXMLRESULT xmlns="http://www.filemaker.com/fmpxmlresult">';

                                $returnStr = $returnStr . '<ERRORCODE>0</ERRORCODE>';

                                $returnStr = $returnStr . '<PRODUCT BUILD="04-14-2016" NAME="FileMaker Pro" VERSION="ProAdvanced 14.0v3"/>';

                                $returnStr = $returnStr . '<DATABASE DATEFORMAT="M/d/yyyy" LAYOUT="" NAME="IMS.fmp12" RECORDS="1" TIMEFORMAT="h:mm:ss a"/>';

                                $returnStr = $returnStr . '<METADATA>';

                                $returnStr = $returnStr . '<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="PartNumber" TYPE="TEXT"/>';

                                $returnStr = $returnStr . '<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="LCD" TYPE="TEXT"/>';

                                $returnStr = $returnStr . '<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="Description" TYPE="TEXT"/>';

                                $returnStr = $returnStr . '<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="Supplier" TYPE="TEXT"/>';

                                $returnStr = $returnStr . '</METADATA>';

                                $returnStr = $returnStr . '<RESULTSET FOUND="'.count($array_data['stockcheckresp']['part']['choice']).'">';

                                $count = 0;

                                foreach ($array_data['stockcheckresp']['part']['choice'] as $arrValues) {

                                    $returnStr = $returnStr . '<ROW MODID="'.$count.'" RECORDID="'.$count.'">';

                                    $returnStr = $returnStr . '<COL>';

                                    $returnStr = $returnStr . '<DATA>'.trim($array_data['stockcheckresp']['part']['choice'][$count]['@attributes']['partno']).'</DATA>';

                                    $returnStr = $returnStr . '</COL>';

                                    $returnStr = $returnStr . '<COL>';

                                    $returnStr = $returnStr . '<DATA>'.trim($array_data['stockcheckresp']['part']['choice'][$count]['@attributes']['lcd']).'</DATA>';

                                    $returnStr = $returnStr . '</COL>';

                                    $returnStr = $returnStr . '<COL>';

                                    $returnStr = $returnStr . '<DATA>'.trim($array_data['stockcheckresp']['part']['choice'][$count]['@attributes']['desc']).'</DATA>';

                                    $returnStr = $returnStr . '</COL>';

                                    $returnStr = $returnStr . '<COL>';

                                    $returnStr = $returnStr . '<DATA>'.trim($array_data['stockcheckresp']['part']['choice'][$count]['@attributes']['linemfg']).'</DATA>';

                                    $returnStr = $returnStr . '</COL>';

                                    $returnStr = $returnStr . '</ROW>';

                                    $count = $count + 1;

                                }

                                $returnStr = $returnStr . '</RESULTSET>';

                                $returnStr = $returnStr . '</FMPXMLRESULT>';

                         

                         

                                echo $returnStr;

                         

                        I have copy past lot of code here but I hope it will be easier if anybody will read the post in sequence.

                        I hope it helps.

                         

                        Thank you

                        Kamal.