XML 错误 在 PHP 中编程时,属性“值”需要打开引号
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12412269/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
XML error Open quote is expected for attribute "value" when programming in PHP
提问by J Noel
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!
我正在使用 PHP 编写 XML 请求,我遇到的问题是当我在 value 字段中使用变量时,它返回一个错误。但是,当我手动写入值时,它可以完美运行。在 field name='Serial_Number' 下,您将看到 $MREPSerial 是变量,假设在 PHP 中我们有 $MREPSerial = 'A-000-1042'; 下面的 XML 会出错。但是,如果我只用 XML 中的值替换 $MREPSerial ,它将成功。任何帮助将不胜感激。谢谢!
$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)
... echo 的返回响应(包括我回显的 XML)
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:
如果我将其更改为 '".$MREPSerial.",则回显的返回响应。是:
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>
回答by Mike Brant
You need quotes around the value attribute's actual value, like this:
您需要在 value 属性的实际值周围加上引号,如下所示:
<field name='Serial_Number' compOperator='Equals' value='{$MREPSerial}'></field>
回答by Dave
just saw your ";close tag...
刚刚看到你的";关闭标签...
try this for that line
为那条线试试这个
<field name='Serial_Number' compOperator='Equals' value='".$MREPSerial."'></field>

