+ Initial implementation of property TDOMParseOptions.CanonicalForm. The only thing it does yet is ignoring the DTD.

* Fixed relevant tests.

git-svn-id: trunk@13914 -
This commit is contained in:
sergei 2009-10-20 22:09:51 +00:00
parent 169ef946a2
commit 0c50cfe10a
2 changed files with 41 additions and 13 deletions

View File

@ -67,7 +67,10 @@ type
FResolveExternals: Boolean;
FNamespaces: Boolean;
FDisallowDoctype: Boolean;
FCanonical: Boolean;
FMaxChars: Cardinal;
function GetCanonical: Boolean;
procedure SetCanonical(aValue: Boolean);
public
property Validate: Boolean read FValidate write FValidate;
property PreserveWhitespace: Boolean read FPreserveWhitespace write FPreserveWhitespace;
@ -78,6 +81,7 @@ type
property Namespaces: Boolean read FNamespaces write FNamespaces;
property DisallowDoctype: Boolean read FDisallowDoctype write FDisallowDoctype;
property MaxChars: Cardinal read FMaxChars write FMaxChars;
property CanonicalForm: Boolean read GetCanonical write SetCanonical;
end;
// NOTE: DOM 3 LS ACTION_TYPE enumeration starts at 1
@ -337,6 +341,7 @@ type
FDTDStartPos: PWideChar;
FIntSubset: TWideCharBuf;
FAttrTag: Cardinal;
FOwnsDoctype: Boolean;
FNSHelper: TNSSupport;
FWorkAtts: array of TPrefixedAttr;
@ -353,6 +358,7 @@ type
FResolveExternals: Boolean;
FNamespaces: Boolean;
FDisallowDoctype: Boolean;
FCanonical: Boolean;
FMaxChars: Cardinal;
procedure SkipQuote(out Delim: WideChar; required: Boolean = True);
@ -683,6 +689,30 @@ begin
CompareMem(ABuf.Buffer, Pointer(Arg), ABuf.Length*sizeof(WideChar));
end;
{ TDOMParseOptions }
function TDOMParseOptions.GetCanonical: Boolean;
begin
Result := FCanonical and FExpandEntities and FCDSectionsAsText and
{ (not normalizeCharacters) and } FNamespaces and
{ namespaceDeclarations and } FPreserveWhitespace;
end;
procedure TDOMParseOptions.SetCanonical(aValue: Boolean);
begin
FCanonical := aValue;
if aValue then
begin
FExpandEntities := True;
FCDSectionsAsText := True;
FNamespaces := True;
FPreserveWhitespace := True;
{ normalizeCharacters := False; }
{ namespaceDeclarations := True; }
{ wellFormed := True; }
end;
end;
{ TXMLInputSource }
constructor TXMLInputSource.Create(AStream: TStream);
@ -1421,6 +1451,7 @@ begin
FResolveExternals := FCtrl.Options.ResolveExternals;
FNamespaces := FCtrl.Options.Namespaces;
FDisallowDoctype := FCtrl.Options.DisallowDoctype;
FCanonical := FCtrl.Options.CanonicalForm;
FMaxChars := FCtrl.Options.MaxChars;
end;
@ -1438,6 +1469,8 @@ begin
ClearRefs(FIDRefs);
FNsAttHash.Free;
FNSHelper.Free;
if FOwnsDoctype then
FDocType.Free;
FNotationRefs.Free;
FIDRefs.Free;
@ -2100,7 +2133,10 @@ begin
SkipS;
finally
// DONE: append node after its name has been set; always append to avoid leak
Doc.AppendChild(FDocType);
if FCanonical then
FOwnsDoctype := True
else
Doc.AppendChild(FDocType);
FCursor := nil;
end;

View File

@ -88,10 +88,7 @@ var
nodeValue: DOMString;
length: Integer;
begin
// canonical form: PreserveWhitespace, Namespaces, NamespaceDeclarations = True;
// Entities, CDSections = False;
FParser.Options.PreserveWhitespace := True;
FParser.Options.Namespaces := True;
FParser.Options.CanonicalForm := True;
LoadStringData(doc, canonicform01);
begin
node := TDOMNode(doc).firstChild;
@ -152,10 +149,7 @@ var
nodeValue: DOMString;
length: Integer;
begin
// canonical form: PreserveWhitespace, Namespaces, NamespaceDeclarations = True;
// Entities, CDSections = False;
FParser.Options.PreserveWhitespace := True;
FParser.Options.Namespaces := True;
FParser.Options.CanonicalForm := True;
FParser.Options.IgnoreComments := True;
LoadStringData(doc, canonicform01);
begin
@ -198,8 +192,7 @@ var
divEl: TDOMElement;
node: TDOMNode;
begin
FParser.Options.PreserveWhitespace := True;
FParser.Options.Namespaces := True;
FParser.Options.CanonicalForm := True;
LoadStringData(doc, canonicform03);
divList := doc.getElementsByTagName('div');
@ -220,8 +213,7 @@ var
attrSpecified: Boolean;
attrValue: DOMString;
begin
FParser.Options.PreserveWhitespace := True;
FParser.Options.Namespaces := True;
FParser.Options.CanonicalForm := True;
LoadStringData(doc, canonicform03);
elemList := doc.getElementsByTagName('acronym');