0

我遇到了一个我无法解决的错误。

$unsortedArray = array (array ( 'profileId' => '32', 'profileMiniature' => '32' ,'firstName' => 'Sarmad', 'lastName' => 'Nekomanesh', 'numberOfMutualContacts' => '0' ), array ( 'profileId' => '37', 'profileMiniature' => '37', 'firstName' => 'Sophie', 'lastName' => 'Gronlund', 'numberOfMutualContacts' => '0' ) );

header('Content-type: text/xml');
$xml = new DOMDocument('1.0', 'utf-8');


foreach($unsortedArray as $v){
    $profiles = $xml->createElement('profiles');
    $xml->appendChild($profiles);
    $profile = $xml->createElement('profile');
    $profile->setAttribute('profileId', $v['profileId']);
    $profile->setAttribute('profileMiniature', $v['profileMiniature']);
    $profile->setAttribute('firstName', $v['firstName']);
    $profile->setAttribute('lastName', $v['lastName']);
    $profiles->appendChild($profile);
}


$xml->formatOutput = true;
echo $xml->saveXML();

当我在数组中只得到一个数组元素时,我完全没有错误。

4

2 回答 2

0

你能试试这个:

$xml->formatOutput = false;

回显命令。看看,有什么错误。

于 2011-01-12T19:10:52.257 回答
0

I ran your lines of code (copy&paste) and got no errors. It printed valid XML document. You probably have errors in other code.

于 2011-01-12T19:12:38.643 回答