Peter De Berdt
2006-Mar-24 17:33 UTC
[Rails] Parsing Filemaker 6 XML into something I can use
Hi One of our customers has a Filemaker database which needs to be accessed for some data. Using the Web Companion, I can query the database for an XML version of the data. I need to be able to push this data into an array of hashes, so I can access it in a more convenient way. Filemaker is able to provide me with 2 XML formats (DSO-XML and FMP-XML): *********** DSO-XML *********** <?xml version="1.0" encoding="UTF-8"?><FMPDSORESULT xmlns="http:// www.filemaker.com/fmpdsoresu lt"><ERRORCODE>0</ERRORCODE><DATABASE>Customers.fp5</ DATABASE><LAYOUT>XMLDump</LAYOUT><ROW MODID="0" RECORDID="13049791"><Company>Acme</ Company><Street>Somewherestreet 145 </Street><Postalcode>8200</Postalcode><City>Somecity</City></ROW><ROW MODID="0" RECORDID="13049792"><Company>Acme the second</ Company><Street>Somewherestreet 146 </Street><Postalcode>8500</Postalcode><City>Somecity Elsewhere</ City></ROW></FMPDSORESULT> *********** FMP-XML *********** <?xml version="1.0" encoding="UTF-8"?><FMPXMLRESULT xmlns="http:// www.filemaker.com/fmpxmlresult"><ERRORCODE>0</ERRORCODE><PRODUCT BUILD="9/10/2003" NAME="FileMaker Pro Web Companion" VERSION="6.0v2"/ ><DATABASE DATEFORMAT="d-M-yyyy" LAYOUT="XMLDump" NAME="Customers.fp5" RECORDS="26" TIMEFORMAT="k:mm:ss"/ ><METADATA><FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="Company" TYPE="TEXT"/><FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="Street" TYPE="TEXT"/><FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="Postalcode" TYPE="TEXT"/><FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="City" TYPE="TEXT"/></METADATA><RESULTSET FOUND="26"><ROW MODID="0" RECORDID="13049791"><COL><DATA>Acme</DATA></ COL><COL><DATA>Somewherestreet 145</DATA></COL><COL><DATA>8200</ DATA></COL><COL><DATA>Somecity</DATA></COL></ROW><ROW MODID="0" RECORDID="13049792"><COL><DATA>Acme the second</DATA></ COL><COL><DATA>Somewherestreet 146</DATA></COL><COL><DATA>8500</ DATA></COL><COL><DATA>Somecity Elsewhere</DATA></COL></ROW></ RESULTSET></FMPXMLRESULT> What would be the best way to get this into something I can use in my controller? I''ve been playing around with REXML, but I''m hitting walls here. Thanks in advance! Best regards Peter De Berdt
What "walls" are you hitting? As long as Filemaker is giving you valid xml, I would just parse it with REXML and then grab what you need with XPaths. http://www.germane-software.com/software/rexml/docs/tutorial.html b Peter De Berdt wrote:> Hi > > One of our customers has a Filemaker database which needs to be > accessed for some data. Using the Web Companion, I can query the > database for an XML version of the data. I need to be able to push this > data into an array of hashes, so I can access it in a more convenient > way. Filemaker is able to provide me with 2 XML formats (DSO-XML and > FMP-XML): > > *********** > DSO-XML > *********** > <?xml version="1.0" encoding="UTF-8"?><FMPDSORESULT xmlns="http:// > www.filemaker.com/fmpdsoresu > lt"><ERRORCODE>0</ERRORCODE><DATABASE>Customers.fp5</ > DATABASE><LAYOUT>XMLDump</LAYOUT><ROW > MODID="0" RECORDID="13049791"><Company>Acme</ > Company><Street>Somewherestreet 145 > </Street><Postalcode>8200</Postalcode><City>Somecity</City></ROW><ROW > MODID="0" RECORDID="13049792"><Company>Acme the second</ > Company><Street>Somewherestreet 146 > </Street><Postalcode>8500</Postalcode><City>Somecity Elsewhere</ > City></ROW></FMPDSORESULT> > > *********** > FMP-XML > *********** > <?xml version="1.0" encoding="UTF-8"?><FMPXMLRESULT xmlns="http:// > www.filemaker.com/fmpxmlresult"><ERRORCODE>0</ERRORCODE><PRODUCT > BUILD="9/10/2003" NAME="FileMaker Pro Web Companion" VERSION="6.0v2"/ > ><DATABASE DATEFORMAT="d-M-yyyy" LAYOUT="XMLDump" NAME="Customers.fp5" > RECORDS="26" TIMEFORMAT="k:mm:ss"/ ><METADATA><FIELD EMPTYOK="YES" > MAXREPEAT="1" NAME="Company" TYPE="TEXT"/><FIELD EMPTYOK="YES" > MAXREPEAT="1" NAME="Street" TYPE="TEXT"/><FIELD EMPTYOK="YES" > MAXREPEAT="1" NAME="Postalcode" TYPE="TEXT"/><FIELD EMPTYOK="YES" > MAXREPEAT="1" NAME="City" TYPE="TEXT"/></METADATA><RESULTSET > FOUND="26"><ROW MODID="0" RECORDID="13049791"><COL><DATA>Acme</DATA></ > COL><COL><DATA>Somewherestreet 145</DATA></COL><COL><DATA>8200</ > DATA></COL><COL><DATA>Somecity</DATA></COL></ROW><ROW MODID="0" > RECORDID="13049792"><COL><DATA>Acme the second</DATA></ > COL><COL><DATA>Somewherestreet 146</DATA></COL><COL><DATA>8500</ > DATA></COL><COL><DATA>Somecity Elsewhere</DATA></COL></ROW></ > RESULTSET></FMPXMLRESULT> > > What would be the best way to get this into something I can use in my > controller? I''ve been playing around with REXML, but I''m hitting walls > here. > > Thanks in advance! > > > Best regards > > Peter De Berdt > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Peter De Berdt
2006-Mar-25 08:02 UTC
[Rails] Parsing Filemaker 6 XML into something I can use
On 25 Mar 2006, at 08:10, Ben Munat wrote:> What "walls" are you hitting? As long as Filemaker is giving you > valid xml, I would just parse it with REXML and then grab what you > need with XPaths. > > http://www.germane-software.com/software/rexml/docs/tutorial.htmlThat''s exactly the kind of tutorial I was looking for. Thanks! Best regards Peter De Berdt
The Filemaker XML is something I find hard to use so I''ll be trying to export to Excel, then to CSV, then parse the CSV with either Ruby''s standard libraries or with fastercsv. If you export from Filemaker directly to CSV, it doesn''t give you the column headings, hence my exporting to Excel format first. There''s another gem called csv-mapper which I have no experience with, but it''s supposed to convert CSV to active record - exactly what I need. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Mar 6, 1:30 am, Michael Nissim <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> The Filemaker XML is something I find hard to use so I''ll be trying to > export to Excel, then to CSV, then parse the CSV with either Ruby''s > standard libraries or with fastercsv. If you export from Filemaker > directly to CSV, it doesn''t give you the column headings, hence my > exporting to Excel format first. There''s another gem called csv-mapper > which I have no experience with, but it''s supposed to convert CSV to > active record - exactly what I need. > > -- > Posted viahttp://www.ruby-forum.com/.It sounds like you may already have a solution but don''t want to RT*M. That being said have you considered using something like Nokogiri (http://nokogiri.org/) to parse the XML directly? I''ve had great success parsing both HTML and XML using it, in fact it seems to be the de facto parser used in the RoR community (someone correct me if I''m wrong on this). But the point is, Nokogiri would probably save you a couple steps and a lot of sanity if you intend to make going between them (Filemaker and RoR) a regular thing. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.