【问题标题】:How to print below xml code in XML?如何在 XML 中打印下面的 xml 代码?
【发布时间】:2018-04-23 10:21:56
【问题描述】:

以 xml 格式打印此 xml?

'<availabilityResponse xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
     <hotel id="123456789">
     <offers>
     <offer total="435.00" currency="EUR">
     </offer>
     </offers>
     </hotel>
     <errors>
     <error type=”E002”>Unknown hotel identifier: 32165487</error>
     <error type=”E002”>Unknown hotel identifier: 951357</error>
     </errors>
    </availabilityResponse>'

以 xml 格式打印此 xml

【问题讨论】:

  • 你已经打印出来了

标签: php xml codeigniter xml-parsing xmlhttprequest


【解决方案1】:
<?php

$string = <<<XML
<availabilityResponse xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
     <hotel id="123456789">
     <offers>
     <offer total="435.00" currency="EUR">
     </offer>
     </offers>
     </hotel>
     <errors>
     <error type="E002">Unknown hotel identifier: 32165487</error>
     <error type="E002">Unknown hotel identifier: 951357</error>
     </errors>
    </availabilityResponse>
XML;

header('Content-type: text/xml');
$xml = new SimpleXMLElement($string);

echo $xml->asXML();

这将输出格式为 xml 的 xml 文件。 您的 xml 中有一个错误,但我已修复。 &lt;error type="E002"&gt; 必须用双引号括起来,它是 xml 属性。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-14
    • 1970-01-01
    • 1970-01-01
    • 2019-08-15
    • 1970-01-01
    相关资源
    最近更新 更多