2016-06-08 2 views
-2
내가 XMLNS

방법의 xmlns

여기

내 배열 및 원하는 출력 XML

<?php 

$aray= array(
'foo' => '12', 
'boo' => '15', 
'bar' => 'test value', 
); 
?> 

원하는 출력

<xml version="1.0" encoding="utf-16"?> 
<opertaion xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">  
<foo xmlns="http://www.w3schools.com">12</foo>  
<boo xmlns="http://www.w3schools.com">15</boo> 
<bar xmlns="http://www.w3schools.com">test value</bar>  
</opertaion> 
와 PHP에서 배열에서 XML을 생성 할 필요가

와 PHP에서 배열에서 XML을 생성

답변

0

foreach()을 사용하여 배열 내의 모든 값을 반복하고 출력 변수에 데이터를 추가 할 수 있습니다.

<?php 
    $aray= array(
     'foo' => '12', 
     'boo' => '15', 
     'bar' => 'test value', 
    ); 

    $output = '<xml version="1.0" encoding="utf-16"><opertaion xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'; 

    foreach ($array as $key => $value) { 
     $output .= '<'.$key.' xmlns="http://www.w3schools.com">'.$value.'</'.$key.'>'; 
    } 

    $output .= '</opertaion>'; 
    echo $output; 
?> 
+1

페이지 XML 만 있습니까? 그렇다면'header ("Content-type : text/xml");를 사용해야합니다. –