|
@@ -146,7 +146,6 @@ type
|
|
TDOMNotationEx = class(TDOMNotation);
|
|
TDOMNotationEx = class(TDOMNotation);
|
|
TDOMDocumentTypeEx = class(TDOMDocumentType);
|
|
TDOMDocumentTypeEx = class(TDOMDocumentType);
|
|
TDOMElementDef = class;
|
|
TDOMElementDef = class;
|
|
- TDOMAttrDef = class;
|
|
|
|
|
|
|
|
TDTDSubsetType = (dsNone, dsInternal, dsExternal);
|
|
TDTDSubsetType = (dsNone, dsInternal, dsExternal);
|
|
|
|
|
|
@@ -289,13 +288,6 @@ type
|
|
|
|
|
|
TXMLReadState = (rsProlog, rsDTD, rsRoot, rsEpilog);
|
|
TXMLReadState = (rsProlog, rsDTD, rsRoot, rsEpilog);
|
|
|
|
|
|
- TAttrDefault = (
|
|
|
|
- adImplied,
|
|
|
|
- adDefault,
|
|
|
|
- adRequired,
|
|
|
|
- adFixed
|
|
|
|
- );
|
|
|
|
-
|
|
|
|
TElementContentType = (
|
|
TElementContentType = (
|
|
ctAny,
|
|
ctAny,
|
|
ctEmpty,
|
|
ctEmpty,
|
|
@@ -437,20 +429,6 @@ type
|
|
|
|
|
|
// Attribute/Element declarations
|
|
// Attribute/Element declarations
|
|
|
|
|
|
- TDOMAttrDef = class(TDOMAttr)
|
|
|
|
- private
|
|
|
|
- FTag: Cardinal;
|
|
|
|
- protected
|
|
|
|
- FExternallyDeclared: Boolean;
|
|
|
|
- FDefault: TAttrDefault;
|
|
|
|
- FEnumeration: array of WideString;
|
|
|
|
- function AddEnumToken(Buf: DOMPChar; Len: Integer): Boolean;
|
|
|
|
- function HasEnumToken(const aValue: WideString): Boolean;
|
|
|
|
- function Clone(AElement: TDOMElement): TDOMAttr;
|
|
|
|
- public
|
|
|
|
- property Tag: Cardinal read FTag write FTag;
|
|
|
|
- end;
|
|
|
|
-
|
|
|
|
TDOMElementDef = class(TDOMElement)
|
|
TDOMElementDef = class(TDOMElement)
|
|
public
|
|
public
|
|
FExternallyDeclared: Boolean;
|
|
FExternallyDeclared: Boolean;
|
|
@@ -2329,10 +2307,9 @@ begin
|
|
begin
|
|
begin
|
|
CheckName;
|
|
CheckName;
|
|
ExpectWhitespace;
|
|
ExpectWhitespace;
|
|
- AttDef := TDOMAttrDef.Create(doc);
|
|
|
|
|
|
+ AttDef := doc.CreateAttributeDef(FName.Buffer, FName.Length);
|
|
try
|
|
try
|
|
- AttDef.FExternallyDeclared := FSource.DTDSubsetType <> dsInternal;
|
|
|
|
- AttDef.FNSI.QName := doc.Names.FindOrAdd(FName.Buffer, FName.Length);
|
|
|
|
|
|
+ AttDef.ExternallyDeclared := FSource.DTDSubsetType <> dsInternal;
|
|
// In case of duplicate declaration of the same attribute, we must discard it,
|
|
// In case of duplicate declaration of the same attribute, we must discard it,
|
|
// not modifying ElDef, and suppressing certain validation errors.
|
|
// not modifying ElDef, and suppressing certain validation errors.
|
|
DiscardIt := Assigned(ElDef.GetAttributeNode(AttDef.Name));
|
|
DiscardIt := Assigned(ElDef.GetAttributeNode(AttDef.Name));
|
|
@@ -2341,7 +2318,7 @@ begin
|
|
|
|
|
|
if CheckForChar('(') then // [59]
|
|
if CheckForChar('(') then // [59]
|
|
begin
|
|
begin
|
|
- AttDef.FDataType := dtNmToken;
|
|
|
|
|
|
+ AttDef.DataType := dtNmToken;
|
|
repeat
|
|
repeat
|
|
SkipWhitespace;
|
|
SkipWhitespace;
|
|
CheckName([cnToken]);
|
|
CheckName([cnToken]);
|
|
@@ -2364,7 +2341,7 @@ begin
|
|
end;
|
|
end;
|
|
if Found and SkipWhitespace then
|
|
if Found and SkipWhitespace then
|
|
begin
|
|
begin
|
|
- AttDef.FDataType := dt;
|
|
|
|
|
|
+ AttDef.DataType := dt;
|
|
if (dt = dtId) and not DiscardIt then
|
|
if (dt = dtId) and not DiscardIt then
|
|
begin
|
|
begin
|
|
if Assigned(ElDef.IDAttr) then
|
|
if Assigned(ElDef.IDAttr) then
|
|
@@ -2406,18 +2383,18 @@ begin
|
|
end;
|
|
end;
|
|
StoreLocation(FTokenStart);
|
|
StoreLocation(FTokenStart);
|
|
if FSource.Matches('#REQUIRED') then
|
|
if FSource.Matches('#REQUIRED') then
|
|
- AttDef.FDefault := adRequired
|
|
|
|
|
|
+ AttDef.Default := adRequired
|
|
else if FSource.Matches('#IMPLIED') then
|
|
else if FSource.Matches('#IMPLIED') then
|
|
- AttDef.FDefault := adImplied
|
|
|
|
|
|
+ AttDef.Default := adImplied
|
|
else if FSource.Matches('#FIXED') then
|
|
else if FSource.Matches('#FIXED') then
|
|
begin
|
|
begin
|
|
- AttDef.FDefault := adFixed;
|
|
|
|
|
|
+ AttDef.Default := adFixed;
|
|
ExpectWhitespace;
|
|
ExpectWhitespace;
|
|
end
|
|
end
|
|
else
|
|
else
|
|
- AttDef.FDefault := adDefault;
|
|
|
|
|
|
+ AttDef.Default := adDefault;
|
|
|
|
|
|
- if AttDef.FDefault in [adDefault, adFixed] then
|
|
|
|
|
|
+ if AttDef.Default in [adDefault, adFixed] then
|
|
begin
|
|
begin
|
|
if AttDef.DataType = dtId then
|
|
if AttDef.DataType = dtId then
|
|
ValidationError('An attribute of type ID cannot have a default value',[]);
|
|
ValidationError('An attribute of type ID cannot have a default value',[]);
|
|
@@ -2950,21 +2927,21 @@ procedure CheckValue;
|
|
var
|
|
var
|
|
AttValue, OldValue: WideString;
|
|
AttValue, OldValue: WideString;
|
|
begin
|
|
begin
|
|
- if FStandalone and AttDef.FExternallyDeclared then
|
|
|
|
|
|
+ if FStandalone and AttDef.ExternallyDeclared then
|
|
begin
|
|
begin
|
|
OldValue := Attr.Value;
|
|
OldValue := Attr.Value;
|
|
- TDOMAttrDef(Attr).FDataType := AttDef.FDataType;
|
|
|
|
|
|
+ Attr.DataType := AttDef.DataType;
|
|
AttValue := Attr.Value;
|
|
AttValue := Attr.Value;
|
|
if AttValue <> OldValue then
|
|
if AttValue <> OldValue then
|
|
StandaloneError(-1);
|
|
StandaloneError(-1);
|
|
end
|
|
end
|
|
else
|
|
else
|
|
begin
|
|
begin
|
|
- TDOMAttrDef(Attr).FDataType := AttDef.FDataType;
|
|
|
|
|
|
+ Attr.DataType := AttDef.DataType;
|
|
AttValue := Attr.Value;
|
|
AttValue := Attr.Value;
|
|
end;
|
|
end;
|
|
// TODO: what about normalization of AttDef.Value? (Currently it IS normalized)
|
|
// TODO: what about normalization of AttDef.Value? (Currently it IS normalized)
|
|
- if (AttDef.FDefault = adFixed) and (AttDef.Value <> AttValue) then
|
|
|
|
|
|
+ if (AttDef.Default = adFixed) and (AttDef.Value <> AttValue) then
|
|
ValidationError('Value of attribute ''%s'' does not match its #FIXED default',[AttDef.Name], -1);
|
|
ValidationError('Value of attribute ''%s'' does not match its #FIXED default',[AttDef.Name], -1);
|
|
if not ValidateAttrSyntax(AttDef, AttValue) then
|
|
if not ValidateAttrSyntax(AttDef, AttValue) then
|
|
ValidationError('Attribute ''%s'' type mismatch', [AttDef.Name], -1);
|
|
ValidationError('Attribute ''%s'' type mismatch', [AttDef.Name], -1);
|
|
@@ -2997,7 +2974,7 @@ begin
|
|
FCursor := attr;
|
|
FCursor := attr;
|
|
ExpectAttValue;
|
|
ExpectAttValue;
|
|
|
|
|
|
- if Assigned(AttDef) and ((AttDef.FDataType <> dtCdata) or (AttDef.FDefault = adFixed)) then
|
|
|
|
|
|
+ if Assigned(AttDef) and ((AttDef.DataType <> dtCdata) or (AttDef.Default = adFixed)) then
|
|
CheckValue;
|
|
CheckValue;
|
|
end;
|
|
end;
|
|
|
|
|
|
@@ -3049,11 +3026,11 @@ begin
|
|
|
|
|
|
if AttDef.Tag <> FAttrTag then // this one wasn't specified
|
|
if AttDef.Tag <> FAttrTag then // this one wasn't specified
|
|
begin
|
|
begin
|
|
- case AttDef.FDefault of
|
|
|
|
|
|
+ case AttDef.Default of
|
|
adDefault, adFixed: begin
|
|
adDefault, adFixed: begin
|
|
- if FStandalone and AttDef.FExternallyDeclared then
|
|
|
|
|
|
+ if FStandalone and AttDef.ExternallyDeclared then
|
|
StandaloneError;
|
|
StandaloneError;
|
|
- Attr := AttDef.Clone(Element);
|
|
|
|
|
|
+ Attr := TDOMAttr(AttDef.CloneNode(True));
|
|
Element.SetAttributeNode(Attr);
|
|
Element.SetAttributeNode(Attr);
|
|
ValidateAttrValue(Attr, Attr.Value);
|
|
ValidateAttrValue(Attr, Attr.Value);
|
|
end;
|
|
end;
|
|
@@ -3273,51 +3250,6 @@ begin
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
-{ TDOMAttrDef }
|
|
|
|
-
|
|
|
|
-function TDOMAttrDef.AddEnumToken(Buf: DOMPChar; Len: Integer): Boolean;
|
|
|
|
-var
|
|
|
|
- I, L: Integer;
|
|
|
|
-begin
|
|
|
|
- // TODO: this implementaion is the slowest possible...
|
|
|
|
- Result := False;
|
|
|
|
- L := Length(FEnumeration);
|
|
|
|
- for I := 0 to L-1 do
|
|
|
|
- begin
|
|
|
|
- if (Len = Length(FEnumeration[I])) and CompareMem(Buf, DOMPChar(FEnumeration[I]), Len*sizeof(WideChar)) then
|
|
|
|
- Exit;
|
|
|
|
- end;
|
|
|
|
- SetLength(FEnumeration, L+1);
|
|
|
|
- SetString(FEnumeration[L], Buf, Len);
|
|
|
|
- Result := True;
|
|
|
|
-end;
|
|
|
|
-
|
|
|
|
-function TDOMAttrDef.HasEnumToken(const aValue: WideString): Boolean;
|
|
|
|
-var
|
|
|
|
- I: Integer;
|
|
|
|
-begin
|
|
|
|
- Result := True;
|
|
|
|
- if Length(FEnumeration) = 0 then
|
|
|
|
- Exit;
|
|
|
|
- for I := 0 to Length(FEnumeration)-1 do
|
|
|
|
- begin
|
|
|
|
- if FEnumeration[I] = aValue then
|
|
|
|
- Exit;
|
|
|
|
- end;
|
|
|
|
- Result := False;
|
|
|
|
-end;
|
|
|
|
-
|
|
|
|
-type
|
|
|
|
- TDOMAttrEx = class(TDOMAttr);
|
|
|
|
-
|
|
|
|
-function TDOMAttrDef.Clone(AElement: TDOMElement): TDOMAttr;
|
|
|
|
-begin
|
|
|
|
- Result := TDOMAttr.Create(FOwnerDocument);
|
|
|
|
- TDOMAttrEx(Result).FNSI.QName := Self.FNSI.QName;
|
|
|
|
- TDOMAttrEx(Result).FDataType := FDataType;
|
|
|
|
- CloneChildren(Result, FOwnerDocument);
|
|
|
|
-end;
|
|
|
|
-
|
|
|
|
{ TElementValidator }
|
|
{ TElementValidator }
|
|
|
|
|
|
function TElementValidator.IsElementAllowed(Def: TDOMElementDef): Boolean;
|
|
function TElementValidator.IsElementAllowed(Def: TDOMElementDef): Boolean;
|