2017-11-10 12 views
-4

이 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. xml에 오류가 있었지만 수정되었습니다. <error type="E002">은 큰 따옴표로 묶어 XML 속성이어야합니다.