mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-15 00:09:26 +02:00
* xmlread.pp, do some cleanup and get rid of FCursor field.
git-svn-id: trunk@16175 -
This commit is contained in:
parent
5dae691c96
commit
d248315ae4
@ -301,14 +301,13 @@ type
|
|||||||
FNext: PNodeData;
|
FNext: PNodeData;
|
||||||
FQName: PHashItem;
|
FQName: PHashItem;
|
||||||
FNodeType: TXMLNodeType;
|
FNodeType: TXMLNodeType;
|
||||||
FDOMNode: TObject; // temporary
|
FDOMNode: TDOMNode_WithChildren; // temporary
|
||||||
|
|
||||||
FValueStr: WideString;
|
FValueStr: WideString;
|
||||||
FValueStart: PWideChar;
|
FValueStart: PWideChar;
|
||||||
FValueLength: Integer;
|
FValueLength: Integer;
|
||||||
|
|
||||||
// validation-specific members
|
// validation-specific members
|
||||||
FElement: TDOMElement;
|
|
||||||
FElementDef: TDOMElementDef;
|
FElementDef: TDOMElementDef;
|
||||||
FCurCP: TContentParticle;
|
FCurCP: TContentParticle;
|
||||||
FFailed: Boolean;
|
FFailed: Boolean;
|
||||||
@ -412,7 +411,6 @@ type
|
|||||||
procedure CleanupAttributeData;
|
procedure CleanupAttributeData;
|
||||||
procedure SetNodeInfoWithValue(typ: TXMLNodeType; AName: PHashItem = nil);
|
procedure SetNodeInfoWithValue(typ: TXMLNodeType; AName: PHashItem = nil);
|
||||||
protected
|
protected
|
||||||
FCursor: TDOMNode_WithChildren;
|
|
||||||
FNesting: Integer;
|
FNesting: Integer;
|
||||||
FCurrNode: PNodeData;
|
FCurrNode: PNodeData;
|
||||||
FAttrCount: Integer;
|
FAttrCount: Integer;
|
||||||
@ -450,7 +448,7 @@ type
|
|||||||
procedure ParseMarkupDecl; // [29]
|
procedure ParseMarkupDecl; // [29]
|
||||||
procedure ParseStartTag; // [39]
|
procedure ParseStartTag; // [39]
|
||||||
procedure ParseEndTag; // [42]
|
procedure ParseEndTag; // [42]
|
||||||
procedure DoEndElement(ErrOffset: Integer);
|
procedure DoEndElement;
|
||||||
procedure ParseAttribute(Elem: TDOMElement; ElDef: TDOMElementDef);
|
procedure ParseAttribute(Elem: TDOMElement; ElDef: TDOMElementDef);
|
||||||
procedure ParseContent; // [43]
|
procedure ParseContent; // [43]
|
||||||
function Read: Boolean;
|
function Read: Boolean;
|
||||||
@ -1372,7 +1370,6 @@ procedure TXMLReader.ProcessXML(ASource: TXMLCharSource);
|
|||||||
begin
|
begin
|
||||||
doc := TXMLDocument.Create;
|
doc := TXMLDocument.Create;
|
||||||
doc.documentURI := ASource.SystemID; // TODO: to be changed to URI or BaseURI
|
doc.documentURI := ASource.SystemID; // TODO: to be changed to URI or BaseURI
|
||||||
FCursor := doc;
|
|
||||||
FState := rsProlog;
|
FState := rsProlog;
|
||||||
FNesting := 0;
|
FNesting := 0;
|
||||||
FCurrNode := @FNodeStack[0];
|
FCurrNode := @FNodeStack[0];
|
||||||
@ -1390,11 +1387,10 @@ end;
|
|||||||
procedure TXMLReader.ProcessFragment(ASource: TXMLCharSource; AOwner: TDOMNode);
|
procedure TXMLReader.ProcessFragment(ASource: TXMLCharSource; AOwner: TDOMNode);
|
||||||
begin
|
begin
|
||||||
doc := AOwner.OwnerDocument;
|
doc := AOwner.OwnerDocument;
|
||||||
FCursor := AOwner as TDOMNode_WithChildren;
|
|
||||||
FState := rsRoot;
|
FState := rsRoot;
|
||||||
FNesting := 0;
|
FNesting := 0;
|
||||||
FCurrNode := @FNodeStack[0];
|
FCurrNode := @FNodeStack[0];
|
||||||
FCurrNode^.FDOMNode := FCursor;
|
FCurrNode^.FDOMNode := AOwner as TDOMNode_WithChildren;
|
||||||
FXML11 := doc.InheritsFrom(TXMLDocument) and (TXMLDocument(doc).XMLVersion = '1.1');
|
FXML11 := doc.InheritsFrom(TXMLDocument) and (TXMLDocument(doc).XMLVersion = '1.1');
|
||||||
Initialize(ASource);
|
Initialize(ASource);
|
||||||
FDocType := TDOMDocumentTypeEx(doc.DocType);
|
FDocType := TDOMDocumentTypeEx(doc.DocType);
|
||||||
@ -2008,7 +2004,7 @@ begin
|
|||||||
ValidationError('Processing instructions are not allowed within EMPTY elements', []);
|
ValidationError('Processing instructions are not allowed within EMPTY elements', []);
|
||||||
|
|
||||||
PINode := Doc.CreateProcessingInstruction(NameStr, ValueStr);
|
PINode := Doc.CreateProcessingInstruction(NameStr, ValueStr);
|
||||||
FCursor.AppendChild(PINode)
|
FNodeStack[FNesting].FDOMNode.InternalAppend(PINode);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
const
|
const
|
||||||
@ -2710,7 +2706,6 @@ begin
|
|||||||
doc := TXMLDocument.Create;
|
doc := TXMLDocument.Create;
|
||||||
FDocType := TDOMDocumentTypeEx.Create(doc);
|
FDocType := TDOMDocumentTypeEx.Create(doc);
|
||||||
// TODO: DTD labeled version 1.1 will be rejected - must set FXML11 flag
|
// TODO: DTD labeled version 1.1 will be rejected - must set FXML11 flag
|
||||||
// DONE: It's ok to have FCursor=nil now
|
|
||||||
doc.AppendChild(FDocType);
|
doc.AppendChild(FDocType);
|
||||||
Initialize(ASource);
|
Initialize(ASource);
|
||||||
ParseMarkupDecl;
|
ParseMarkupDecl;
|
||||||
@ -2796,7 +2791,7 @@ begin
|
|||||||
xtComment:
|
xtComment:
|
||||||
DoComment(FCurrNode^.FValueStart, FCurrNode^.FValueLength);
|
DoComment(FCurrNode^.FValueStart, FCurrNode^.FValueLength);
|
||||||
xtEndElement:
|
xtEndElement:
|
||||||
DoEndElement(-1);
|
DoEndElement;
|
||||||
xtDoctype:
|
xtDoctype:
|
||||||
if not FCanonical then
|
if not FCanonical then
|
||||||
begin
|
begin
|
||||||
@ -2898,7 +2893,7 @@ begin
|
|||||||
if InCDATA then
|
if InCDATA then
|
||||||
FatalError('Unterminated CDATA section', -1);
|
FatalError('Unterminated CDATA section', -1);
|
||||||
if FNesting > FSource.FStartNesting then
|
if FNesting > FSource.FStartNesting then
|
||||||
FatalError('End-tag is missing for ''%s''', [FCurrNode^.FElement.NSI.QName^.Key]);
|
FatalError('End-tag is missing for ''%s''', [FNodeStack[FNesting].FQName^.Key]);
|
||||||
if ContextPop then Continue;
|
if ContextPop then Continue;
|
||||||
tok := xtEOF;
|
tok := xtEOF;
|
||||||
end
|
end
|
||||||
@ -2966,14 +2961,9 @@ begin
|
|||||||
FNext := xtText;
|
FNext := xtText;
|
||||||
|
|
||||||
case tok of
|
case tok of
|
||||||
xtEntity: AppendReference(FCursor, FCurrEntity);
|
xtEntity: AppendReference(FNodeStack[FNesting].FDOMNode, FCurrEntity);
|
||||||
xtElement: ParseStartTag;
|
xtElement: ParseStartTag;
|
||||||
xtEndElement:
|
xtEndElement: ParseEndTag;
|
||||||
begin
|
|
||||||
ParseEndTag;
|
|
||||||
FCurrNode^.FNodeType := ntEndElement;
|
|
||||||
FNext := xtPopElement;
|
|
||||||
end;
|
|
||||||
xtPI: ParsePI;
|
xtPI: ParsePI;
|
||||||
xtDoctype: ParseDoctypeDecl;
|
xtDoctype: ParseDoctypeDecl;
|
||||||
xtComment: ParseComment(False);
|
xtComment: ParseComment(False);
|
||||||
@ -3013,13 +3003,14 @@ begin
|
|||||||
FState := rsRoot;
|
FState := rsRoot;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
NewElem := doc.CreateElementBuf(FName.Buffer, FName.Length);
|
|
||||||
FCursor.AppendChild(NewElem);
|
|
||||||
// we're about to process a new set of attributes
|
// we're about to process a new set of attributes
|
||||||
Inc(FAttrTag);
|
Inc(FAttrTag);
|
||||||
// can point to a child text/comment/PI node, so restore it
|
// can point to a child text/comment/PI node, so restore it
|
||||||
FCurrNode := @FNodeStack[FNesting];
|
FCurrNode := @FNodeStack[FNesting];
|
||||||
|
|
||||||
|
NewElem := doc.CreateElementBuf(FName.Buffer, FName.Length);
|
||||||
|
FCurrNode^.FDOMNode.InternalAppend(NewElem);
|
||||||
|
|
||||||
// Remember the hash entry, we'll need it often
|
// Remember the hash entry, we'll need it often
|
||||||
ElName := NewElem.NSI.QName;
|
ElName := NewElem.NSI.QName;
|
||||||
|
|
||||||
@ -3063,7 +3054,6 @@ begin
|
|||||||
|
|
||||||
if not IsEmpty then
|
if not IsEmpty then
|
||||||
begin
|
begin
|
||||||
FCursor := NewElem;
|
|
||||||
if not FPreserveWhitespace then // critical for testsuite compliance
|
if not FPreserveWhitespace then // critical for testsuite compliance
|
||||||
SkipS;
|
SkipS;
|
||||||
FNext := xtPushElement;
|
FNext := xtPushElement;
|
||||||
@ -3072,18 +3062,13 @@ begin
|
|||||||
FNext := xtPopEmptyElement;
|
FNext := xtPopEmptyElement;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TXMLReader.DoEndElement(ErrOffset: Integer);
|
procedure TXMLReader.DoEndElement;
|
||||||
var
|
|
||||||
NewElem: TDOMElement;
|
|
||||||
begin
|
begin
|
||||||
NewElem := FCurrNode^.FElement;
|
if (FNesting > 0) and (FNodeStack[FNesting-1].FDOMNode = doc) then
|
||||||
TDOMNode(FCursor) := NewElem.ParentNode;
|
|
||||||
if FCursor = doc then
|
|
||||||
FState := rsEpilog;
|
FState := rsEpilog;
|
||||||
|
|
||||||
if FValidate and FCurrNode^.Incomplete then
|
if FValidate and FCurrNode^.Incomplete then
|
||||||
ValidationError('Element ''%s'' is missing required sub-elements', [NewElem.NSI.QName^.Key], ErrOffset);
|
ValidationError('Element ''%s'' is missing required sub-elements', [FNodeStack[FNesting].FQName^.Key], -1);
|
||||||
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TXMLReader.ParseEndTag; // [42]
|
procedure TXMLReader.ParseEndTag; // [42]
|
||||||
@ -3095,6 +3080,7 @@ begin
|
|||||||
Inc(FSource.FBuf);
|
Inc(FSource.FBuf);
|
||||||
|
|
||||||
FCurrNode := @FNodeStack[FNesting]; // move off the possible child
|
FCurrNode := @FNodeStack[FNesting]; // move off the possible child
|
||||||
|
FCurrNode^.FNodeType := ntEndElement;
|
||||||
ElName := FCurrNode^.FQName;
|
ElName := FCurrNode^.FQName;
|
||||||
|
|
||||||
CheckName;
|
CheckName;
|
||||||
@ -3108,6 +3094,7 @@ begin
|
|||||||
ExpectChar('>');
|
ExpectChar('>');
|
||||||
end;
|
end;
|
||||||
Inc(FTokenStart.LinePos, 2); // move over '</' chars
|
Inc(FTokenStart.LinePos, 2); // move over '</' chars
|
||||||
|
FNext := xtPopElement;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TXMLReader.ParseAttribute(Elem: TDOMElement; ElDef: TDOMElementDef);
|
procedure TXMLReader.ParseAttribute(Elem: TDOMElement; ElDef: TDOMElementDef);
|
||||||
@ -3477,7 +3464,7 @@ begin
|
|||||||
|
|
||||||
// Document builder part
|
// Document builder part
|
||||||
TextNode := Doc.CreateTextNodeBuf(ch, Count, Whitespace and (FCurrContentType = ctChildren));
|
TextNode := Doc.CreateTextNodeBuf(ch, Count, Whitespace and (FCurrContentType = ctChildren));
|
||||||
FCursor.AppendChild(TextNode);
|
FNodeStack[FNesting].FDOMNode.InternalAppend(TextNode);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TXMLReader.DoComment(ch: PWideChar; Count: Integer);
|
procedure TXMLReader.DoComment(ch: PWideChar; Count: Integer);
|
||||||
@ -3489,10 +3476,10 @@ begin
|
|||||||
ValidationError('Comments are not allowed within EMPTY elements', []);
|
ValidationError('Comments are not allowed within EMPTY elements', []);
|
||||||
|
|
||||||
// DOM builder part
|
// DOM builder part
|
||||||
if (not FIgnoreComments) and Assigned(FCursor) then
|
if (not FIgnoreComments) and (FState <> rsDTD) then
|
||||||
begin
|
begin
|
||||||
Node := Doc.CreateCommentBuf(ch, Count);
|
Node := Doc.CreateCommentBuf(ch, Count);
|
||||||
FCursor.AppendChild(Node);
|
FNodeStack[FNesting].FDOMNode.InternalAppend(Node);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -3506,7 +3493,7 @@ begin
|
|||||||
ValidationError('CDATA sections are not allowed in element-only content',[]);
|
ValidationError('CDATA sections are not allowed in element-only content',[]);
|
||||||
|
|
||||||
SetString(s, ch, Count);
|
SetString(s, ch, Count);
|
||||||
FCursor.AppendChild(doc.CreateCDATASection(s));
|
FNodeStack[FNesting].FDOMNode.InternalAppend(doc.CreateCDATASection(s));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TXMLReader.DoNotationDecl(const aName, aPubID, aSysID: WideString);
|
procedure TXMLReader.DoNotationDecl(const aName, aPubID, aSysID: WideString);
|
||||||
@ -3593,7 +3580,7 @@ procedure TXMLReader.PushVC(aElement: TDOMElement; aElDef: TDOMElementDef);
|
|||||||
begin
|
begin
|
||||||
Inc(FNesting);
|
Inc(FNesting);
|
||||||
FCurrNode := AllocNodeData(FNesting);
|
FCurrNode := AllocNodeData(FNesting);
|
||||||
FCurrNode^.FElement := aElement;
|
FCurrNode^.FDOMNode := aElement;
|
||||||
FCurrNode^.FElementDef := aElDef;
|
FCurrNode^.FElementDef := aElDef;
|
||||||
FCurrNode^.FCurCP := nil;
|
FCurrNode^.FCurCP := nil;
|
||||||
FCurrNode^.FFailed := False;
|
FCurrNode^.FFailed := False;
|
||||||
|
Loading…
Reference in New Issue
Block a user