我正在尝试在 PHP 中解析订单导出 xml,但是当 xml 中包含卡号时我遇到了问题,因为它们是加密的。下面是 xml 的片段和我收到的错误。我正在使用 $xml = new SimpleXMLElement($ox->xml); 解析 xml $ox->xml 是将 xml 作为从 API 中提取的字符串。有没有办法在将它传递给 SimpleXML 之前从字符串中删除 cardnum?
XML 片段(您会注意到并非所有订单都有卡片编号):
<?xml version = "1.0" encoding="Windows-1252" standalone="yes"?>
<VFPDataSet>
<sqlresult>
<orderno>1001</orderno>
<custnum>1000</custnum>
<cl_key>WEBF12</cl_key>
<odr_date>2012-07-25T00:00:00</odr_date>
<hold_type/>
<perm_hold>false</perm_hold>
<sys_hold>false</sys_hold>
<ship_date>2012-07-25T00:00:00</ship_date>
<ccheck>G</ccheck>
<paymethod>CK</paymethod>
<cashonly>false</cashonly>
<cardnum>ÈòMh»ÚKj›Õ›Ïzs鄸“®ôLý[0¡ZÍ</cardnum>
<cardtype>VI</cardtype>
...
<edi>false</edi>
</sqlresult>
<sqlresult>
<orderno>1005</orderno>
<custnum>1001</custnum>
<cl_key>NEWCUST</cl_key>
<odr_date>2012-07-26T00:00:00</odr_date>
<hold_type/>
<perm_hold>false</perm_hold>
<sys_hold>false</sys_hold>
<ccheck/>
<paymethod>CK</paymethod>
<cashonly>false</cashonly>
<cardnum/>
<cardtype/>
...
<edi>false</edi>
</sqlresult>
</VFPDataSet>
错误:
Warning: SimpleXMLElement::__construct(): input conversion failed due to input error, bytes 0x90 0x03 0x51 0x3B in C:\inetpub\wwwroot\automa
te\exportOrdHeader.php on line 43
Warning: SimpleXMLElement::__construct(): input conversion failed due to input error, bytes 0x90 0x03 0x51 0x3B in C:\inetpub\wwwroot\automa
te\exportOrdHeader.php on line 43
Warning: SimpleXMLElement::__construct(): encoder errorEntity: line 1202: parser error : PCDATA invalid Char value 30 in C:\inetpub\wwwroot\
automate\exportOrdHeader.php on line 43
Warning: SimpleXMLElement::__construct(): <cardnum>╦å{├╛▲├Ü┬«↓-├┐v┬▒ in C:\inetpub\wwwroot\automate\exportOrdHeader.php on lin
e 43
Warning: SimpleXMLElement::__construct(): ^ in C:\inetpub\wwwroot\automate\exportOrdHeader.php on line 43
Warning: SimpleXMLElement::__construct(): Entity: line 1202: parser error : PCDATA invalid Char value 25 in C:\inetpub\wwwroot\automate\expo
rtOrdHeader.php on line 43
Warning: SimpleXMLElement::__construct(): <cardnum>╦å{├╛▲├Ü┬«↓-├┐v┬▒ in C:\inetpub\wwwroot\automate\exportOrdHeader.php on lin
e 43
Warning: SimpleXMLElement::__construct(): ^ in C:\inetpub\wwwroot\automate\exportOrdHeader.php on line 43
Warning: SimpleXMLElement::__construct(): Entity: line 1202: parser error : PCDATA invalid Char value 7 in C:\inetpub\wwwroot\automate\expor
tOrdHeader.php on line 43
Warning: SimpleXMLElement::__construct(): <cardnum>╦å{├╛▲├Ü┬«↓-├┐v┬▒ in C:\inetpub\wwwroot\automate\exportOrdHeader.php on lin
e 43
Warning: SimpleXMLElement::__construct(): ^ in C:\inetpub\wwwroot\automate\exportOrdHeader.php on line 43
Warning: SimpleXMLElement::__construct(): Entity: line 1202: parser error : Premature end of data in tag cardnum line 1202 in C:\inetpub\www
root\automate\exportOrdHeader.php on line 43
Warning: SimpleXMLElement::__construct(): <cardnum>╦å{├╛▲├Ü┬«↓-├┐v┬▒ in C:\inetpub\wwwroot\automate\exportOrdHeader.php on lin
e 43
Warning: SimpleXMLElement::__construct(): ^ in C:\inetpub\wwwroot\automate\exportOrdHeader.php on l
ine 43
Warning: SimpleXMLElement::__construct(): Entity: line 1202: parser error : Premature end of data in tag sqlresult line 1191 in C:\inetpub\w
wwroot\automate\exportOrdHeader.php on line 43
Warning: SimpleXMLElement::__construct(): <cardnum>╦å{├╛▲├Ü┬«↓-├┐v┬▒ in C:\inetpub\wwwroot\automate\exportOrdHeader.php on lin
e 43
Warning: SimpleXMLElement::__construct(): ^ in C:\inetpub\wwwroot\automate\exportOrdHeader.php on l
ine 43
Warning: SimpleXMLElement::__construct(): Entity: line 1202: parser error : Premature end of data in tag VFPDataSet line 2 in C:\inetpub\www
root\automate\exportOrdHeader.php on line 43
Warning: SimpleXMLElement::__construct(): <cardnum>╦å{├╛▲├Ü┬«↓-├┐v┬▒ in C:\inetpub\wwwroot\automate\exportOrdHeader.php on lin
e 43
Warning: SimpleXMLElement::__construct(): ^ in C:\inetpub\wwwroot\automate\exportOrdHeader.php on l
ine 43
Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in C:\inetpub\wwwroot\automate\exportOrdHeader.
php:43
Stack trace:
#0 C:\inetpub\wwwroot\automate\exportOrdHeader.php(43 ): SimpleXMLElement->__construct('<?xml version =...')
#1 {main}
thrown in C:\inetpub\wwwroot\automate\exportOrdHeader.php on line 43