2

我有一个 POST 方法

$ab = $_POST['xml'];

xml数据如下:

<email CommunicationType="Email" SourceSystem="GPS" TemplatePageZone="" brand="THORN" channel="THORN" emailAddr="mallu@THORN.com" template="tttt_09999_TEST">
  <communicationTypes>
    <communicationType Name="EMAIL" Value="PETERS@THORN.com" isRequired="Y" />
    <communicationType MobileTemplateID="12345" Name="COMM" OptInUrl="OptInUrl" Value="1234567890" isPartialOrFull="" isRequired="Y" template="88888" />
  </communicationTypes>
  <name firstName="**SMITH&quot;** SON" lastName="" middleInitial="" />
  <order orderDate="05/16/2013" orderHeaderKey="287346JSDV" orderIdATG="THORN01-23423415" orderNoEOMS="THORN01-22324323015" >
    <creditCard card="" numbersss="" />
    <digitalCoupons digitalCouponTotal="0.00" />
    <lineItems />
  </order>
  <account atgProfileId="" cirisID="" info="" password="" />
  <comments />
</email>
$xmlmain = simplexml_load_string($ab);

$ab问题是 $xmlmain由于特殊字符而无法加载SMITH&quot;

史密斯被截断后的一切。我将带有变量的 EMAIL 发送$xmlmain给自己,然后我看到所有内容都被截断了。由于未读取 XML,这也会导致以下失败。

$template_XMLMAIN =  $xmlmain->attributes()->template;  //This should be tttt_09999_TEST

为什么我无法读取 XML?谢谢你。

PS:这是将 XML 发送给我的方式,不能将它从客户端更改给我。

4

1 回答 1

0

" 是需要首先用 " 编码的实体。

需要在创建 XML 流的地方进行编码,以便字符串如下所示:

<name firstName="**SMITH&amp;quot;** SON" lastName="" middleInitial="" />

...

或者:

$ab = preg_replac('/&/', '&amp;', $ab);
$xmlmain = simplexml_load_string($ab);
于 2013-05-19T21:53:09.547 回答