Closed qgribble closed 2 years ago
This plugin is not specific to Bootstrap, so it doesn't know about Bootstraps data escape option. What you can do is implement the callback function onCellHtmlData and change (escape) the cell content yourself.
Suppose you want to export this table:
If you implement the callback function onCellData:
{type: 'xml', onCellData: DoOnXmlCellData}
function DoOnXmlCellData(cell, row, col, data) {
if (data == null || data.length === 0) {
return data;
}
return data
.replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">")
.replace(/"/g, """)
.replace(/'/g, "'");
}
the result would be:
<?xml version="1.0" encoding="utf-8"?>
<tabledata>
<fields>
<field>column 1</field>
<field>column 2</field>
</fields>
<data>
<row id="1">
<column-1>A</column-1>
<column-2>Line 1
Line 2
Line 3
Line 4</column-2>
</row>
<row id="2">
<column-1>B</column-1>
<column-2>Line 1 TeableExport's Line 2 Line 3 contains ' and "</column-2>
</row>
<row id="3">
<column-1>C</column-1>
<column-2>Text with "unsafe" characters: <&></column-2>
</row>
<row id="4">
<column-1>D</column-1>
<column-2>Text content</column-2>
</row>
</data>
</tabledata>
If you implement the callback function onCellHtmlData:
{type: 'xml', onCellData: onCellHtmlData}
the result would be:
<?xml version="1.0" encoding="utf-8"?>
<tabledata>
<fields>
<field>column 1</field>
<field>column 2</field>
</fields>
<data>
<row id="1">
<column-1>A</column-1>
<column-2>Line 1<br> Line 2<br ng-if="!$last" class="ng-scope"> Line 3<br> Line 4</column-2>
</row>
<row id="2">
<column-1>B</column-1>
<column-2>Line 1 TeableExport's Line 2 Line 3 contains ' and "</column-2>
</row>
<row id="3">
<column-1>C</column-1>
<column-2>
<span>Text with "unsafe" characters: <&></span>
</column-2>
</row>
<row id="4">
<column-1>D</column-1>
<column-2>
<span>Text content</span>
</column-2>
</row>
</data>
</tabledata>
I have an issue with unsafe characters in cell content. I encode content using bootstrap-table's data-escape="true" feature. The problem is when I export to XML, the content is not escaped and I get an invalid xml document.
Anyone else had this problem? Is there a workaround?