douzhu6149 2017-11-10 08:31
浏览 33

如何在XML下打印xml代码?

print this xml in xml format ?

'<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>'

print this xml in xml format

  • 写回答

1条回答 默认 最新

  • dpxbc88022 2017-11-10 08:47
    关注
    <?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();
    

    This will output the xml file formated as xml. You had an error in your xml though which i fixed. <error type="E002"> must be in double-quotes it's xml-attribute.

    评论

报告相同问题?

悬赏问题

  • ¥15 对于这个问题的解释说明
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。