Php Laravel和DOMDocument createDocumentFragment
我在Laravel控制器中有以下代码:Php Laravel和DOMDocument createDocumentFragment,php,xml,laravel,xml-spreadsheet,Php,Xml,Laravel,Xml Spreadsheet,我在Laravel控制器中有以下代码: public function toXMLSpreadsheet() { $doc = new DOMDocument(); $doc->load('xmlspreadsheet.xml'); $table = $doc->getElementsByTagName('Table')->item(0); $applications = Application::all(); foreach($app
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');
}
公共函数()
{
$doc=新的DOMDocument();
$doc->load('xmlseadsheet.xml');
$table=$doc->getElementsByTagName('table')->项(0);
$applications=Application::all();
foreach($applications作为$application)
{
$f=$doc->createDocumentFragment();
$f->appendXML(“
{$application->id}
{$application->nume}
{$application->prenume}
{$application->cnp}
{$application->adresa}
{$application->localate}
{$application->judet}
{$application->telefon}
{$application->email}
{$application->nationalite}
");
$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:异常“ErrorException”,消息为“DOMDocumentFragment::appendXML():命名空间错误:未在E:\www\practica\app\controllers\ApplicationController.php:105中定义数据类型的命名空间前缀ss”
知道为什么吗?命名空间ss
在XML文件中定义
谢谢大家! 您需要在XML片段中为“ss”前缀定义名称空间。将具有正确名称空间的xmlns:ss添加到顶部元素(行)。编辑并添加
laravel
-标记