2014-05-24 49 views
0

,我有以下的Laravel控制器一段代碼:Laravel和DOM文檔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'); 

} 

和下面的XML文件:

<?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> 

當我運行在控制器的功能,我得到一個像這樣的錯誤:

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

任何想法爲什麼?命名空間ss在XML文件中定義。

謝謝!

+0

編輯並添加'laravel' -tag – michi

回答

0

您需要爲XML片段中的'ss'前綴定義命名空間。將正確的命名空間添加到頂部元素(行)的xmlns:ss。