Solved

xml presented in a tree view

Posted on 2002-07-25
3
892 Views
Last Modified: 2012-06-21
I have an xml file with around 500 records. I want my user to browse the xml file via a tree view. is this possible.

thnks in advance.
0
Comment
Question by:drnadeem
3 Comments
 
LVL 7

Accepted Solution

by:
Cynna earned 100 total points
ID: 7178548

Yes it is, but you need XML parser for this. This is a bit of work, but there is
no need to develop your own. You have two choices:

1. Use Microsoft XML ActiveX component. You need to import Microsoft XML type library
   for this (Project -> Import type library -> Microsoft XML <version xxx>).
   This is slightly modified code from borland.public.delphi.xml that does what you want:


procedure XMLFile2TreeView(XMLDocFileName: String; TV:TTreeView); // Parses and transfers xml file to a treeview
var DOM: IXMLDOMDocument;
  procedure AddNodes(XMLNode: IXMLDOMNode; TreeNode: TTreeNode);
  var Index: Integer;
      NewNode: TTreeNode;
      Value: string;
  begin
    if XMLNode.nodeType in [NODE_TEXT, NODE_CDATA_SECTION, NODE_COMMENT] then
      Value := XMLNode.text
    else
      Value := XMLNode.nodeName;
    NewNode := TV.Items.AddChild(TreeNode,
    XMLNode.nodeTypeString + ': ' + Value);
    for Index := 0 to XMLNode.childNodes.length - 1 do
        AddNodes(XMLNode.childNodes.item[Index], NewNode);
  end;
begin
  DOM := CoDOMDocument.Create;
  DOM.load(XMLDocFileName);
  with TV do begin
       try
          Items.BeginUpdate;
          Items.Clear;
          AddNodes(DOM, nil);
          Items[0].Expand(True);
          TopItem := Items[0];
       finally
          Items.EndUpdate;
       end;
  end;
end;

// DEMO (requires Button1 and TreeView1 on the form, uses MSXML_TLB):
//------------------------------------------------------------------
procedure TForm1.Button1Click(Sender: TObject);
begin
  XMLFile2TreeView('demo.xml', TreeView1);
end;



2. Use custom XML parser component, for example:  http://www.destructor.de/xmlparser/

0
 
LVL 14

Expert Comment

by:DragonSlayer
ID: 7179081
or embed a webbrowser and just load the file in the embedded webbrowser :)
0
 
LVL 1

Author Comment

by:drnadeem
ID: 7183139
the component worked 4 me
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question