XML writer: split CDATA sections at the ']]>' sequence.

git-svn-id: trunk@14186 -
This commit is contained in:
sergei 2009-11-15 16:35:13 +00:00
parent 60a9ef963d
commit 5c60f0e9e2

View File

@ -316,6 +316,7 @@ end;
const
AttrSpecialChars = ['<', '"', '&', #9, #10, #13];
TextSpecialChars = ['<', '>', '&'];
CDSectSpecialChars = [']'];
procedure TXMLWriter.ConvWrite(const s: WideString; const SpecialChars: TSetOfChar;
const SpecialCharCallback: TSpecialCharCallback);
@ -372,6 +373,19 @@ begin
end;
end;
procedure CDSectSpecialCharCallback(Sender: TXMLWriter; const s: DOMString;
var idx: Integer);
begin
if (idx <= Length(s)-2) and (s[idx+1] = ']') and (s[idx+2] = '>') then
begin
Sender.wrtStr(']]]]><![CDATA[>');
Inc(idx, 2);
// TODO: emit warning 'cdata-section-splitted'
end
else
Sender.wrtChr(s[idx]);
end;
procedure TXMLWriter.WriteNode(node: TDOMNode);
begin
case node.NodeType of
@ -598,7 +612,7 @@ begin
else
begin
wrtChars('<![CDATA[', 9);
wrtStr(TDOMCharacterData(node).Data);
ConvWrite(TDOMCharacterData(node).Data, CDSectSpecialChars, @CDSectSpecialCharCallback);
wrtChars(']]>', 3);
end;
end;