XML error Open quote is expected for attribute "value" when programming in PHP

J Noel picture J Noel · Sep 13, 2012 · Viewed 23.4k times · Source

Hello and thank you for your help,

I am using PHP to write an XML request, the problem I am having is when I use the variable in the value field, it returns an error. However when I write in the value manually it works perfectly. Under field name='Serial_Number' you will see the $MREPSerial is the variable, let's assume that in the PHP we have $MREPSerial = 'A-000-1042'; The below XML would give an error. However if i were to replace $MREPSerial with just the value in the XML it would be successful. Any help would be greatly appreciated. Thank you!

$MREPSerial  = htmlspecialchars(strtoupper($_POST['NSMREP']));
echo "Hi".$MREPSerial;
<ZohoCreator>
            <applicationlist>
                <application name='ajout-de-materiel'>
                    <formlist>
                        <form name='MREP'>
                            <update>
                                <criteria>
                                    <field name='Serial_Number' compOperator='Equals' value={$MREPSerial}></field>
                                    <reloperator>AND</reloperator>
                                    <field name='MREP_Type' compOperator='Equals' value='0'></field>                            
                                </criteria>
                                <newvalues>
                                    <field name='Is_being_Used' value='TRUE'></field>
                                </newvalues>
                            </update>    
                        </form>
                    </formlist>
                </application>
            </applicationlist>
        </ZohoCreator>";

... the return response on echo (including the XML i echoed)

A-000-1012HI! <?xml version="1.0" encoding="UTF-8" ?>
<response><errorlist><error><code>2830</code><message><![CDATA[Open quote is expected for attribute "value" associated with an  element type  "field".]]></message></error></errorlist></response>

the return response on echo if i change it to '".$MREPSerial." is:

A-000-1012HI! <?xml version="1.0" encoding="UTF-8" ?>
<response><result><form name="MREP"><update><criteria><field name="Serial_Number" compOperator="Equals" value=""></field><reloperator>AND</reloperator><field name="MREP_Type" compOperator="Equals" value="0"></field></criteria><newvalues><field name="Is_being_Used"><value><![CDATA[TRUE]]></value></field></newvalues> <status>Failure, No Records Found With Specified Criteria</status></update></form></result></response>

Answer

Mike Brant picture Mike Brant · Sep 13, 2012

You need quotes around the value attribute's actual value, like this:

<field name='Serial_Number' compOperator='Equals' value='{$MREPSerial}'></field>