2013-04-26 66 views
0

我很初学PHP。我想动态创建一个XML文件,我知道如何做到这一点。但在这种情况下,在XML文件中,一个节点应包含属性“名称”,其值为$_POST变量。如何编写用于创建XML文件的PHP代码,该文件包含具有属性“名称”的节点。如何使用PHP创建XML

+1

重复:http://stackoverflow.com/questions/2038535/php-create-new -xml-file-and-write-data-to-it,http://stackoverflow.com/questions/3212982/need-to-write-xml-using-php-how – elclanrs 2013-04-26 04:53:33

+2

伙计, 我从这里得到了答案链接。这就是我需要的。 http://php.net/manual/en/domdocument.createattribute.php 谢谢。 – user2322331 2013-04-26 04:58:55

回答

0

它可能对你会有所帮助:

<?php 
// Send the headers 
header('Content-type: text/xml'); 
header('Pragma: public'); 
header('Cache-control: private'); 
header('Expires: -1'); 
echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>"; 

echo '<xml>'; 

// echo some dynamically generated content here 


echo '</xml>'; 

?> 

最后保存文件,.php扩展

0
As a solution to your problem please try executing following example code snippet 

The below code snippet is created on basis of assumption that there is a form for user registration containing fields such as email ,address depicting the procedure for dynamically generation of **xml** content using php 

<?php 
    $xmlstring='<xml>'; 
    if($_SERVER['REQUEST_METHOD']=='POST') 
    { 
     $xmlstring.='<user> 
    <email>'.$POST['email'].'</email> 
    <address>'.$_POST['address'].'</address> 
    </user>'; 
    } 
    $xmlstring.='</xml>'; 
    header('Content-type:text/xml'); 
    echo $xmlstring; 
    die; 
?>