Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2011-08

Explicit encoding of LF in XML

4 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Reinier Olislagers

All,

Looking at multiline support of text/string cells for export to Excel XML format.

My code, such as:
    TDOMElement(FieldNode).SetAttribute('ss:Type', 'String');
    FNode :=
Foutputdoc.CreateTextNode(LeftStr(UTF8Decode(EF.Field.AsString), 32767));
writes out a cell like:

<Cell><Data ss:Type="String">First line.
Second line</Data></Cell>
(Separated by CR LF - changing it to only LF with a hex editor doesn't help)

Excel needs an encoded LF:
<Cell><Data ss:Type="String">First line.&#10;Second line</Data></Cell>

How can I produce that?

Thanks,
Reinier

Ludo Brands
to Reinier Olislagers
Show quoted text 21 lines
All, Looking at multiline support of text/string cells for export to Excel XML format. My code, such as: TDOMElement(FieldNode).SetAttribute('ss:Type', 'String'); FNode := Foutputdoc.CreateTextNode(LeftStr(UTF8Decode(EF.Field.AsString ), 32767)); writes out a cell like: <Cell><Data ss:Type="String">First line. Second line</Data></Cell> (Separated by CR LF - changing it to only LF with a hex editor doesn't help) Excel needs an encoded LF: <Cell><Data ss:Type="String">First line.&#10;Second line</Data></Cell> How can I produce that?
Uses strutils;
...
Foutputdoc.CreateTextNode(LeftStr(UTF8Decode(AnsiReplaceStr(AnsiReplaceStr(E
F.Field.AsString,#10,'&#10;'),#13,'')),32767));

Ludo

Reinier Olislagers
to Ludo Brands
Ludo Brands wrote 13 lines
> Excel needs an encoded LF: > <Cell><Data ss:Type="String">First line.&#10;Second line</Data></Cell> > > How can I produce that? > Uses strutils; ... Foutputdoc.CreateTextNode(LeftStr(UTF8Decode(AnsiReplaceStr(AnsiReplaceStr(E F.Field.AsString,#10,'&#10;'),#13,'')),32767)); Ludo

That's what I thought at first, too ;)

But the & gets encoded again by the XML unit and you get:
&amp;#10;
Ludo Brands
to Reinier Olislagers
Show quoted text 13 lines
> Uses strutils; > ... > Foutputdoc.CreateTextNode(LeftStr(UTF8Decode(AnsiReplaceStr(AnsiReplac > eStr(E > F.Field.AsString,#10,'&#10;'),#13,'')),32767)); > > Ludo > That's what I thought at first, too ;) But the & gets encoded again by the XML unit and you get: &amp;#10;

Of course....

Looking in XMLWrite, I don't see any solution. LF is a valid character in a text node while & isn't.

Ludo