Avatar of IbrahimSA
IbrahimSA
 asked on

HOW I CAN SHOW THE UTF-8 character using IXMLDocument component

hi all

i use the following code for parsing XML .... it works, however, it doesn't show the UTF-8 characters >>>instead it shows '????'


is there any way to show these UTF-8 Characters?

thank a lot
unit Unit1;
 
interface
 
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Menus, ComCtrls, ExtCtrls,
  XMLDoc, XMLIntf;
 
type
  TForm1 = class(TForm)
    Button3: TButton;
    Memo1: TMemo;
    procedure Button3Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    procedure PrintNode(ANode: IXMLNode);
  end;
 
var
  Form1: TForm1;
 
implementation
 
{$R *.dfm}
 
 
procedure TForm1.PrintNode(ANode: IXMLNode);
var cnt: Integer;
begin
  if ANode.NodeType = ntElement then begin
    Memo1.Lines.Add(ANode.NodeName);
    if ANode.IsTextElement then
      Memo1.Lines.Add(#9 + ANode.Text);
    for cnt := 0 to ANode.AttributeNodes.Count - 1 do
      Memo1.Lines.Add(ANode.AttributeNodes.Nodes[cnt].NodeName+'='+ VarToStr(ANode.AttributeNodes.Nodes[cnt].NodeValue));
    for cnt := 0 to ANode.ChildNodes.Count - 1 do
      PrintNode(ANode.ChildNodes.Nodes[cnt]);
  end;
end;
 
procedure TForm1.Button3Click(Sender: TObject);
var doc: IXMLDocument;
    cnt: Integer;
    node: IXMLNode;
begin
  doc := LoadXMLDocument('aa1.xml');
  for cnt := 0 to doc.ChildNodes.Count - 1 do begin
    node := doc.ChildNodes.Nodes[cnt];
    PrintNode(node);
  end;
 
end;
 
end.

Open in new window

Delphi

Avatar of undefined
Last Comment
db2trade

8/22/2022 - Mon
IbrahimSA

ASKER
I tried to add this line
doc.encoding :='UTF-8';

and nothings changes :(




procedure TForm1.Button3Click(Sender: TObject);
var
doc: IXMLDocument;
    cnt: Integer;
    node: IXMLNode;
begin

  doc := LoadXMLDocument('aa1.xml');
 doc.encoding :='UTF-8';
  for cnt := 0 to doc.ChildNodes.Count - 1 do begin
    node := doc.ChildNodes.Nodes[cnt];
    PrintNode(node);
 end;end;
IbrahimSA

ASKER
I also added this command

  doc := LoadXMLDocument(AnsiToUtf8('aa1.xml'));

rather than
  doc := LoadXMLDocument('aa1.xml));


With NO success :(
ASKER CERTIFIED SOLUTION
db2trade

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes