unit DemoFrm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids, ComCtrls, MSXML2_Tlb, ActnList, StdActns,
XPMan, ExtCtrls, TntComCtrls, TntStdCtrls,
ActiveX;
type
TDemoForm =
class(TForm)
TreeView: TTntTreeview;
ActionList: TActionList;
FileOpen: TFileOpen;
XPManifest: TXPManifest;
ActionPanel: TPanel;
Button: TButton;
Splitter: TSplitter;
RightPanel: TPanel;
Splitter1: TSplitter;
Memo: TTntMemo;
StatusBar: TStatusBar;
TntListView1: TTntListView;
procedure FormClose(Sender: TObject;
var Action: TCloseAction);
procedure TreeViewChange(Sender: TObject; Node: TTreeNode);
procedure FileOpenAccept(Sender: TObject);
private
XmlStream: TMemoryStream;
function TreeNodes: TTntTreeNodes;
procedure ShowContent(e: IXMLDOMElement);
procedure ShowFolder(e: IXMLDOMElement; nParent: TTntTreeNode);
end;
var
DemoForm: TDemoForm;
implementation
{$R *.dfm}
uses
StrUtils;
type
TReference =
class
public
Element: IXMLDOMElement;
constructor Create(e: IXMLDOMElement);
end;
var
doc: IXMLDOMDocument;
constructor TReference.Create(e: IXMLDOMElement);
begin
inherited Create;
Element := e;
end;
function TDemoForm.TreeNodes: TTntTreeNodes;
begin
Result := TreeView.Items;
end;
procedure TDemoForm.ShowContent(e: IXMLDOMElement);
var
i: Integer;
nl: IXMLDOMNodeList;
s:
String;
n: IXMLDOMNode;
begin
s := '
';
nl := e.selectNodes('
* | text()');
for i := 0
to Pred(nl.length)
do
begin
n := nl.item[i];
if n.nodeType = NODE_TEXT
then s := s + n.text
else s := s + Format('
(%s)', [n.text]);
end;
Memo.Text := s;
end;
procedure TDemoForm.ShowFolder(e: IXMLDOMElement; nParent: TTntTreeNode);
var
i: Integer;
nl: IXMLDOMNodeList;
n: TTntTreeNode;
eChild, eName: IXMLDOMElement;
s: WideString;
begin
nl := e.selectNodes('
*');
for i := 0
to Pred(nl.length)
do
begin
eChild := nl.item[i]
as IXMLDOMElement;
eName := eChild.selectSingleNode('
name')
as IXMLDOMElement;
if eChild.tagName = '
group'
then
begin
s := (eName.text);
n := TreeNodes.AddChildObject(nParent, s, TReference.Create(eChild));
ShowFolder(eChild, n);
end;
end;
end;
procedure TDemoForm.FileOpenAccept(Sender: TObject);
begin
with Sender
as TFileOpen
do
begin
doc := CoDomDocument.Create;
doc.async := false;
XmlStream := TMemoryStream.Create;
XmlStream.LoadFromFile(Dialog.FileName);
doc.Load(TStreamAdapter.Create(XmlStream, soReference)
as IStream);
begin
StatusBar.SimpleText := Dialog.FileName;
TreeNodes.Clear;
ShowFolder(doc.documentElement,
nil);
end;
end;
end;
procedure TDemoForm.TreeViewChange(Sender: TObject; Node: TTreeNode);
var
ref: TReference;
begin
ref := TReference(Node.Data);
ShowContent(ref.Element);
end;
procedure TDemoForm.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
XmlStream.Free;
end;
end.