Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2010-10

TDOMDocument.GetTextContent implementation seems wrong

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Graeme Geldenhuys

Hi,

The current hierarchy in the dom unit is as follows

TDomNode
|
TDOMNode_WithChildren
|
TDOMDocument

Now the GetTextContent() implementation for TDOMNode_WithChildren runs recursively through all child nodes collecting data.

...but the GetTextContent() implementation of TDomDocument simply returns '', without calling inherited GetTextContent; so we loose all the functionality implemented in
TDOMNode_WithChildren! Why is that?

So the following code (under FPC) simply results in returning nothing, because FXMLDoc is a TDomDocument instance. :-/

I'm using FPC 2.4.3 here...

-----------------------------------------
destructor TXMLListener.Destroy;
var
  Stream: TFileStream;
  S: string;
begin
  {$IFDEF FPC}
  S := FXMLDoc.TextContent;
  {$ELSE}
  S := FXMLDoc.code;
  {$ENDIF}
  Stream := TFileStream.Create(FAppPath + FDocName, fmCreate or fmOpenWrite);
  try
    Stream.Write(PChar(S)^, Length(S));
//    Stream.Write(S[1], Length(S));
  finally
    FreeAndNil(Stream);
  end;
  FStack := nil;
  FreeAndNil(FXMLDoc);
  inherited Destroy;
end;
-----------------------------------------
Regards,   - Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://opensoft.homeip.net:8080/fpgui/

Reply by email

Sergei Gorelkin
to Graeme Geldenhuys
Graeme Geldenhuys wrote 19 lines
Hi, The current hierarchy in the dom unit is as follows TDomNode | TDOMNode_WithChildren | TDOMDocument Now the GetTextContent() implementation for TDOMNode_WithChildren runs recursively through all child nodes collecting data. ...but the GetTextContent() implementation of TDomDocument simply returns '', without calling inherited GetTextContent; so we loose all the functionality implemented in TDOMNode_WithChildren! Why is that?

Compliance, see
http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#Node3-textContent

specifies that textContent property should be null for Document, Notation and DocumentType nodes.

Regards,
Sergei

Reply by email