0

PHPで注文エクスポートxmlを解析しようとしていますが、xmlに暗号化されているため、カード番号が含まれていると問題が発生します。以下は、xmlのスニペットと私が受け取っているエラーです。$ xml = new SimpleXMLElement($ ox-> xml);を使用しています。xmlを解析するには$ox->xmlは、APIから取得した文字列としてのxmlです。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 
4

1 に答える 1

0

この特定のケースの最も簡単な解決策は、正規表現で削除することです。

$xml = preg_replace('/<cardnum>.*?<\/cardnum>/s', '<cardnum>REMOVED</cardnum>', $xml);
于 2012-08-02T13:28:34.967 に答える