2017-11-10 15 views
-4

このxmlをxml形式で印刷しますか? XML形式で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

+1

あなたはすでに印刷しています – splash58

答えて

0
<?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にエラーがありましたが、修正されました。 <error type="E002">は二重引用符で囲む必要があります。これはxml属性です。

関連する問題