我将 Mink 与 Goutte webdriver 一起使用,试图用 XML 提要替换网站中表单的内容。
我编写了以下方法:
public function replaceField($field)
{
$baseText = '<?xml version="1.0" encoding="UTF-8"?>
<RiskAssessmentReply xmlns="http://test.com" >
<!-- ExternalId of the Order -->
<OrderId>TO_REPLACE</OrderId>
<RiskInfo>
<Actions>
<SystemAction>SystemAction</SystemAction>
<FinalAction>FinalAction</FinalAction>
</Actions>
<Score SystemScore="0"/>
</RiskInfo>
<!-- One of Accept, Manual_Accept, Reject, Cancel, or Ignore -->
<ResponseCode>Accept</ResponseCode>
<StoreId>TESTSTORE</StoreId>
</RiskAssessmentReply>';
$textWithOrderId = preg_replace('/TO_REPLACE/', $GLOBALS['ORDER_ID'], $baseText);
$this->getSession()->getPage()->fillField($field, $textWithOrderId);
}
其中基本上包含 XML 提要,然后我将其中的一部分替换为我事先拥有的订单 ID 并调用该函数fillField
与 Mink 捆绑在一起的函数。
问题是它不只是粘贴我提供的文本,而是通过在 " 符号之前设置反斜杠以一种奇怪的方式对其进行格式化,如下所示:
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
因此,当我尝试提交 XML 提要时,网站显示以下错误:
| Fatal error: Uncaught exception 'ErrorException' with message 'SimpleXMLElement::__construct(): Entity: line 1: parser error : String not started expecting ' or "'
我尝试使用stripslashes
PHP 中的方法,但它不起作用,就好像我在添加订单 ID 后尝试回显它显示原始 XML 没有斜杠,所以我猜有调用其他一些函数使用fillField
它时确实会在我的文本中添加反斜杠,但我无法找到它的来源。
有谁知道这种从"
到的转换\"
是在哪里进行的以避免它?
谢谢