unit Unit2;
interface
uses
System.SysUtils, System.Variants, System.Classes, System.IOUtils,
Vcl.Controls,
Vcl.Forms,
Vcl.StdCtrls,
Vcl.ComCtrls,
Skia, Skia.Vcl,
Xml.XMLIntf,
Xml.XMLDoc;
type
TForm1 =
class(TForm)
SkSvg1: TSkSvg;
Button1: TButton;
Memo1: TMemo;
TreeView1: TTreeView;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
SvgFilePath, SvgAsText:
string;
XMLDoc: IXMLDocument;
XMLNode: IXMLNode;
TreeNode: TTreeNode;
procedure Fill(Nodes: IXMLNodeList; Item: TTreeNode);
var
Node: IXMLNode;
Item2: TTreeNode;
begin
Node := Nodes.First;
while Assigned(Node)
do
begin
Item2 := TreeView1.Items.AddChildObject(Item, Node.NodeName,
nil);
if Node.HasAttribute('
id')
then
begin
Item2.Text := Item2.Text + '
- id: ' + Node.Attributes['
id'];
end;
if Node.HasChildNodes
then
Fill(Node.ChildNodes, Item2);
Node := Node.NextSibling;
end;
end;
begin
SvgFilePath := '
..._PfadZuEinenTestSVG_...\Skia4Delphi\Samples\Demo\Assets\gorilla.svg';
SvgAsText := TFile.ReadAllText(SvgFilePath);
Memo1.Lines.Text := SvgAsText;
XMLDoc := NewXMLDocument;
XMLDoc.LoadFromXML(SvgAsText);
TreeView1.Items.BeginUpdate;
try
TreeView1.Items.Clear;
TreeNode := TreeView1.Items.AddChild(
nil, '
Root');
Fill(XMLDoc.DocumentElement.ChildNodes, TreeNode)
finally
TreeView1.FullExpand;
TreeView1.Items.EndUpdate;
end;
SkSvg1.Svg.Source := SvgAsText;
end;
end.