Question

I have a problem reading an exported file from FileMaker Pro and read/load it in PHP.

I'm using Codeigniter, but I can use pure/plain Php 5

I tried exporting in csv but having difficulties reading it, than I tried in xml, but the export is about 500MB size (...) and is difficult to loop thru the nodes.

Now I tried using html export from FileMaker and with Simple HTML DOM I tried this:

public function parse($file_name){

        include 'xml/simple_html_dom.php';

        // Create DOM from URL or file
        $html = file_get_html(base_url("xml/$file_name.htm"));

        foreach($html->find('th') as $header => $hr){
            echo $hr;
            foreach($html->find('td') as $content => $td){ 
                echo ($td == "<BR>") ? '': $td;
            }
        }        


    }

This goes pretty ok but can't read all the stuff in a way I can load line by line into the DB... Is there a best solution?

Was it helpful?

Solution

If you're trying to pull data out of a FileMaker XML record export you could use the SimpleXML tools like SimpleXMLElement to access the data within the nodes:

$string = <<<XML
<?xml version="1.0" encoding="UTF-8" ?>
<FMPXMLRESULT xmlns="http://www.filemaker.com/fmpxmlresult">
    <ERRORCODE>0</ERRORCODE>
    <PRODUCT BUILD="04-17-2014" NAME="FileMaker" VERSION="ProAdvanced 13.0v3"/>
    <DATABASE DATEFORMAT="M/d/yyyy" LAYOUT="" NAME="XMLTest.fmp12" RECORDS="3" TIMEFORMAT="h:mm:ss a"/>
    <METADATA>
        <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="id" TYPE="NUMBER"/>
        <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="test" TYPE="TEXT"/>
        <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="name" TYPE="TEXT"/>
    </METADATA>
    <RESULTSET FOUND="3">
        <ROW MODID="3" RECORDID="1">
            <COL>
                <DATA>1</DATA>
            </COL>
            <COL>
                <DATA>test</DATA>
            </COL>
            <COL>
                <DATA>Chris</DATA>
            </COL>
        </ROW>
        <ROW MODID="3" RECORDID="2">
            <COL>
                <DATA>2</DATA>
            </COL>
            <COL>
                <DATA>jaslfk;jad</DATA>
            </COL>
            <COL>
                <DATA>Ruthie</DATA>
            </COL>
        </ROW>
        <ROW MODID="3" RECORDID="3">
            <COL>
                <DATA>3</DATA>
            </COL>
            <COL>
                <DATA>iiiii</DATA>
            </COL>
            <COL>
                <DATA>Zoe</DATA>
            </COL>
        </ROW>
    </RESULTSET>
</FMPXMLRESULT>
XML;

// This is required for FileMaker record exports since they're namespaced
$string = str_replace('xmlns=', 'ns=', $string);

$xml    = new SimpleXMLElement($string);
$result = $xml->xpath('//RESULTSET');

echo "<pre>";

foreach($result[0]->children() as $row){

    echo "<ul>";

        // This shows how you can pull the specific attributes from a give node.
        echo "<li>record: " . $row->attributes()->RECORDID->__toString() . "</li>" ;
        echo "<ul>";

        // This shows how you can drill down to a specific node and pull a node value.
            foreach($row->COL as $column){
                echo "<li>" . $column->DATA->__toString() . "</li>" ;
            }

        echo "</ul>";
    echo "</ul>";
}

A couple of special notes:

  • The line $string = str_replace('xmlns=', 'ns=', $string); is required because FileMaker namespaces it's xml
  • I'm using xpath to grab the values, but you can also use the SimpleXMLIterator tool to walk through the structure as well

OTHER TIPS

I've had decent success using an XML export and the class described here:

http://thomasoandrews.com/wordpress/2011/02/24/parsing-huge-xml-exports-from-filemaker-with-php/

(Note - I'm not the author of this).

You're correct about XML adding a lot of overhead - the only thing you can do i think is to only export the fields you need.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top