1 Reply Latest reply on Apr 17, 2013 2:58 PM by nrgsoft

    Import XML Document - Help

    fmdataweb

      Hi,

       

      I'm using FileMaker Pro v12 and the BaseElements plugin to retrieve XML data which I'm storing in a variable at present. I then need to parse out the XML into individual records and set the field values along the way. I've only worked with simple XML structures before and I'm getting stuck on this one and also not sure what is the best approach.

       

      Here's a sample of the XML:

       

      <?xml version="1.0" encoding="utf-8"?>

      <checkRepliesResponse xmlns="http://www.w3.org/1999">

      <result returned="2" remaining="0">

      <replies>

      <reply format="message" uid="96541" receiptId="94211794">

      <origin>1212587456</origin>

      <received>2013-02-18T22:35:02Z</received>

      <content>message 1</content>

      </reply>

      <reply format="message" uid="8745" receiptId="94721243">

      <origin>1212987654</origin>

      <received>2013-02-25T11:37:58Z</received>

      <content>message 2</content>

      </reply>

      </replies>

      </result>

      </checkRepliesResponse>

       

      In this example there are 2 records that I need to create and for each record I need to get the value of these elments:

       

      uid

      receiptId

      origin

      received

      content

       

      I could parse the XML but that doesn't seem like the most efficient approach. Should I export it as an xml file somehow and then import it back in using XSLT?

       

      If anyone has any examples of how to write a XSLT that can get both attributes and elements at the same time that would be great.

       

      What would be the best practice to import the XML?

       

      thanks,

      Steve

        • 1. Re: Import XML Document - Help
          nrgsoft

          Don't mess with export/import and XSLT. Using a simple custom function for parsing out the XML and another for getting text between.

           

          set variable $max=patterncount ( $xml ; "<reply" )

          if $max > 0

          set variable $ctr = 0

          loop

          set $ctr = $ctr + 1

          set variable $reply = GetTextBetween ( $xml ; "<reply" ; "</reply>" ; $ctr )

          set variable $uid= GetTextBetween ( $reply ; "uid=\"" ; "\"" ; 1 )

          set variable $receiptId= GetTextBetween ( $reply ; "receiptid=\"" ; "\"" ; 1 )

          set variable $origin= ExtractData ( $reply ; "origin" ; 1 )

          ...

          new record

          set field uid = $uid

          set field receiptid = $receiptid

          ...

          exit loop if $ctr = $max

          end loop

          end if