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();

また、配列に配列要素が1つしかない場合でも、エラーはまったく発生しませんでした。

4

2 に答える 2

0

あなたはこれを試すことができますか:

$xml->formatOutput = false;

またはechoコマンド。そして、見て、エラーがあります。

于 2011-01-12T19:10:52.257 に答える
0

コード行(コピー&ペースト)を実行しましたが、エラーは発生しませんでした。有効なXMLドキュメントを印刷しました。他のコードにエラーがある可能性があります。

于 2011-01-12T19:12:38.643 に答える