12 Replies Latest reply on Nov 7, 2016 11:46 AM by malachydevlin

    export to XML

    malachydevlin

      Hi, I am not familiar with exporting to XML and ordered could I ask for help on how to export just 2 fields to this format XML

       

      <stockupdate>

          <sku>A20009</sku>

          <stock>0</stock>

        </stockupdate>

        <stockupdate>

        • 1. Re: export to XML
          wimdecorte

          To export to XML, FM uses one of its own XML grammars.  If you want the end result to be a different kind of XML grammars then you need to write an XSLT style sheet to do the transformation from one grammar into the other.  You can then specify the XSLT sheet as part of the export script step.

           

          Another option - given how simple the desired XML structure is - is to just create the XML in a script and treat it as a text parsing / merging exercise.

          • 2. Re: export to XML
            beverly

            Plus what Wim says.

             

            Is the example really as simple as that or are there other things that need to be in the XML? Is there a repeat of the pattern for each record? Is there another element that surrounds the repeats perhaps?  What are the names of the fields in your database?

             

            It may still be calculated, but the whole picture would be helpful.

             

            Sent from miPhone

            • 3. Re: export to XML
              malachydevlin

              yes parsing probably most simple.. thanks

              • 4. Re: export to XML
                David Moyer

                Hi,

                in my experience, you can export xml by simply populating a single text field in a single record.  This is because xml doesn't "care" about line-by-line formatting.  Export to .tab format but name your file filename.xml.

                In your one text field, start with <?xml version="1.0" encoding="UTF-8"?> and then add your xml.  In windows, I can double-click my filename.xml and it will open in Internet Explorer which clearly shows if the xml is well formed, or not.

                • 5. Re: export to XML
                  Menno

                  I would simply use export to xml using "FMPRESULTXML" grammar with an XSL-stylesheet.

                   

                  That xsl could in your case look as follows:

                   

                   

                  <?xml version="1.0" encoding="UTF-8"?>
                  <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                       
                  xmlns:fmp="http://www.filemaker.com/fmpxmlresult" version="1.0" exclude-result-prefixes="fmp"
                       
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                       
                  xsi:noNamespaceSchemaLocation="anyfile.xsd">
                       
                  <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
                       
                  <xsl:strip-space elements="*"/>
                       
                  <xsl:template match="fmp:FMPXMLRESULT">
                            
                  <stockupdates>
                                 
                  <xsl:for-each select="fmp:RESULTSET/fmp:ROW">
                                      
                  <stockupdate>
                                           
                  <sku>
                                                
                  <xsl:value-of select="fmp:COL[1]/fmp:DATA"/>
                                           
                  </sku>
                                           
                  <stock>
                                                
                  <xsl:value-of select="fmp:COL[2]/fmp:DATA"/>
                                           
                  </stock>
                                      
                  </stockupdate>
                                 
                  </xsl:for-each>
                            
                  </stockupdates>
                       
                  </xsl:template>
                  </xsl:stylesheet>

                   

                  Just copy and paste this into a text-document (change the extension to xsl) and export to an xml-file using this xsl and the result should look something like:

                  <?xml version="1.0" encoding="UTF-8"?>
                  <stockupdates xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                      
                  <stockupdate>
                          
                  <sku>X1234</sku>
                          
                  <stock>1</stock>
                      
                  </stockupdate>
                      
                  <stockupdate>
                          
                  <sku>X2341</sku>
                          
                  <stock>2</stock>
                      
                  </stockupdate>
                      
                  <stockupdate>
                          
                  <sku>X3412</sku>
                          
                  <stock>3</stock>
                      
                  </stockupdate>
                  </stockupdates>

                   

                  XML/XSL is very verbose, but it does not need to be difficult as you can see in the example here.

                   

                  For more info look at XSLT Introduction and XPath Tutorial and XML and XSLT

                   

                  Once I also started with a field and a script and as soon things got a little complicated I also had major problems. So I started learning xslt and never go back to fields and scripts. It is really worth the effort

                  1 of 1 people found this helpful
                  • 6. Re: export to XML
                    beverly

                    caveat: single field, single row export (with Tab-delimited) will still convert your CR (returns) to VT (vertical tab) and tabs to spaces:

                     

                    beverly

                    • 7. Re: export to XML
                      malachydevlin

                      Beverly,

                      yes I have hit this problem!

                      the xml file when sent to the web hosting company came back with errors says there are VT's in it.

                       

                      is there any easy solution to this, I guess I will have to use a stylesheet but not sure where to start with this and the one Menno posted doesn't seem to work.

                       

                      thanks

                      • 8. Re: export to XML
                        malachydevlin

                        Meeno, is the any chance you can help me with your stylesheet (I agree is the only way to do this now).

                        I used your example and get an error.

                        SAXparse exception, invalid document structure.

                         

                        thanks..

                        • 9. Re: export to XML
                          beverly

                          as an alternative, I wrote this article.

                           

                          It has an XSLT to export the single field. However there is a buglet with Windows and XML & XSLT. So I appended the article with a way to push the single field to one field, many records, so that standard tab-separated can be used and avoid the end-of-line problem. You will still have a problem if there are tab characters in the single-field-many-records, as they will not export exactly as in the field. So, there are many plug-ins (even free ones!) that can push your field contents and preserve your characters as you entered them (including the CRLF, if so desired).

                           

                          beverly

                          • 10. Re: export to XML
                            malachydevlin

                            Beverly, thanks for this, I used your stylesheet for a single field export which seems to have worked a treat, also it has worked by using export records (not export field contents) as this is a server script and the later isn't an option.

                            So to do this I just showed any 1 record and exported the global field using your XSL & it looks good.

                             

                            thanks..

                            • 11. Re: export to XML
                              Malcolm

                              This may be a problem caused by data within your export fields. I've cut and pasted Menno's solution and it worked perfectly for the export on my data.

                              • 12. Re: export to XML
                                malachydevlin

                                yes not sure what is going on but I got a solution that seems to work.. fingers crossed.. thanks.