2014-05-24 2 views
0

je la pièce suivante de code dans un contrôleur Laravel:Laravel et DOMDocument createDocumentFragment

public function toXMLSpreadsheet() 
{ 
    $doc = new DOMDocument(); 
    $doc->load('xmlspreadsheet.xml'); 
    $table = $doc->getElementsByTagName('Table')->item(0); 

    $applications = Application::all(); 
    foreach($applications as $application) 
    { 
     $f = $doc->createDocumentFragment(); 
     $f->appendXML(" 
      <Row> 
       <Cell><Data ss:Type=\"Number\">{$application->id}</Data></Cell> 
       <Cell><Data ss:Type=\"String\">{$application->nume}</Data></Cell> 
       <Cell><Data ss:Type=\"String\">{$application->prenume}</Data></Cell> 
       <Cell><Data ss:Type=\"String\">{$application->cnp}</Data></Cell> 
       <Cell><Data ss:Type=\"String\">{$application->adresa}</Data></Cell> 
       <Cell><Data ss:Type=\"String\">{$application->localitate}</Data></Cell> 
       <Cell><Data ss:Type=\"String\">{$application->judet}</Data></Cell> 
       <Cell><Data ss:Type=\"String\">{$application->telefon}</Data></Cell> 
       <Cell><Data ss:Type=\"String\">{$application->email}</Data></Cell> 
       <Cell><Data ss:Type=\"String\">{$application->nationalitate}</Data></Cell> 
      </Row> 
     "); 
     $table->appendChild($f); 
    } 

    $doc->save('Inscrisi.xml'); 

} 

et le fichier XML suivant:

<?xml version="1.0" encoding="UTF-8"?> 

<?mso-application progid="Excel.Sheet"?> 

<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" 
    xmlns:o="urn:schemas-microsoft-com:office:office" 
    xmlns:x="urn:schemas-microsoft-com:office:excel" 
    xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" 
    xmlns:html="http://www.w3.org/TR/REC-html40"> 

    <Worksheet ss:Name="Table1"> 
    <Table> 
    </Table> 
    </Worksheet> 
</Workbook> 

Quand je lance la fonction dans le contrôleur je reçois un erreur comme ceci:

production.ERROR: exception 'ErrorException' with message 'DOMDocumentFragment::appendXML(): namespace error : Namespace prefix ss for Type on Data is not defined' in E:\www\practica\app\controllers\ApplicationsController.php:105

Une idée pourquoi? L'espace de noms ss est défini dans le fichier XML.

Merci!

+0

modifier et ajouter le 'laravel' -tag – michi

Répondre

0

Vous devez définir l'espace de noms pour le préfixe 'ss' dans le fragment XML. Ajouter un xmlns: ss avec l'espace de noms correct à l'élément supérieur (ligne).