Solved

xml presented in a tree view

Posted on 2002-07-25
3
886 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

758 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now