日期:2014-05-17 浏览次数:20503 次
array(4)
{
["auth"]=> array(3)
{
["user"]=> string(8) "customer"
["password"]=> string(8) "password"
["context"]=> string(1) "4"
}
["owner"]=> array(2)
{
["user"]=> string(9) "customer2"
["context"]=> string(1) "4"
}
["language"]=> string(2) "en"
["task"]=> array(1)
{
["code"]=> string(4) "0130"
}
}
<?xml version="1.0" encoding="utf-8"?>
<request>
<auth>
<user>customer</user>
<password>password</password>
<context>4</context>
</auth>
<owner>
<user>customer2</user>
<context>4</context>
</owner>
<language>en</language>
<task>
<code>0130</code>
</task>
</request>
$ar=array
(
"auth"=> array
(
"user"=> "customer" ,
"password"=> "password" ,
"context"=> "4"
) ,
"owner"=> array
(
"user"=> "customer2" ,
"context"=> "4"
) ,
"language"=> "en" ,
"task"=> array
(
"code"=> "0130"
)
);
$doc = new DOMDocument('1.0','UTF-8');
// we want a nice output
$doc->formatOutput = true;
$root = $doc->createElement('request');
$root = $doc->appendChild($root);
foreach($ar as $title=>$title_v){
$title = $doc->createElement($title);
$title = $root->appendChild($title);
if(is_array($title_v)){
foreach($title_v as $k=>$v){
$k = $doc->createElement($k);
$k = $title->appendChild($k);
$text = $doc->createTextNode($v);
$text = $k->appendChild($text);
}
}else{
$text = $doc->createTextNode($title_v);
$text = $title->appendChild($text);
}
}
echo $doc->saveXML();