mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-17 20:49:09 +02:00
* Hopefully final fix for TDOMDocument.DocumentElement:
- Reading this property always delivers the first element in the document - Removed SetDocumentElement. Use "AppendChild" or one of the other generic methods for TDOMNode instead.
This commit is contained in:
parent
72ded63070
commit
3d6ba19140
@ -286,11 +286,11 @@ type
|
|||||||
protected
|
protected
|
||||||
FDocType: TDOMDocumentType;
|
FDocType: TDOMDocumentType;
|
||||||
FImplementation: TDOMImplementation;
|
FImplementation: TDOMImplementation;
|
||||||
FDocumentElement: TDOMElement;
|
function GetDocumentElement: TDOMElement;
|
||||||
public
|
public
|
||||||
property DocType: TDOMDocumentType read FDocType;
|
property DocType: TDOMDocumentType read FDocType;
|
||||||
property Impl: TDOMImplementation read FImplementation;
|
property Impl: TDOMImplementation read FImplementation;
|
||||||
property DocumentElement: TDOMElement read FDocumentElement;
|
property DocumentElement: TDOMElement read GetDocumentElement;
|
||||||
|
|
||||||
function CreateElement(const tagName: DOMString): TDOMElement; virtual;
|
function CreateElement(const tagName: DOMString): TDOMElement; virtual;
|
||||||
function CreateDocumentFragment: TDOMDocumentFragment;
|
function CreateDocumentFragment: TDOMDocumentFragment;
|
||||||
@ -309,7 +309,6 @@ type
|
|||||||
// Extensions to DOM interface:
|
// Extensions to DOM interface:
|
||||||
constructor Create; virtual;
|
constructor Create; virtual;
|
||||||
function CreateEntity(const data: DOMString): TDOMEntity;
|
function CreateEntity(const data: DOMString): TDOMEntity;
|
||||||
procedure SetDocumentElement(ADocumentElement: TDOMElement);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
TXMLDocument = class(TDOMDocument)
|
TXMLDocument = class(TDOMDocument)
|
||||||
@ -673,7 +672,8 @@ function TDOMNode_WithChildren.ReplaceChild(NewChild, OldChild: TDOMNode):
|
|||||||
TDOMNode;
|
TDOMNode;
|
||||||
begin
|
begin
|
||||||
InsertBefore(NewChild, OldChild);
|
InsertBefore(NewChild, OldChild);
|
||||||
RemoveChild(OldChild);
|
if Assigned(OldChild) then
|
||||||
|
RemoveChild(OldChild);
|
||||||
Result := NewChild;
|
Result := NewChild;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -932,9 +932,19 @@ begin
|
|||||||
FOwnerDocument := Self;
|
FOwnerDocument := Self;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TDOMDocument.SetDocumentElement(ADocumentElement: TDOMElement);
|
function TDOMDocument.GetDocumentElement: TDOMElement;
|
||||||
|
var
|
||||||
|
node: TDOMNode;
|
||||||
begin
|
begin
|
||||||
FDocumentElement := ADocumentElement;
|
node := FFirstChild;
|
||||||
|
while Assigned(node) do begin
|
||||||
|
if node.FNodeType = ELEMENT_NODE then begin
|
||||||
|
Result := TDOMElement(node);
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
node := node.NextSibling;
|
||||||
|
end;
|
||||||
|
Result := nil;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TDOMDocument.CreateElement(const tagName: DOMString): TDOMElement;
|
function TDOMDocument.CreateElement(const tagName: DOMString): TDOMElement;
|
||||||
@ -1283,7 +1293,13 @@ end.
|
|||||||
|
|
||||||
{
|
{
|
||||||
$Log$
|
$Log$
|
||||||
Revision 1.11 2000-01-30 22:18:16 sg
|
Revision 1.12 2000-02-13 10:03:31 sg
|
||||||
|
* Hopefully final fix for TDOMDocument.DocumentElement:
|
||||||
|
- Reading this property always delivers the first element in the document
|
||||||
|
- Removed SetDocumentElement. Use "AppendChild" or one of the other
|
||||||
|
generic methods for TDOMNode instead.
|
||||||
|
|
||||||
|
Revision 1.11 2000/01/30 22:18:16 sg
|
||||||
* Fixed memory leaks, all nodes are now freed by their parent
|
* Fixed memory leaks, all nodes are now freed by their parent
|
||||||
* Many cosmetic changes
|
* Many cosmetic changes
|
||||||
|
|
||||||
|
@ -78,15 +78,14 @@ begin
|
|||||||
Close(f);
|
Close(f);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
if doc = nil then
|
if not Assigned(doc) then
|
||||||
doc := TXMLDocument.Create;
|
doc := TXMLDocument.Create;
|
||||||
|
|
||||||
cfg :=TDOMElement(doc.FindNode('CONFIG'));
|
cfg :=TDOMElement(doc.FindNode('CONFIG'));
|
||||||
if cfg = nil then begin
|
if not Assigned(cfg) then begin
|
||||||
cfg := doc.CreateElement('CONFIG');
|
cfg := doc.CreateElement('CONFIG');
|
||||||
doc.AppendChild(cfg);
|
doc.AppendChild(cfg);
|
||||||
end;
|
end;
|
||||||
doc.SetDocumentElement(cfg);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TXMLConfig.Destroy;
|
destructor TXMLConfig.Destroy;
|
||||||
@ -121,17 +120,17 @@ begin
|
|||||||
name := Copy(path, 1, i - 1);
|
name := Copy(path, 1, i - 1);
|
||||||
path := Copy(path, i + 1, Length(path));
|
path := Copy(path, i + 1, Length(path));
|
||||||
subnode := node.FindNode(name);
|
subnode := node.FindNode(name);
|
||||||
if subnode = nil then begin
|
if not Assigned(subnode) then begin
|
||||||
Result := ADefault;
|
Result := ADefault;
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
node := subnode;
|
node := subnode;
|
||||||
end;
|
end;
|
||||||
attr := node.Attributes.GetNamedItem(path);
|
attr := node.Attributes.GetNamedItem(path);
|
||||||
if attr = nil then
|
if Assigned(attr) then
|
||||||
Result := ADefault
|
Result := attr.NodeValue
|
||||||
else
|
else
|
||||||
Result := attr.NodeValue;
|
Result := ADefault;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TXMLConfig.GetValue(const APath: String; ADefault: Integer): Integer;
|
function TXMLConfig.GetValue(const APath: String; ADefault: Integer): Integer;
|
||||||
@ -172,14 +171,14 @@ begin
|
|||||||
name := Copy(path, 1, i - 1);
|
name := Copy(path, 1, i - 1);
|
||||||
path := Copy(path, i + 1, Length(path));
|
path := Copy(path, i + 1, Length(path));
|
||||||
subnode := node.FindNode(name);
|
subnode := node.FindNode(name);
|
||||||
if subnode = nil then begin
|
if not Assigned(subnode) then begin
|
||||||
subnode := doc.CreateElement(name);
|
subnode := doc.CreateElement(name);
|
||||||
node.AppendChild(subnode);
|
node.AppendChild(subnode);
|
||||||
end;
|
end;
|
||||||
node := subnode;
|
node := subnode;
|
||||||
end;
|
end;
|
||||||
attr := node.Attributes.GetNamedItem(path);
|
attr := node.Attributes.GetNamedItem(path);
|
||||||
if attr = nil then begin
|
if not Assigned(attr) then begin
|
||||||
attr := doc.CreateAttribute(path);
|
attr := doc.CreateAttribute(path);
|
||||||
node.Attributes.SetNamedItem(attr);
|
node.Attributes.SetNamedItem(attr);
|
||||||
end;
|
end;
|
||||||
@ -205,7 +204,13 @@ end.
|
|||||||
|
|
||||||
{
|
{
|
||||||
$Log$
|
$Log$
|
||||||
Revision 1.8 2000-01-30 22:20:08 sg
|
Revision 1.9 2000-02-13 10:03:31 sg
|
||||||
|
* Hopefully final fix for TDOMDocument.DocumentElement:
|
||||||
|
- Reading this property always delivers the first element in the document
|
||||||
|
- Removed SetDocumentElement. Use "AppendChild" or one of the other
|
||||||
|
generic methods for TDOMNode instead.
|
||||||
|
|
||||||
|
Revision 1.8 2000/01/30 22:20:08 sg
|
||||||
* TXMLConfig now frees its XML document (major memory leak...)
|
* TXMLConfig now frees its XML document (major memory leak...)
|
||||||
|
|
||||||
Revision 1.7 2000/01/07 01:24:34 peter
|
Revision 1.7 2000/01/07 01:24:34 peter
|
||||||
|
@ -188,11 +188,6 @@ begin
|
|||||||
ExpectElement(doc);
|
ExpectElement(doc);
|
||||||
ParseMisc(doc);
|
ParseMisc(doc);
|
||||||
|
|
||||||
if Assigned(LastNodeBeforeDoc) then
|
|
||||||
doc.SetDocumentElement(LastNodeBeforeDoc.NextSibling as TDOMElement)
|
|
||||||
else
|
|
||||||
doc.SetDocumentElement(doc.FirstChild as TDOMElement);
|
|
||||||
|
|
||||||
if buf[0] <> #0 then
|
if buf[0] <> #0 then
|
||||||
RaiseExc('Text after end of document element found');
|
RaiseExc('Text after end of document element found');
|
||||||
|
|
||||||
@ -985,7 +980,13 @@ end.
|
|||||||
|
|
||||||
{
|
{
|
||||||
$Log$
|
$Log$
|
||||||
Revision 1.14 2000-01-30 22:19:13 sg
|
Revision 1.15 2000-02-13 10:03:31 sg
|
||||||
|
* Hopefully final fix for TDOMDocument.DocumentElement:
|
||||||
|
- Reading this property always delivers the first element in the document
|
||||||
|
- Removed SetDocumentElement. Use "AppendChild" or one of the other
|
||||||
|
generic methods for TDOMNode instead.
|
||||||
|
|
||||||
|
Revision 1.14 2000/01/30 22:19:13 sg
|
||||||
* Made some optimizations and cosmetic changes
|
* Made some optimizations and cosmetic changes
|
||||||
|
|
||||||
Revision 1.13 2000/01/07 01:24:34 peter
|
Revision 1.13 2000/01/07 01:24:34 peter
|
||||||
|
Loading…
Reference in New Issue
Block a user