Reputation: 237
I need to code a web service that creates a FM XML file.
The expected output file looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<FMPXMLRESULT xmlns="http://www.filemaker.com/fmpxmlresult">
<ERRORCODE>0</ERRORCODE>
<PRODUCT BUILD="27/11/2002" NAME="FileMaker Pro" VERSION="6.0Dv4"/>
<DATABASE DATEFORMAT="d.M.yyyy" LAYOUT="" NAME="Schlüssel Adresse für green" RECORDS="3" TIMEFORMAT="k:mm:ss"/>
<METADATA>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="Datum" TYPE="DATE"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="Sprache Typ" TYPE="TEXT"/>
...
</METADATA>
<RESULTSET FOUND="3">
<ROW MODID="0" RECORDID="1">
<COL>
<DATA>12.11.2012</DATA>
</COL>
...
</ROW>
</RESULTSET>
</FMPXMLRESULT>
This is my php code:
$xml = new SimpleXMLElement('<FMPXMLRESULT xmlns="http://www.filemaker.com/fmpxmlresult"></FMPXMLRESULT>');
$xml->addChild('ERRORCODE',0);
$xml->addChild('PRODUCT BUILD="27/11/2002" NAME="FileMaker Pro" VERSION="6.0Dv4"');
$xml->addChild('DATABASE DATEFORMAT="d.M.yyyy" LAYOUT=" " NAME="Schlüssel Adresse für green" RECORDS="3" TIMEFORMAT="k mm ss" ');
$node = $xml->addChild('METADATA');
$node->addChild('FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="Datum" TYPE="DATE"');
$node->addChild('FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="Sprache Typ" TYPE="TEXT"');
...
$node = $xml->addChild('RESULTSET FOUND="3"');
$node->addChild('FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="Datum" TYPE="DATE"');
There are two things that I can't get to work:
The TIMEFORMAT="k:mm:ss" in the DATABASE node provokes the following error. Removing the colons ':' solves the error message problem but won't produce the same file
error on line 2 at column 80: error parsing attribute name
As soon as there is 'FOUND="3"' AND a child in the RESULTSET, the RESULTSET node provokes an error. It does not cause any error if there is no child. No error if the FOUND="3" is removed.
This page contains the following errors:
error on line 2 at column 2199: expected '>'
Any help much appreciated!
Upvotes: 1
Views: 142
Reputation: 237
Solved both cases by using the
$node->addAttribute("...","...")
method that SimpleXML provides.
Upvotes: 1