首页 > 解决方案 > 原始 PDF 的响应无法解析为 XML

问题描述

我从一个看起来像这样的 API 收到 XML 响应;

<?xml version="1.0" encoding="ISO-8859-1"?>
<tppxmlresponse>
<requestvalid>1</requestvalid>
<invoicevalid>1</invoicevalid>
<invoicepdf><![CDATA[%PDF-1.3
%“Œ‹ž ReportLab Generated PDF document http://www.reportlab.com
% 'BasicFonts': class PDFDictionary 
1 0 obj
% The standard fonts dictionary
<< /F1 2 0 R
 /F2 3 0 R
 /F3+0 11 0 R >>
endobj
(....)
startxref
110364
%%EOF
]]></invoicepdf></tppxmlresponse>

<invoicepdf>包含我要获取的原始 PDF。但是在响应上使用常规new SimpleXMLElement($response);会返回以下错误;

PHP Fatal error:  Uncaught Exception: String could not be parsed as XML in (...)

任何能够最好地访问 .xml 内容<invoicepdf>、剥离 XML 的想法都会很棒。谢谢!

标签: phpxml

解决方案


推荐阅读